37 Star 411 Fork 76

GVPrancher/rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
utils.go 1.25 KB
一键复制 编辑 原始数据 按行查看 历史
kinarashah 提交于 2018-08-10 02:22 . Fix moving of netpolicies on move ns
package networkpolicy
import (
"fmt"
"github.com/rancher/norman/types/convert"
"github.com/rancher/rancher/pkg/controllers/user/nslabels"
"github.com/rancher/types/apis/core/v1"
"github.com/rancher/types/apis/management.cattle.io/v3"
corev1 "k8s.io/api/core/v1"
)
func isNetworkPolicyDisabled(clusterNamespace string, clusterLister v3.ClusterLister) (bool, error) {
cluster, err := clusterLister.Get("", clusterNamespace)
if err != nil {
return false, fmt.Errorf("error getting cluster %v", err)
}
return !convert.ToBool(cluster.Annotations[netPolAnnotation]), nil
}
func isNamespaceMoved(namespace string, nsLister v1.NamespaceLister) (bool, error) {
ns, err := nsLister.Get("", namespace)
if err != nil {
return false, fmt.Errorf("error getting ns %v", err)
}
if _, ok := ns.Annotations[nslabels.ProjectIDFieldLabel]; !ok {
return true, nil
}
return ns.Annotations[nslabels.ProjectIDFieldLabel] == "", nil
}
func nodePortService(service *corev1.Service) bool {
for _, port := range service.Spec.Ports {
if port.NodePort != 0 {
return true
}
}
return false
}
func hostPortPod(pod *corev1.Pod) bool {
for _, c := range pod.Spec.Containers {
for _, port := range c.Ports {
if port.HostPort != 0 {
return true
}
}
}
return false
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.2.0-rc15

搜索帮助

0d507c66 1850385 C8b1a773 1850385