代码拉取完成,页面将自动刷新
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
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。