From 89d88a17edc9ac1c82f6a39d26b5c6fb48b32aec Mon Sep 17 00:00:00 2001 From: Sargun Dhillon Date: Thu, 15 Aug 2019 00:46:38 -0700 Subject: [PATCH] Add a generic reactor to lifecycle_test to bump resource version (#733) All updates in our tests should have the behaviour that best reflects what API server does. --- node/lifecycle_test.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/node/lifecycle_test.go b/node/lifecycle_test.go index 0d0627fd6..1bc07800e 100644 --- a/node/lifecycle_test.go +++ b/node/lifecycle_test.go @@ -27,6 +27,7 @@ import ( "k8s.io/client-go/tools/record" watchutils "k8s.io/client-go/tools/watch" "k8s.io/klog" + ktesting "k8s.io/client-go/testing" ) var ( @@ -263,6 +264,20 @@ func wireUpSystem(ctx context.Context, provider PodLifecycleHandler, f testFunct // Create the fake client. client := fake.NewSimpleClientset() + client.PrependReactor("update", "pods", func(action ktesting.Action) (handled bool, ret runtime.Object, err error) { + var pod *corev1.Pod + + updateAction := action.(ktesting.UpdateAction) + pod = updateAction.GetObject().(*corev1.Pod) + + resourceVersion, err := strconv.Atoi(pod.ResourceVersion) + if err != nil { + panic(errors.Wrap(err, "Could not parse resource version of pod")) + } + pod.ResourceVersion = strconv.Itoa(resourceVersion + 1) + return false, nil, nil + }) + // This is largely copy and pasted code from the root command sharedInformerFactory := kubeinformers.NewSharedInformerFactoryWithOptions( client, @@ -448,9 +463,6 @@ func testCreateStartDeleteScenario(ctx context.Context, t *testing.T, s *system, currentPod, err := s.client.CoreV1().Pods(testNamespace).Get(p.Name, metav1.GetOptions{}) assert.NilError(t, err) // 2. Set the pod's deletion timestamp, version, and so on - curVersion, err := strconv.Atoi(currentPod.ResourceVersion) - assert.NilError(t, err) - currentPod.ResourceVersion = strconv.Itoa(curVersion + 1) var deletionGracePeriod int64 = 30 currentPod.DeletionGracePeriodSeconds = &deletionGracePeriod deletionTimestamp := metav1.NewTime(time.Now().Add(time.Second * time.Duration(deletionGracePeriod)))