37 Star 411 Fork 76

GVPrancher/rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
clusterNetAnnHandler.go 1.35 KB
一键复制 编辑 原始数据 按行查看 历史
Darren Shepherd 提交于 2018-11-06 10:06 . Change return type
package networkpolicy
import (
"github.com/rancher/norman/types/convert"
"github.com/rancher/types/apis/management.cattle.io/v3"
"github.com/sirupsen/logrus"
"k8s.io/apimachinery/pkg/runtime"
)
const netPolAnnotation = "networking.management.cattle.io/enable-network-policy"
/*
clusterNetAnnHandler syncs cluster.Spec.EnableNetworkPolicy to cluster.Annotations[netPolAnnotation]
All network policy controllers read from this annotation value to decide if network policy is enabled
*/
type clusterNetAnnHandler struct {
clusters v3.ClusterInterface
clusterNamespace string
}
func (cn *clusterNetAnnHandler) Sync(key string, cluster *v3.Cluster) (runtime.Object, error) {
if cluster == nil || cluster.DeletionTimestamp != nil ||
cluster.Name != cn.clusterNamespace ||
!v3.ClusterConditionProvisioned.IsTrue(cluster) {
return nil, nil
}
if cluster.Spec.EnableNetworkPolicy == nil {
return nil, nil
}
if *cluster.Spec.EnableNetworkPolicy == convert.ToBool(cluster.Annotations[netPolAnnotation]) {
return nil, nil
}
logrus.Infof("clusterNetAnnHandler: updating EnableNetworkPolicy of cluster %s to %v", cluster.Name,
*cluster.Spec.EnableNetworkPolicy)
cluster.Annotations[netPolAnnotation] = convert.ToString(*cluster.Spec.EnableNetworkPolicy)
if _, err := cn.clusters.Update(cluster); err != nil {
return nil, err
}
return nil, nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.3.0-alpha2

搜索帮助

0d507c66 1850385 C8b1a773 1850385