-
Notifications
You must be signed in to change notification settings - Fork 469
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
full sync when namespace labels change (#917)
- Loading branch information
Showing
2 changed files
with
60 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package netpol | ||
|
||
import ( | ||
"github.com/golang/glog" | ||
api "k8s.io/api/core/v1" | ||
"k8s.io/client-go/tools/cache" | ||
"reflect" | ||
) | ||
|
||
func (npc *NetworkPolicyController) newNamespaceEventHandler() cache.ResourceEventHandler { | ||
return cache.ResourceEventHandlerFuncs{ | ||
AddFunc: func(obj interface{}) { | ||
npc.handleNamespaceAdd(obj.(*api.Namespace)) | ||
}, | ||
UpdateFunc: func(oldObj, newObj interface{}) { | ||
npc.handleNamespaceUpdate(oldObj.(*api.Namespace), newObj.(*api.Namespace)) | ||
}, | ||
DeleteFunc: func(obj interface{}) { | ||
switch obj := obj.(type) { | ||
case *api.Namespace: | ||
npc.handleNamespaceDelete(obj) | ||
return | ||
case cache.DeletedFinalStateUnknown: | ||
if namespace, ok := obj.Obj.(*api.Namespace); ok { | ||
npc.handleNamespaceDelete(namespace) | ||
return | ||
} | ||
default: | ||
glog.Errorf("unexpected object type: %v", obj) | ||
} | ||
}, | ||
} | ||
} | ||
|
||
func (npc *NetworkPolicyController) handleNamespaceAdd(obj *api.Namespace) { | ||
if npc.v1NetworkPolicy && obj.Labels == nil { | ||
return | ||
} | ||
glog.V(2).Infof("Received update for namespace: %s", obj.Name) | ||
|
||
npc.RequestFullSync() | ||
} | ||
|
||
func (npc *NetworkPolicyController) handleNamespaceUpdate(oldObj, newObj *api.Namespace) { | ||
if npc.v1NetworkPolicy && reflect.DeepEqual(oldObj.Labels, newObj.Labels) { | ||
return | ||
} | ||
glog.V(2).Infof("Received update for namespace: %s", newObj.Name) | ||
|
||
npc.RequestFullSync() | ||
} | ||
|
||
func (npc *NetworkPolicyController) handleNamespaceDelete(obj *api.Namespace) { | ||
if npc.v1NetworkPolicy && obj.Labels == nil { | ||
return | ||
} | ||
glog.V(2).Infof("Received namespace: %s delete event", obj.Name) | ||
|
||
npc.RequestFullSync() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters