37 Star 403 Fork 75

GVPrancher/rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
clusterNetAnnHandler.go 1.27 KB
一键复制 编辑 原始数据 按行查看 历史
package networkpolicy
import (
"github.com/rancher/norman/types/convert"
"github.com/rancher/types/apis/management.cattle.io/v3"
"github.com/sirupsen/logrus"
)
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) error {
if cluster == nil || cluster.DeletionTimestamp != nil ||
cluster.Name != cn.clusterNamespace ||
!v3.ClusterConditionProvisioned.IsTrue(cluster) {
return nil
}
if cluster.Spec.EnableNetworkPolicy == nil {
return nil
}
if *cluster.Spec.EnableNetworkPolicy == convert.ToBool(cluster.Annotations[netPolAnnotation]) {
return 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 err
}
return nil
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.1.0

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385