-
Notifications
You must be signed in to change notification settings - Fork 260
[NPM] fix management of DeletedFinalStateUnknown object on deletion event in each controller #856
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ import ( | |
| kubeinformers "k8s.io/client-go/informers" | ||
| k8sfake "k8s.io/client-go/kubernetes/fake" | ||
| core "k8s.io/client-go/testing" | ||
| "k8s.io/client-go/tools/cache" | ||
| ) | ||
|
|
||
| type netPolFixture struct { | ||
|
|
@@ -165,13 +166,22 @@ func addNetPol(t *testing.T, f *netPolFixture, netPolObj *networkingv1.NetworkPo | |
| f.netPolController.processNextWorkItem() | ||
| } | ||
|
|
||
| func deleteNetPol(t *testing.T, f *netPolFixture, netPolObj *networkingv1.NetworkPolicy) { | ||
| func deleteNetPol(t *testing.T, f *netPolFixture, netPolObj *networkingv1.NetworkPolicy, isDeletedFinalStateUnknownObject IsDeletedFinalStateUnknownObject) { | ||
| addNetPol(t, f, netPolObj) | ||
| t.Logf("Complete adding network policy event") | ||
|
|
||
| // simulate network policy deletion event and delete network policy object from sharedInformer cache | ||
| f.kubeInformer.Networking().V1().NetworkPolicies().Informer().GetIndexer().Delete(netPolObj) | ||
| f.netPolController.deleteNetworkPolicy(netPolObj) | ||
| if isDeletedFinalStateUnknownObject { | ||
| netPolKey := getKey(netPolObj, t) | ||
| tombstone := cache.DeletedFinalStateUnknown{ | ||
| Key: netPolKey, | ||
| Obj: netPolObj, | ||
| } | ||
| f.netPolController.deleteNetworkPolicy(tombstone) | ||
| } else { | ||
| f.netPolController.deleteNetworkPolicy(netPolObj) | ||
| } | ||
|
|
||
| if f.netPolController.workqueue.Len() == 0 { | ||
| f.isEnqueueEventIntoWorkQueue = false | ||
|
|
@@ -305,13 +315,54 @@ func TestDeleteNetworkPolicy(t *testing.T) { | |
| defer close(stopCh) | ||
| f.newNetPolController(stopCh) | ||
|
|
||
| deleteNetPol(t, f, netPolObj) | ||
| deleteNetPol(t, f, netPolObj, DeletedFinalStateknownObject) | ||
| testCases := []expectedNetPolValues{ | ||
| {1, 0, 0, false, true, 0, nil, 1, nil}, | ||
| } | ||
| checkNetPolTestResult("TestDelNetPol", f, testCases) | ||
| } | ||
|
|
||
| func TestDeleteNetworkPolicyWithTombstone(t *testing.T) { | ||
| netPolObj := createNetPol() | ||
|
|
||
| f := newNetPolFixture(t) | ||
| f.isEnqueueEventIntoWorkQueue = false | ||
| f.netPolLister = append(f.netPolLister, netPolObj) | ||
| f.kubeobjects = append(f.kubeobjects, netPolObj) | ||
| stopCh := make(chan struct{}) | ||
| defer close(stopCh) | ||
| f.newNetPolController(stopCh) | ||
|
|
||
| netPolKey := getKey(netPolObj, t) | ||
| tombstone := cache.DeletedFinalStateUnknown{ | ||
| Key: netPolKey, | ||
| Obj: netPolObj, | ||
| } | ||
|
|
||
| f.netPolController.deleteNetworkPolicy(tombstone) | ||
| testCases := []expectedNetPolValues{ | ||
| {1, 0, 0, false, false, 0, nil, 0, nil}, | ||
| } | ||
| checkNetPolTestResult("TestDeleteNetworkPolicyWithTombstone", f, testCases) | ||
| } | ||
|
|
||
| func TestDeleteNetworkPolicyWithTombstoneAfterAddingNetworkPolicy(t *testing.T) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel like there is no major difference in functionality between TestDeleteNetworkPolicyWithTombstone and TestDeleteNetworkPolicyWithTombstoneAfterAddingNetworkPolicy as AddingNS does not care about tombstone and in deleting the way we contruct tombstone is same. So we can reduce the complexity these test files by having only one tescase and not send delefinalstate in deleteNetPol(t *testing.T, ...) func bu
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They are different. I am not sure this increase complexity. It has one extra boolean variable for only delete event in UT and later we can do more sophisticated tests. But, if there is better way to deal with this, let me know. |
||
| netPolObj := createNetPol() | ||
|
|
||
| f := newNetPolFixture(t) | ||
| f.netPolLister = append(f.netPolLister, netPolObj) | ||
| f.kubeobjects = append(f.kubeobjects, netPolObj) | ||
| stopCh := make(chan struct{}) | ||
| defer close(stopCh) | ||
| f.newNetPolController(stopCh) | ||
|
|
||
| deleteNetPol(t, f, netPolObj, DeletedFinalStateUnknownObject) | ||
| testCases := []expectedNetPolValues{ | ||
| {1, 0, 0, false, true, 0, nil, 1, nil}, | ||
| } | ||
| checkNetPolTestResult("TestDeleteNetworkPolicyWithTombstoneAfterAddingNetworkPolicy", f, testCases) | ||
| } | ||
|
|
||
| // this unit test is for the case where states of network policy are changed, but network policy controller does not need to reconcile. | ||
| // Check it with expectedEnqueueEventIntoWorkQueue variable. | ||
| func TestUpdateNetworkPolicy(t *testing.T) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential function name ambiguity, can clarify between this helper deleteNamespace and f.nsController.deleteNamespace()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I think last time Vamsi also mentioned this. We can discuss and refactor this point when we add more UTs with ipset and iptables.