Skip to content

Commit

Permalink
k8s/watcher: check if spec and specs are equal
Browse files Browse the repository at this point in the history
If both Spec and Specs are considered the same we don't need to re-add
the CNP into the policy repository. The commit 134fdb5 should have
added the Specs.DeepEqual and not remove the Spec.DeepEqual.

Fixes: 134fdb5 ("k8s/watchers: fix missing missing CNP/CCNP updates")
Signed-off-by: André Martins <andre@cilium.io>
  • Loading branch information
aanm committed Oct 9, 2020
1 parent c0b4519 commit 30160bc
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions pkg/k8s/watchers/cilium_network_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,24 +301,28 @@ func (k *K8sWatcher) updateCiliumNetworkPolicyV2(ciliumNPClient clientset.Interf

// Do not add rule into policy repository if the spec remains unchanged.
if !option.Config.DisableCNPStatusUpdates {
if !oldRuleCpy.AnnotationsEquals(newRuleCpy.CiliumNetworkPolicy) {

// Update annotations within a controller so the status of the update
// is trackable from the list of running controllers, and so we do
// not block subsequent policy lifecycle operations from Kubernetes
// until the update is complete.
oldCtrlName := oldRuleCpy.GetControllerName()
newCtrlName := newRuleCpy.GetControllerName()

// In case the controller name changes between copies of rules,
// remove old controller so we do not leak goroutines.
if oldCtrlName != newCtrlName {
err := k8sCM.RemoveController(oldCtrlName)
if err != nil {
log.Debugf("Unable to remove controller %s: %s", oldCtrlName, err)
if oldRuleCpy.Spec.DeepEqual(newRuleCpy.CiliumNetworkPolicy.Spec) &&
oldRuleCpy.Specs.DeepEqual(&newRuleCpy.CiliumNetworkPolicy.Specs) {
if !oldRuleCpy.AnnotationsEquals(newRuleCpy.CiliumNetworkPolicy) {

// Update annotations within a controller so the status of the update
// is trackable from the list of running controllers, and so we do
// not block subsequent policy lifecycle operations from Kubernetes
// until the update is complete.
oldCtrlName := oldRuleCpy.GetControllerName()
newCtrlName := newRuleCpy.GetControllerName()

// In case the controller name changes between copies of rules,
// remove old controller so we do not leak goroutines.
if oldCtrlName != newCtrlName {
err := k8sCM.RemoveController(oldCtrlName)
if err != nil {
log.Debugf("Unable to remove controller %s: %s", oldCtrlName, err)
}
}
k.updateCiliumNetworkPolicyV2AnnotationsOnly(ciliumNPClient, ciliumV2Store, newRuleCpy)
}
k.updateCiliumNetworkPolicyV2AnnotationsOnly(ciliumNPClient, ciliumV2Store, newRuleCpy)
return nil
}
}

Expand Down

0 comments on commit 30160bc

Please sign in to comment.