|
3 | 3 | package npm |
4 | 4 |
|
5 | 5 | import ( |
| 6 | + "reflect" |
| 7 | + |
6 | 8 | "github.com/Azure/azure-container-networking/log" |
7 | 9 | "github.com/Azure/azure-container-networking/npm/ipsm" |
8 | 10 | "github.com/Azure/azure-container-networking/npm/iptm" |
@@ -42,6 +44,15 @@ func isSystemNs(nsObj *corev1.Namespace) bool { |
42 | 44 | return nsObj.ObjectMeta.Name == util.KubeSystemFlag |
43 | 45 | } |
44 | 46 |
|
| 47 | +func isInvalidNamespaceUpdate(oldNsObj, newNsObj *corev1.Namespace) (isInvalidUpdate bool) { |
| 48 | + isInvalidUpdate = oldNsObj.ObjectMeta.Name == newNsObj.ObjectMeta.Name && |
| 49 | + newNsObj.ObjectMeta.DeletionTimestamp == nil && |
| 50 | + newNsObj.ObjectMeta.DeletionGracePeriodSeconds == nil |
| 51 | + isInvalidUpdate = isInvalidUpdate && reflect.DeepEqual(oldNsObj.ObjectMeta.Labels, newNsObj.ObjectMeta.Labels) |
| 52 | + |
| 53 | + return |
| 54 | +} |
| 55 | + |
45 | 56 | func (ns *namespace) policyExists(npObj *networkingv1.NetworkPolicy) bool { |
46 | 57 | if np, exists := ns.rawNpMap[npObj.ObjectMeta.Name]; exists { |
47 | 58 | if isSamePolicy(np, npObj) { |
@@ -134,8 +145,11 @@ func (npMgr *NetworkPolicyManager) AddNamespace(nsObj *corev1.Namespace) error { |
134 | 145 |
|
135 | 146 | // UpdateNamespace handles updating namespace in ipset. |
136 | 147 | func (npMgr *NetworkPolicyManager) UpdateNamespace(oldNsObj *corev1.Namespace, newNsObj *corev1.Namespace) error { |
137 | | - var err error |
| 148 | + if isInvalidNamespaceUpdate(oldNsObj, newNsObj) { |
| 149 | + return nil |
| 150 | + } |
138 | 151 |
|
| 152 | + var err error |
139 | 153 | oldNsNs, oldNsLabel := "ns-"+oldNsObj.ObjectMeta.Name, oldNsObj.ObjectMeta.Labels |
140 | 154 | newNsNs, newNsLabel := "ns-"+newNsObj.ObjectMeta.Name, newNsObj.ObjectMeta.Labels |
141 | 155 | log.Printf( |
|
0 commit comments