From 3eaab702fb38463760302262708272fcafd767ad Mon Sep 17 00:00:00 2001 From: Audrey Lim Date: Sat, 6 Oct 2018 22:01:43 -0700 Subject: [PATCH] Annotate errors in apimachinery e2e tests --- test/e2e/apimachinery/chunking.go | 13 ++-- test/e2e/apimachinery/crd_watch.go | 12 ++-- test/e2e/apimachinery/etcd_failure.go | 9 +-- test/e2e/apimachinery/garbage_collector.go | 38 +++++++----- test/e2e/apimachinery/initializers.go | 70 ++++++++++++---------- test/e2e/apimachinery/namespace.go | 51 +++++++++------- test/e2e/apimachinery/table_conversion.go | 14 ++--- test/e2e/apimachinery/watch.go | 62 +++++++++---------- test/e2e/apimachinery/webhook.go | 34 ++++++----- 9 files changed, 163 insertions(+), 140 deletions(-) diff --git a/test/e2e/apimachinery/chunking.go b/test/e2e/apimachinery/chunking.go index d46406e070..07fa1f53ce 100644 --- a/test/e2e/apimachinery/chunking.go +++ b/test/e2e/apimachinery/chunking.go @@ -80,7 +80,7 @@ var _ = SIGDescribe("Servers with support for API chunking", func() { for { opts.Limit = int64(rand.Int31n(numberOfTotalResources/10) + 1) list, err := client.List(opts) - Expect(err).ToNot(HaveOccurred()) + Expect(err).ToNot(HaveOccurred(), "failed to list pod templates in namespace: %s, given limit: %d", ns, opts.Limit) framework.Logf("Retrieved %d/%d results with rv %s and continue %s", len(list.Items), opts.Limit, list.ResourceVersion, list.Continue) Expect(len(list.Items)).To(BeNumerically("<=", opts.Limit)) @@ -101,8 +101,9 @@ var _ = SIGDescribe("Servers with support for API chunking", func() { } By("retrieving those results all at once") - list, err := client.List(metav1.ListOptions{Limit: numberOfTotalResources + 1}) - Expect(err).ToNot(HaveOccurred()) + opts := metav1.ListOptions{Limit: numberOfTotalResources + 1} + list, err := client.List(opts) + Expect(err).ToNot(HaveOccurred(), "failed to list pod templates in namespace: %s, given limit: %d", ns, opts.Limit) Expect(list.Items).To(HaveLen(numberOfTotalResources)) }) @@ -116,7 +117,7 @@ var _ = SIGDescribe("Servers with support for API chunking", func() { opts := metav1.ListOptions{} opts.Limit = oneTenth list, err := client.List(opts) - Expect(err).ToNot(HaveOccurred()) + Expect(err).ToNot(HaveOccurred(), "failed to list pod templates in namespace: %s, given limit: %d", ns, opts.Limit) firstToken := list.Continue firstRV := list.ResourceVersion framework.Logf("Retrieved %d/%d results with rv %s and continue %s", len(list.Items), opts.Limit, list.ResourceVersion, firstToken) @@ -149,7 +150,7 @@ var _ = SIGDescribe("Servers with support for API chunking", func() { By("retrieving the second page again with the token received with the error message") opts.Continue = inconsistentToken list, err = client.List(opts) - Expect(err).ToNot(HaveOccurred()) + Expect(err).ToNot(HaveOccurred(), "failed to list pod templates in namespace: %s, given inconsistent continue token %s and limit: %d", ns, opts.Continue, opts.Limit) Expect(list.ResourceVersion).ToNot(Equal(firstRV)) Expect(len(list.Items)).To(BeNumerically("==", opts.Limit)) found := oneTenth @@ -163,7 +164,7 @@ var _ = SIGDescribe("Servers with support for API chunking", func() { lastRV := list.ResourceVersion for { list, err := client.List(opts) - Expect(err).ToNot(HaveOccurred()) + Expect(err).ToNot(HaveOccurred(), "failed to list pod templates in namespace: %s, given limit: %d", ns, opts.Limit) framework.Logf("Retrieved %d/%d results with rv %s and continue %s", len(list.Items), opts.Limit, list.ResourceVersion, list.Continue) Expect(len(list.Items)).To(BeNumerically("<=", opts.Limit)) Expect(list.ResourceVersion).To(Equal(lastRV)) diff --git a/test/e2e/apimachinery/crd_watch.go b/test/e2e/apimachinery/crd_watch.go index 93339f5980..e3f04a3377 100644 --- a/test/e2e/apimachinery/crd_watch.go +++ b/test/e2e/apimachinery/crd_watch.go @@ -80,35 +80,35 @@ var _ = SIGDescribe("CustomResourceDefinition Watch", func() { noxuResourceClient := newNamespacedCustomResourceClient(ns, f.DynamicClient, noxuDefinition) watchA, err := watchCRWithName(noxuResourceClient, watchCRNameA) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to watch custom resource: %s", watchCRNameA) watchB, err := watchCRWithName(noxuResourceClient, watchCRNameB) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to watch custom resource: %s", watchCRNameB) testCrA := fixtures.NewNoxuInstance(ns, watchCRNameA) testCrB := fixtures.NewNoxuInstance(ns, watchCRNameB) By("Creating first CR ") testCrA, err = instantiateCustomResource(testCrA, noxuResourceClient, noxuDefinition) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to instantiate custom resource: %+v", testCrA) expectEvent(watchA, watch.Added, testCrA) expectNoEvent(watchB, watch.Added, testCrA) By("Creating second CR") testCrB, err = instantiateCustomResource(testCrB, noxuResourceClient, noxuDefinition) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to instantiate custom resource: %+v", testCrB) expectEvent(watchB, watch.Added, testCrB) expectNoEvent(watchA, watch.Added, testCrB) By("Deleting first CR") err = deleteCustomResource(noxuResourceClient, watchCRNameA) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to delete custom resource: %s", watchCRNameA) expectEvent(watchA, watch.Deleted, nil) expectNoEvent(watchB, watch.Deleted, nil) By("Deleting second CR") err = deleteCustomResource(noxuResourceClient, watchCRNameB) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to delete custom resource: %s", watchCRNameB) expectEvent(watchB, watch.Deleted, nil) expectNoEvent(watchA, watch.Deleted, nil) }) diff --git a/test/e2e/apimachinery/etcd_failure.go b/test/e2e/apimachinery/etcd_failure.go index 4f1d9c4c03..d1e6da23fa 100644 --- a/test/e2e/apimachinery/etcd_failure.go +++ b/test/e2e/apimachinery/etcd_failure.go @@ -94,8 +94,9 @@ func doEtcdFailure(failCommand, fixCommand string) { } func masterExec(cmd string) { - result, err := framework.SSH(cmd, framework.GetMasterHost()+":22", framework.TestContext.Provider) - Expect(err).NotTo(HaveOccurred()) + host := framework.GetMasterHost() + ":22" + result, err := framework.SSH(cmd, host, framework.TestContext.Provider) + Expect(err).NotTo(HaveOccurred(), "failed to SSH to host %s on provider %s and run command: %q", host, framework.TestContext.Provider, cmd) if result.Code != 0 { framework.LogSSHResult(result) framework.Failf("master exec command returned non-zero") @@ -120,7 +121,7 @@ func checkExistingRCRecovers(f *framework.Framework) { } for _, pod := range pods.Items { err = podClient.Delete(pod.Name, metav1.NewDeleteOptions(0)) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to delete pod %s in namespace: %s", pod.Name, f.Namespace.Name) } framework.Logf("apiserver has recovered") return true, nil @@ -130,7 +131,7 @@ func checkExistingRCRecovers(f *framework.Framework) { framework.ExpectNoError(wait.Poll(time.Millisecond*500, time.Second*60, func() (bool, error) { options := metav1.ListOptions{LabelSelector: rcSelector.String()} pods, err := podClient.List(options) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to list pods in namespace: %s, that match label selector: %s", f.Namespace.Name, rcSelector.String()) for _, pod := range pods.Items { if pod.DeletionTimestamp == nil && podutil.IsPodReady(&pod) { return true, nil diff --git a/test/e2e/apimachinery/garbage_collector.go b/test/e2e/apimachinery/garbage_collector.go index fa2f6f4e5f..875e390ae8 100644 --- a/test/e2e/apimachinery/garbage_collector.go +++ b/test/e2e/apimachinery/garbage_collector.go @@ -737,12 +737,12 @@ var _ = SIGDescribe("Garbage collector", func() { } By(fmt.Sprintf("set half of pods created by rc %s to have rc %s as owner as well", rc1Name, rc2Name)) pods, err := podClient.List(metav1.ListOptions{}) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to list pods in namespace: %s", f.Namespace.Name) patch := fmt.Sprintf(`{"metadata":{"ownerReferences":[{"apiVersion":"v1","kind":"ReplicationController","name":"%s","uid":"%s"}]}}`, rc2.ObjectMeta.Name, rc2.ObjectMeta.UID) for i := 0; i < halfReplicas; i++ { pod := pods.Items[i] _, err := podClient.Patch(pod.Name, types.StrategicMergePatchType, []byte(patch)) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to apply to pod %s in namespace %s, a strategic merge patch: %s", pod.Name, f.Namespace.Name, patch) } By(fmt.Sprintf("delete the rc %s", rc1Name)) @@ -816,33 +816,39 @@ var _ = SIGDescribe("Garbage collector", func() { framework.ConformanceIt("should not be blocked by dependency circle", func() { clientSet := f.ClientSet podClient := clientSet.CoreV1().Pods(f.Namespace.Name) - pod1 := newGCPod("pod1") + pod1Name := "pod1" + pod1 := newGCPod(pod1Name) pod1, err := podClient.Create(pod1) - Expect(err).NotTo(HaveOccurred()) - pod2 := newGCPod("pod2") + Expect(err).NotTo(HaveOccurred(), "failed to create pod %s in namespace: %s", pod1Name, f.Namespace.Name) + pod2Name := "pod2" + pod2 := newGCPod(pod2Name) pod2, err = podClient.Create(pod2) - Expect(err).NotTo(HaveOccurred()) - pod3 := newGCPod("pod3") + Expect(err).NotTo(HaveOccurred(), "failed to create pod %s in namespace: %s", pod2Name, f.Namespace.Name) + pod3Name := "pod3" + pod3 := newGCPod(pod3Name) pod3, err = podClient.Create(pod3) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to create pod %s in namespace: %s", pod3Name, f.Namespace.Name) // create circular dependency addRefPatch := func(name string, uid types.UID) []byte { return []byte(fmt.Sprintf(`{"metadata":{"ownerReferences":[{"apiVersion":"v1","kind":"Pod","name":"%s","uid":"%s","controller":true,"blockOwnerDeletion":true}]}}`, name, uid)) } - pod1, err = podClient.Patch(pod1.Name, types.StrategicMergePatchType, addRefPatch(pod3.Name, pod3.UID)) - Expect(err).NotTo(HaveOccurred()) + patch1 := addRefPatch(pod3.Name, pod3.UID) + pod1, err = podClient.Patch(pod1.Name, types.StrategicMergePatchType, patch1) + Expect(err).NotTo(HaveOccurred(), "failed to apply to pod %s in namespace %s, a strategic merge patch: %s", pod1.Name, f.Namespace.Name, patch1) framework.Logf("pod1.ObjectMeta.OwnerReferences=%#v", pod1.ObjectMeta.OwnerReferences) - pod2, err = podClient.Patch(pod2.Name, types.StrategicMergePatchType, addRefPatch(pod1.Name, pod1.UID)) - Expect(err).NotTo(HaveOccurred()) + patch2 := addRefPatch(pod1.Name, pod1.UID) + pod2, err = podClient.Patch(pod2.Name, types.StrategicMergePatchType, patch2) + Expect(err).NotTo(HaveOccurred(), "failed to apply to pod %s in namespace %s, a strategic merge patch: %s", pod2.Name, f.Namespace.Name, patch2) framework.Logf("pod2.ObjectMeta.OwnerReferences=%#v", pod2.ObjectMeta.OwnerReferences) - pod3, err = podClient.Patch(pod3.Name, types.StrategicMergePatchType, addRefPatch(pod2.Name, pod2.UID)) - Expect(err).NotTo(HaveOccurred()) + patch3 := addRefPatch(pod2.Name, pod2.UID) + pod3, err = podClient.Patch(pod3.Name, types.StrategicMergePatchType, patch3) + Expect(err).NotTo(HaveOccurred(), "failed to apply to pod %s in namespace %s, a strategic merge patch: %s", pod3.Name, f.Namespace.Name, patch3) framework.Logf("pod3.ObjectMeta.OwnerReferences=%#v", pod3.ObjectMeta.OwnerReferences) // delete one pod, should result in the deletion of all pods deleteOptions := getForegroundOptions() deleteOptions.Preconditions = metav1.NewUIDPreconditions(string(pod1.UID)) err = podClient.Delete(pod1.ObjectMeta.Name, deleteOptions) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to delete pod %s in namespace: %s", pod1.Name, f.Namespace.Name) var pods *v1.PodList var err2 error // TODO: shorten the timeout when we make GC's periodic API rediscovery more efficient. @@ -1073,7 +1079,7 @@ var _ = SIGDescribe("Garbage collector", func() { By("Create the cronjob") cronJob := newCronJob("simple", "*/1 * * * ?") cronJob, err := f.ClientSet.BatchV1beta1().CronJobs(f.Namespace.Name).Create(cronJob) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to create cronjob: %+v, in namespace: %s", cronJob, f.Namespace.Name) By("Wait for the CronJob to create new Job") err = wait.PollImmediate(500*time.Millisecond, 2*time.Minute, func() (bool, error) { diff --git a/test/e2e/apimachinery/initializers.go b/test/e2e/apimachinery/initializers.go index f0381721f1..1adfd2d047 100644 --- a/test/e2e/apimachinery/initializers.go +++ b/test/e2e/apimachinery/initializers.go @@ -52,8 +52,9 @@ var _ = SIGDescribe("Initializers [Feature:Initializers]", func() { ch := make(chan struct{}) go func() { - _, err := c.CoreV1().Pods(ns).Create(newUninitializedPod(podName)) - Expect(err).NotTo(HaveOccurred()) + pod := newUninitializedPod(podName) + _, err := c.CoreV1().Pods(ns).Create(pod) + Expect(err).NotTo(HaveOccurred(), "failed to create pod %s in namespace: %s", podName, ns) close(ch) }() @@ -72,34 +73,35 @@ var _ = SIGDescribe("Initializers [Feature:Initializers]", func() { // verify that we can update an initializing pod pod, err := c.CoreV1().Pods(ns).Get(podName, metav1.GetOptions{}) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to get pod %s in namespace: %s", podName, ns) pod.Annotations = map[string]string{"update-1": "test"} pod, err = c.CoreV1().Pods(ns).Update(pod) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to update pod %s in namespace %s to: %+v", pod.Name, ns, pod) // verify the list call filters out uninitialized pods - pods, err := c.CoreV1().Pods(ns).List(metav1.ListOptions{IncludeUninitialized: true}) - Expect(err).NotTo(HaveOccurred()) + listOptions := metav1.ListOptions{IncludeUninitialized: true} + pods, err := c.CoreV1().Pods(ns).List(listOptions) + Expect(err).NotTo(HaveOccurred(), "failed to list pods in namespace: %s, given list options: %+v", ns, listOptions) Expect(pods.Items).To(HaveLen(1)) pods, err = c.CoreV1().Pods(ns).List(metav1.ListOptions{}) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to list pods in namespace: %s", ns) Expect(pods.Items).To(HaveLen(0)) // clear initializers pod.Initializers = nil pod, err = c.CoreV1().Pods(ns).Update(pod) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to update pod %s in namespace %s to: %+v", pod.Name, ns, pod) // pod should now start running err = framework.WaitForPodRunningInNamespace(c, pod) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "error while waiting for pod %s to go to Running phase in namespace: %s", pod.Name, pod.Namespace) // ensure create call returns <-ch // verify that we cannot start the pod initializing again pod, err = c.CoreV1().Pods(ns).Get(podName, metav1.GetOptions{}) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to get pod %s in namespace: %s", podName, ns) pod.Initializers = &metav1.Initializers{ Pending: []metav1.Initializer{{Name: "Other"}}, } @@ -119,7 +121,7 @@ var _ = SIGDescribe("Initializers [Feature:Initializers]", func() { // create and register an initializer initializerName := "pod.test.e2e.kubernetes.io" initializerConfigName := "e2e-test-initializer" - _, err := c.AdmissionregistrationV1alpha1().InitializerConfigurations().Create(&v1alpha1.InitializerConfiguration{ + initializerConfig := &v1alpha1.InitializerConfiguration{ ObjectMeta: metav1.ObjectMeta{Name: initializerConfigName}, Initializers: []v1alpha1.Initializer{ { @@ -129,11 +131,12 @@ var _ = SIGDescribe("Initializers [Feature:Initializers]", func() { }, }, }, - }) + } + _, err := c.AdmissionregistrationV1alpha1().InitializerConfigurations().Create(initializerConfig) if errors.IsNotFound(err) { framework.Skipf("dynamic configuration of initializers requires the alpha admissionregistration.k8s.io group to be enabled") } - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to create and register initializer with config: %+v", initializerConfig) // we must remove the initializer when the test is complete and ensure no pods are pending for that initializer defer cleanupInitializer(c, initializerConfigName, initializerName) @@ -145,8 +148,9 @@ var _ = SIGDescribe("Initializers [Feature:Initializers]", func() { ch := make(chan struct{}) go func() { defer close(ch) - _, err := c.CoreV1().Pods(ns).Create(newInitPod(podName)) - Expect(err).NotTo(HaveOccurred()) + pod := newInitPod(podName) + _, err := c.CoreV1().Pods(ns).Create(pod) + Expect(err).NotTo(HaveOccurred(), "failed to create pod %s in namespace: %s", podName, ns) }() // wait until the pod shows up uninitialized @@ -162,7 +166,7 @@ var _ = SIGDescribe("Initializers [Feature:Initializers]", func() { } return true, nil }) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to get pod %s from namespace: %s", podName, ns) Expect(pod.Initializers).NotTo(BeNil()) Expect(pod.Initializers.Pending).To(HaveLen(1)) Expect(pod.Initializers.Pending[0].Name).To(Equal(initializerName)) @@ -171,14 +175,14 @@ var _ = SIGDescribe("Initializers [Feature:Initializers]", func() { By("Completing initialization") pod.Initializers = nil pod, err = c.CoreV1().Pods(ns).Update(pod) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to update pod %s in namespace %s to: %+v", pod.Name, ns, pod) // ensure create call returns <-ch // pod should now start running err = framework.WaitForPodRunningInNamespace(c, pod) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "error while waiting for pod %s to go to Running phase in namespace: %s", pod.Name, pod.Namespace) // bypass initialization by explicitly passing an empty pending list By("Setting an empty initializer as an admin to bypass initialization") @@ -186,7 +190,7 @@ var _ = SIGDescribe("Initializers [Feature:Initializers]", func() { pod = newUninitializedPod(podName) pod.Initializers.Pending = nil pod, err = c.CoreV1().Pods(ns).Create(pod) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to create pod %s in namespace: %s", podName, ns) Expect(pod.Initializers).To(BeNil()) // bypass initialization for mirror pods @@ -198,7 +202,7 @@ var _ = SIGDescribe("Initializers [Feature:Initializers]", func() { } pod.Spec.NodeName = "node-does-not-yet-exist" pod, err = c.CoreV1().Pods(ns).Create(pod) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to create pod %s in namespace: %s", podName, ns) Expect(pod.Initializers).To(BeNil()) Expect(pod.Annotations[v1.MirrorPodAnnotationKey]).To(Equal("true")) }) @@ -213,7 +217,7 @@ var _ = SIGDescribe("Initializers [Feature:Initializers]", func() { // create and register an initializer, without setting up a controller to handle it. initializerName := "pod.test.e2e.kubernetes.io" initializerConfigName := "e2e-test-initializer" - _, err := c.AdmissionregistrationV1alpha1().InitializerConfigurations().Create(&v1alpha1.InitializerConfiguration{ + initializerConfig := &v1alpha1.InitializerConfiguration{ ObjectMeta: metav1.ObjectMeta{Name: initializerConfigName}, Initializers: []v1alpha1.Initializer{ { @@ -223,11 +227,12 @@ var _ = SIGDescribe("Initializers [Feature:Initializers]", func() { }, }, }, - }) + } + _, err := c.AdmissionregistrationV1alpha1().InitializerConfigurations().Create(initializerConfig) if errors.IsNotFound(err) { framework.Skipf("dynamic configuration of initializers requires the alpha admissionregistration.k8s.io group to be enabled") } - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to create and register initializer with config: %+v", initializerConfig) // we must remove the initializer when the test is complete and ensure no pods are pending for that initializer defer cleanupInitializer(c, initializerConfigName, initializerName) @@ -236,31 +241,32 @@ var _ = SIGDescribe("Initializers [Feature:Initializers]", func() { time.Sleep(3 * time.Second) // create a replicaset - persistedRS, err := c.ExtensionsV1beta1().ReplicaSets(ns).Create(newReplicaset()) - Expect(err).NotTo(HaveOccurred()) + rs := newReplicaset() + persistedRS, err := c.ExtensionsV1beta1().ReplicaSets(ns).Create(rs) + Expect(err).NotTo(HaveOccurred(), "failed to create replicaset %s in namespace: %s", persistedRS.Name, ns) // wait for replicaset controller to confirm that it has handled the creation err = waitForRSObservedGeneration(c, persistedRS.Namespace, persistedRS.Name, persistedRS.Generation) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "replicaset %s failed to observe generation: %d", persistedRS.Name, persistedRS.Generation) // update the replicaset spec to trigger a resync patch := []byte(`{"spec":{"minReadySeconds":5}}`) persistedRS, err = c.ExtensionsV1beta1().ReplicaSets(ns).Patch(persistedRS.Name, types.StrategicMergePatchType, patch) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to apply to replicaset %s in namespace %s a strategic merge patch: %s", persistedRS.Name, ns, patch) // wait for replicaset controller to confirm that it has handle the spec update err = waitForRSObservedGeneration(c, persistedRS.Namespace, persistedRS.Name, persistedRS.Generation) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "replicaset %s failed to observe generation: %d", persistedRS.Name, persistedRS.Generation) // verify that the replicaset controller doesn't create extra pod selector, err := metav1.LabelSelectorAsSelector(persistedRS.Spec.Selector) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to convert label selector %+v of LabelSelector api type into a struct that implements labels.Selector", persistedRS.Spec.Selector) listOptions := metav1.ListOptions{ LabelSelector: selector.String(), IncludeUninitialized: true, } pods, err := c.CoreV1().Pods(ns).List(listOptions) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to list pods in namespace: %s, given list options: %+v", ns, listOptions) Expect(len(pods.Items)).Should(Equal(1)) }) @@ -277,13 +283,13 @@ var _ = SIGDescribe("Initializers [Feature:Initializers]", func() { framework.Failf("expect err to be timeout error, got %v", err) } uninitializedPod, err := c.CoreV1().Pods(ns).Get(podName, metav1.GetOptions{}) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to get pod %s in namespace: %s", podName, ns) Expect(uninitializedPod.Initializers).NotTo(BeNil()) Expect(len(uninitializedPod.Initializers.Pending)).Should(Equal(1)) patch := fmt.Sprintf(`{"metadata":{"initializers":{"pending":[{"$patch":"delete","name":"%s"}]}}}`, uninitializedPod.Initializers.Pending[0].Name) patchedPod, err := c.CoreV1().Pods(ns).Patch(uninitializedPod.Name, types.StrategicMergePatchType, []byte(patch)) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to apply to pod %s in namespace %s a strategic merge patch: %s", uninitializedPod.Name, ns, patch) Expect(patchedPod.Initializers).To(BeNil()) }) }) diff --git a/test/e2e/apimachinery/namespace.go b/test/e2e/apimachinery/namespace.go index 7f090baae6..9c39ee4fab 100644 --- a/test/e2e/apimachinery/namespace.go +++ b/test/e2e/apimachinery/namespace.go @@ -45,8 +45,9 @@ func extinguish(f *framework.Framework, totalNS int, maxAllowedAfterDel int, max go func(n int) { defer wg.Done() defer GinkgoRecover() - _, err = f.CreateNamespace(fmt.Sprintf("nslifetest-%v", n), nil) - Expect(err).NotTo(HaveOccurred()) + ns := fmt.Sprintf("nslifetest-%v", n) + _, err = f.CreateNamespace(ns, nil) + Expect(err).NotTo(HaveOccurred(), "failed to create namespace: %s", ns) }(n) } wg.Wait() @@ -54,8 +55,9 @@ func extinguish(f *framework.Framework, totalNS int, maxAllowedAfterDel int, max //Wait 10 seconds, then SEND delete requests for all the namespaces. By("Waiting 10 seconds") time.Sleep(time.Duration(10 * time.Second)) - deleted, err := framework.DeleteNamespaces(f.ClientSet, []string{"nslifetest"}, nil /* skipFilter */) - Expect(err).NotTo(HaveOccurred()) + deleteFilter := []string{"nslifetest"} + deleted, err := framework.DeleteNamespaces(f.ClientSet, deleteFilter, nil /* skipFilter */) + Expect(err).NotTo(HaveOccurred(), "failed to delete namespace(s) containing: %s", deleteFilter) Expect(len(deleted)).To(Equal(totalNS)) By("Waiting for namespaces to vanish") @@ -93,23 +95,25 @@ func waitForPodInNamespace(c clientset.Interface, ns, podName string) *v1.Pod { } return true, nil }) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to get pod %s in namespace: %s", podName, ns) return pod } func ensurePodsAreRemovedWhenNamespaceIsDeleted(f *framework.Framework) { By("Creating a test namespace") - namespace, err := f.CreateNamespace("nsdeletetest", nil) - Expect(err).NotTo(HaveOccurred()) + namespaceName := "nsdeletetest" + namespace, err := f.CreateNamespace(namespaceName, nil) + Expect(err).NotTo(HaveOccurred(), "failed to create namespace: %s", namespaceName) By("Waiting for a default service account to be provisioned in namespace") err = framework.WaitForDefaultServiceAccountInNamespace(f.ClientSet, namespace.Name) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failure while waiting for a default service account to be provisioned in namespace: %s", namespace.Name) By("Creating a pod in the namespace") + podName := "test-pod" pod := &v1.Pod{ ObjectMeta: metav1.ObjectMeta{ - Name: "test-pod", + Name: podName, }, Spec: v1.PodSpec{ Containers: []v1.Container{ @@ -121,7 +125,7 @@ func ensurePodsAreRemovedWhenNamespaceIsDeleted(f *framework.Framework) { }, } pod, err = f.ClientSet.CoreV1().Pods(namespace.Name).Create(pod) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to create pod %s in namespace: %s", podName, namespace.Name) By("Waiting for the pod to have running status") framework.ExpectNoError(framework.WaitForPodRunningInNamespace(f.ClientSet, pod)) @@ -150,7 +154,7 @@ func ensurePodsAreRemovedWhenNamespaceIsDeleted(f *framework.Framework) { By("Deleting the namespace") err = f.ClientSet.CoreV1().Namespaces().Delete(namespace.Name, nil) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to delete namespace: %s", namespace.Name) By("Waiting for the namespace to be removed.") maxWaitSeconds := int64(60) + *pod.Spec.TerminationGracePeriodSeconds @@ -164,26 +168,27 @@ func ensurePodsAreRemovedWhenNamespaceIsDeleted(f *framework.Framework) { })) By("Recreating the namespace") - namespace, err = f.CreateNamespace("nsdeletetest", nil) - Expect(err).NotTo(HaveOccurred()) + namespace, err = f.CreateNamespace(namespaceName, nil) + Expect(err).NotTo(HaveOccurred(), "failed to create namespace: %s", namespaceName) By("Verifying there are no pods in the namespace") _, err = f.ClientSet.CoreV1().Pods(namespace.Name).Get(pod.Name, metav1.GetOptions{}) - Expect(err).To(HaveOccurred()) + Expect(err).To(HaveOccurred(), "failed to get pod %s in namespace: %s", pod.Name, namespace.Name) _, err = f.ClientSet.CoreV1().Pods(namespace.Name).Get(podB.Name, metav1.GetOptions{IncludeUninitialized: true}) - Expect(err).To(HaveOccurred()) + Expect(err).To(HaveOccurred(), "failed to get pod %s in namespace: %s", podB.Name, namespace.Name) } func ensureServicesAreRemovedWhenNamespaceIsDeleted(f *framework.Framework) { var err error By("Creating a test namespace") - namespace, err := f.CreateNamespace("nsdeletetest", nil) - Expect(err).NotTo(HaveOccurred()) + namespaceName := "nsdeletetest" + namespace, err := f.CreateNamespace(namespaceName, nil) + Expect(err).NotTo(HaveOccurred(), "failed to create namespace: %s", namespaceName) By("Waiting for a default service account to be provisioned in namespace") err = framework.WaitForDefaultServiceAccountInNamespace(f.ClientSet, namespace.Name) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failure while waiting for a default service account to be provisioned in namespace: %s", namespace.Name) By("Creating a service in the namespace") serviceName := "test-service" @@ -204,11 +209,11 @@ func ensureServicesAreRemovedWhenNamespaceIsDeleted(f *framework.Framework) { }, } service, err = f.ClientSet.CoreV1().Services(namespace.Name).Create(service) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to create service %s in namespace %s", serviceName, namespace.Name) By("Deleting the namespace") err = f.ClientSet.CoreV1().Namespaces().Delete(namespace.Name, nil) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to delete namespace: %s", namespace.Name) By("Waiting for the namespace to be removed.") maxWaitSeconds := int64(60) @@ -222,12 +227,12 @@ func ensureServicesAreRemovedWhenNamespaceIsDeleted(f *framework.Framework) { })) By("Recreating the namespace") - namespace, err = f.CreateNamespace("nsdeletetest", nil) - Expect(err).NotTo(HaveOccurred()) + namespace, err = f.CreateNamespace(namespaceName, nil) + Expect(err).NotTo(HaveOccurred(), "failed to create namespace: %s", namespaceName) By("Verifying there is no service in the namespace") _, err = f.ClientSet.CoreV1().Services(namespace.Name).Get(service.Name, metav1.GetOptions{}) - Expect(err).To(HaveOccurred()) + Expect(err).To(HaveOccurred(), "failed to get service %s in namespace: %s", service.Name, namespace.Name) } // This test must run [Serial] due to the impact of running other parallel diff --git a/test/e2e/apimachinery/table_conversion.go b/test/e2e/apimachinery/table_conversion.go index 1356b4e79d..3d66bd88ab 100644 --- a/test/e2e/apimachinery/table_conversion.go +++ b/test/e2e/apimachinery/table_conversion.go @@ -55,11 +55,11 @@ var _ = SIGDescribe("Servers with support for Table transformation", func() { framework.Logf("Creating pod %s", podName) _, err := c.CoreV1().Pods(ns).Create(newTablePod(podName)) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to create pod %s in namespace: %s", podName, ns) table := &metav1beta1.Table{} err = c.CoreV1().RESTClient().Get().Resource("pods").Namespace(ns).Name(podName).SetHeader("Accept", "application/json;as=Table;v=v1beta1;g=meta.k8s.io").Do().Into(table) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to get pod %s in Table form in namespace: %s", podName, ns) framework.Logf("Table: %#v", table) Expect(len(table.ColumnDefinitions)).To(BeNumerically(">", 2)) @@ -107,7 +107,7 @@ var _ = SIGDescribe("Servers with support for Table transformation", func() { VersionedParams(&metav1.ListOptions{Limit: 2}, metav1.ParameterCodec). SetHeader("Accept", "application/json;as=Table;v=v1beta1;g=meta.k8s.io"). Do().Into(pagedTable) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to get pod templates in Table form in namespace: %s", ns) Expect(len(pagedTable.Rows)).To(Equal(2)) Expect(pagedTable.ResourceVersion).ToNot(Equal("")) Expect(pagedTable.SelfLink).ToNot(Equal("")) @@ -119,7 +119,7 @@ var _ = SIGDescribe("Servers with support for Table transformation", func() { VersionedParams(&metav1.ListOptions{Continue: pagedTable.Continue}, metav1.ParameterCodec). SetHeader("Accept", "application/json;as=Table;v=v1beta1;g=meta.k8s.io"). Do().Into(pagedTable) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to get pod templates in Table form in namespace: %s", ns) Expect(len(pagedTable.Rows)).To(BeNumerically(">", 0)) Expect(pagedTable.Rows[0].Cells[0]).To(Equal("template-0002")) }) @@ -129,7 +129,7 @@ var _ = SIGDescribe("Servers with support for Table transformation", func() { table := &metav1beta1.Table{} err := c.CoreV1().RESTClient().Get().Resource("nodes").SetHeader("Accept", "application/json;as=Table;v=v1beta1;g=meta.k8s.io").Do().Into(table) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to get nodes in Table form across all namespaces") framework.Logf("Table: %#v", table) Expect(len(table.ColumnDefinitions)).To(BeNumerically(">=", 2)) @@ -157,7 +157,7 @@ var _ = SIGDescribe("Servers with support for Table transformation", func() { }, } err := c.AuthorizationV1().RESTClient().Post().Resource("selfsubjectaccessreviews").SetHeader("Accept", "application/json;as=Table;v=v1beta1;g=meta.k8s.io").Body(sar).Do().Into(table) - Expect(err).To(HaveOccurred()) + Expect(err).To(HaveOccurred(), "failed to return error when posting self subject access review: %+v, to a backend that does not implement metadata", sar) Expect(err.(errors.APIStatus).Status().Code).To(Equal(int32(406))) }) }) @@ -166,7 +166,7 @@ func printTable(table *metav1beta1.Table) string { buf := &bytes.Buffer{} tw := tabwriter.NewWriter(buf, 5, 8, 1, ' ', 0) err := printers.PrintTable(table, tw, printers.PrintOptions{}) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to print table: %+v", table) tw.Flush() return buf.String() } diff --git a/test/e2e/apimachinery/watch.go b/test/e2e/apimachinery/watch.go index 2ca292bda2..1d3ad98320 100644 --- a/test/e2e/apimachinery/watch.go +++ b/test/e2e/apimachinery/watch.go @@ -55,15 +55,15 @@ var _ = SIGDescribe("Watchers", func() { By("creating a watch on configmaps with label A") watchA, err := watchConfigMaps(f, "", multipleWatchersLabelValueA) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to create a watch on configmaps with label: %s", multipleWatchersLabelValueA) By("creating a watch on configmaps with label B") watchB, err := watchConfigMaps(f, "", multipleWatchersLabelValueB) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to create a watch on configmaps with label: %s", multipleWatchersLabelValueB) By("creating a watch on configmaps with label A or B") watchAB, err := watchConfigMaps(f, "", multipleWatchersLabelValueA, multipleWatchersLabelValueB) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to create a watch on configmaps with label %s or %s", multipleWatchersLabelValueA, multipleWatchersLabelValueB) testConfigMapA := &v1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ @@ -84,7 +84,7 @@ var _ = SIGDescribe("Watchers", func() { By("creating a configmap with label A and ensuring the correct watchers observe the notification") testConfigMapA, err = c.CoreV1().ConfigMaps(ns).Create(testConfigMapA) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to create a configmap with label %s in namespace: %s", multipleWatchersLabelValueA, ns) expectEvent(watchA, watch.Added, testConfigMapA) expectEvent(watchAB, watch.Added, testConfigMapA) expectNoEvent(watchB, watch.Added, testConfigMapA) @@ -93,7 +93,7 @@ var _ = SIGDescribe("Watchers", func() { testConfigMapA, err = updateConfigMap(c, ns, testConfigMapA.GetName(), func(cm *v1.ConfigMap) { setConfigMapData(cm, "mutation", "1") }) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to update configmap %s in namespace: %s", testConfigMapA.GetName(), ns) expectEvent(watchA, watch.Modified, testConfigMapA) expectEvent(watchAB, watch.Modified, testConfigMapA) expectNoEvent(watchB, watch.Modified, testConfigMapA) @@ -102,28 +102,28 @@ var _ = SIGDescribe("Watchers", func() { testConfigMapA, err = updateConfigMap(c, ns, testConfigMapA.GetName(), func(cm *v1.ConfigMap) { setConfigMapData(cm, "mutation", "2") }) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to update configmap %s in namespace: %s", testConfigMapA.GetName(), ns) expectEvent(watchA, watch.Modified, testConfigMapA) expectEvent(watchAB, watch.Modified, testConfigMapA) expectNoEvent(watchB, watch.Modified, testConfigMapA) By("deleting configmap A and ensuring the correct watchers observe the notification") err = c.CoreV1().ConfigMaps(ns).Delete(testConfigMapA.GetName(), nil) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to delete configmap %s in namespace: %s", testConfigMapA.GetName(), ns) expectEvent(watchA, watch.Deleted, nil) expectEvent(watchAB, watch.Deleted, nil) expectNoEvent(watchB, watch.Deleted, nil) By("creating a configmap with label B and ensuring the correct watchers observe the notification") testConfigMapB, err = c.CoreV1().ConfigMaps(ns).Create(testConfigMapB) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to create configmap %s in namespace: %s", testConfigMapB, ns) expectEvent(watchB, watch.Added, testConfigMapB) expectEvent(watchAB, watch.Added, testConfigMapB) expectNoEvent(watchA, watch.Added, testConfigMapB) By("deleting configmap B and ensuring the correct watchers observe the notification") err = c.CoreV1().ConfigMaps(ns).Delete(testConfigMapB.GetName(), nil) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to delete configmap %s in namespace: %s", testConfigMapB.GetName(), ns) expectEvent(watchB, watch.Deleted, nil) expectEvent(watchAB, watch.Deleted, nil) expectNoEvent(watchA, watch.Deleted, nil) @@ -149,27 +149,27 @@ var _ = SIGDescribe("Watchers", func() { By("creating a new configmap") testConfigMap, err := c.CoreV1().ConfigMaps(ns).Create(testConfigMap) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to create configmap %s in namespace: %s", testConfigMap.GetName(), ns) By("modifying the configmap once") testConfigMapFirstUpdate, err := updateConfigMap(c, ns, testConfigMap.GetName(), func(cm *v1.ConfigMap) { setConfigMapData(cm, "mutation", "1") }) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to update configmap %s in namespace: %s", testConfigMap.GetName(), ns) By("modifying the configmap a second time") testConfigMapSecondUpdate, err := updateConfigMap(c, ns, testConfigMap.GetName(), func(cm *v1.ConfigMap) { setConfigMapData(cm, "mutation", "2") }) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to update configmap %s in namespace %s a second time", testConfigMap.GetName(), ns) By("deleting the configmap") err = c.CoreV1().ConfigMaps(ns).Delete(testConfigMap.GetName(), nil) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to delete configmap %s in namespace: %s", testConfigMap.GetName(), ns) By("creating a watch on configmaps from the resource version returned by the first update") testWatch, err := watchConfigMaps(f, testConfigMapFirstUpdate.ObjectMeta.ResourceVersion, fromResourceVersionLabelValue) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to create a watch on configmaps from the resource version %s returned by the first update", testConfigMapFirstUpdate.ObjectMeta.ResourceVersion) By("Expecting to observe notifications for all changes to the configmap after the first update") expectEvent(testWatch, watch.Modified, testConfigMapSecondUpdate) @@ -186,9 +186,10 @@ var _ = SIGDescribe("Watchers", func() { c := f.ClientSet ns := f.Namespace.Name + configMapName := "e2e-watch-test-watch-closed" testConfigMap := &v1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ - Name: "e2e-watch-test-watch-closed", + Name: configMapName, Labels: map[string]string{ watchConfigMapLabelKey: watchRestartedLabelValue, }, @@ -197,17 +198,17 @@ var _ = SIGDescribe("Watchers", func() { By("creating a watch on configmaps") testWatchBroken, err := watchConfigMaps(f, "", watchRestartedLabelValue) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to create a watch on configmap with label: %s", watchRestartedLabelValue) By("creating a new configmap") testConfigMap, err = c.CoreV1().ConfigMaps(ns).Create(testConfigMap) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to create configmap %s in namespace: %s", configMapName, ns) By("modifying the configmap once") _, err = updateConfigMap(c, ns, testConfigMap.GetName(), func(cm *v1.ConfigMap) { setConfigMapData(cm, "mutation", "1") }) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to update configmap %s in namespace: %s", configMapName, ns) By("closing the watch once it receives two notifications") expectEvent(testWatchBroken, watch.Added, testConfigMap) @@ -221,7 +222,7 @@ var _ = SIGDescribe("Watchers", func() { testConfigMapSecondUpdate, err := updateConfigMap(c, ns, testConfigMap.GetName(), func(cm *v1.ConfigMap) { setConfigMapData(cm, "mutation", "2") }) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to update configmap %s in namespace %s a second time", configMapName, ns) By("creating a new watch on configmaps from the last resource version observed by the first watch") lastEventConfigMap, ok := lastEvent.Object.(*v1.ConfigMap) @@ -229,11 +230,11 @@ var _ = SIGDescribe("Watchers", func() { framework.Failf("Expected last notfication to refer to a configmap but got: %v", lastEvent) } testWatchRestarted, err := watchConfigMaps(f, lastEventConfigMap.ObjectMeta.ResourceVersion, watchRestartedLabelValue) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to create a new watch on configmaps from the last resource version %s observed by the first watch", lastEventConfigMap.ObjectMeta.ResourceVersion) By("deleting the configmap") err = c.CoreV1().ConfigMaps(ns).Delete(testConfigMap.GetName(), nil) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to delete configmap %s in namespace: %s", configMapName, ns) By("Expecting to observe notifications for all changes to the configmap since the first watch closed") expectEvent(testWatchRestarted, watch.Modified, testConfigMapSecondUpdate) @@ -250,9 +251,10 @@ var _ = SIGDescribe("Watchers", func() { c := f.ClientSet ns := f.Namespace.Name + configMapName := "e2e-watch-test-label-changed" testConfigMap := &v1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ - Name: "e2e-watch-test-label-changed", + Name: configMapName, Labels: map[string]string{ watchConfigMapLabelKey: toBeChangedLabelValue, }, @@ -261,23 +263,23 @@ var _ = SIGDescribe("Watchers", func() { By("creating a watch on configmaps with a certain label") testWatch, err := watchConfigMaps(f, "", toBeChangedLabelValue) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to create a watch on configmap with label: %s", toBeChangedLabelValue) By("creating a new configmap") testConfigMap, err = c.CoreV1().ConfigMaps(ns).Create(testConfigMap) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to create configmap %s in namespace: %s", configMapName, ns) By("modifying the configmap once") testConfigMapFirstUpdate, err := updateConfigMap(c, ns, testConfigMap.GetName(), func(cm *v1.ConfigMap) { setConfigMapData(cm, "mutation", "1") }) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to update configmap %s in namespace: %s", configMapName, ns) By("changing the label value of the configmap") _, err = updateConfigMap(c, ns, testConfigMap.GetName(), func(cm *v1.ConfigMap) { cm.ObjectMeta.Labels[watchConfigMapLabelKey] = "wrong-value" }) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to update configmap %s in namespace %s by changing label value", configMapName, ns) By("Expecting to observe a delete notification for the watched object") expectEvent(testWatch, watch.Added, testConfigMap) @@ -288,7 +290,7 @@ var _ = SIGDescribe("Watchers", func() { testConfigMapSecondUpdate, err := updateConfigMap(c, ns, testConfigMap.GetName(), func(cm *v1.ConfigMap) { setConfigMapData(cm, "mutation", "2") }) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to update configmap %s in namespace %s a second time", configMapName, ns) By("Expecting not to observe a notification because the object no longer meets the selector's requirements") expectNoEvent(testWatch, watch.Modified, testConfigMapSecondUpdate) @@ -297,17 +299,17 @@ var _ = SIGDescribe("Watchers", func() { testConfigMapLabelRestored, err := updateConfigMap(c, ns, testConfigMap.GetName(), func(cm *v1.ConfigMap) { cm.ObjectMeta.Labels[watchConfigMapLabelKey] = toBeChangedLabelValue }) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to update configmap %s in namespace %s by changing label value back", configMapName, ns) By("modifying the configmap a third time") testConfigMapThirdUpdate, err := updateConfigMap(c, ns, testConfigMap.GetName(), func(cm *v1.ConfigMap) { setConfigMapData(cm, "mutation", "3") }) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to update configmap %s in namespace %s a third time", configMapName, ns) By("deleting the configmap") err = c.CoreV1().ConfigMaps(ns).Delete(testConfigMap.GetName(), nil) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to delete configmap %s in namespace: %s", configMapName, ns) By("Expecting to observe an add notification for the watched object when the label value was restored") expectEvent(testWatch, watch.Added, testConfigMapLabelRestored) diff --git a/test/e2e/apimachinery/webhook.go b/test/e2e/apimachinery/webhook.go index b71b174dfb..72c5ea67c0 100644 --- a/test/e2e/apimachinery/webhook.go +++ b/test/e2e/apimachinery/webhook.go @@ -620,7 +620,7 @@ func testWebhook(f *framework.Framework) { // Creating the pod, the request should be rejected pod := nonCompliantPod(f) _, err := client.CoreV1().Pods(f.Namespace.Name).Create(pod) - Expect(err).NotTo(BeNil()) + Expect(err).To(HaveOccurred(), "create pod %s in namespace %s should have been denied by webhook", pod.Name, f.Namespace.Name) expectedErrMsg1 := "the pod contains unwanted container name" if !strings.Contains(err.Error(), expectedErrMsg1) { framework.Failf("expect error contains %q, got %q", expectedErrMsg1, err.Error()) @@ -635,7 +635,7 @@ func testWebhook(f *framework.Framework) { // Creating the pod, the request should be rejected pod = hangingPod(f) _, err = client.CoreV1().Pods(f.Namespace.Name).Create(pod) - Expect(err).NotTo(BeNil()) + Expect(err).To(HaveOccurred(), "create pod %s in namespace %s should have caused webhook to hang", pod.Name, f.Namespace.Name) expectedTimeoutErr := "request did not complete within" if !strings.Contains(err.Error(), expectedTimeoutErr) { framework.Failf("expect timeout error %q, got %q", expectedTimeoutErr, err.Error()) @@ -645,7 +645,7 @@ func testWebhook(f *framework.Framework) { // Creating the configmap, the request should be rejected configmap := nonCompliantConfigMap(f) _, err = client.CoreV1().ConfigMaps(f.Namespace.Name).Create(configmap) - Expect(err).NotTo(BeNil()) + Expect(err).To(HaveOccurred(), "create configmap %s in namespace %s should have been denied by the webhook", configmap.Name, f.Namespace.Name) expectedErrMsg := "the configmap contains unwanted key and value" if !strings.Contains(err.Error(), expectedErrMsg) { framework.Failf("expect error contains %q, got %q", expectedErrMsg, err.Error()) @@ -662,7 +662,7 @@ func testWebhook(f *framework.Framework) { }, } _, err = client.CoreV1().ConfigMaps(f.Namespace.Name).Create(configmap) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "failed to create configmap %s in namespace: %s", configmap.Name, f.Namespace.Name) By("update (PUT) the admitted configmap to a non-compliant one should be rejected by the webhook") toNonCompliantFn := func(cm *v1.ConfigMap) { @@ -672,7 +672,7 @@ func testWebhook(f *framework.Framework) { cm.Data["webhook-e2e-test"] = "webhook-disallow" } _, err = updateConfigMap(client, f.Namespace.Name, allowedConfigMapName, toNonCompliantFn) - Expect(err).NotTo(BeNil()) + Expect(err).To(HaveOccurred(), "update (PUT) admitted configmap %s in namespace %s to a non-compliant one should be rejected by webhook", allowedConfigMapName, f.Namespace.Name) if !strings.Contains(err.Error(), expectedErrMsg) { framework.Failf("expect error contains %q, got %q", expectedErrMsg, err.Error()) } @@ -680,7 +680,7 @@ func testWebhook(f *framework.Framework) { By("update (PATCH) the admitted configmap to a non-compliant one should be rejected by the webhook") patch := nonCompliantConfigMapPatch() _, err = client.CoreV1().ConfigMaps(f.Namespace.Name).Patch(allowedConfigMapName, types.StrategicMergePatchType, []byte(patch)) - Expect(err).NotTo(BeNil()) + Expect(err).To(HaveOccurred(), "update admitted configmap %s in namespace %s by strategic merge patch to a non-compliant one should be rejected by webhook. Patch: %+v", allowedConfigMapName, f.Namespace.Name, patch) if !strings.Contains(err.Error(), expectedErrMsg) { framework.Failf("expect error contains %q, got %q", expectedErrMsg, err.Error()) } @@ -699,7 +699,7 @@ func testWebhook(f *framework.Framework) { By("create a configmap that violates the webhook policy but is in a whitelisted namespace") configmap = nonCompliantConfigMap(f) _, err = client.CoreV1().ConfigMaps(skippedNamespaceName).Create(configmap) - Expect(err).To(BeNil()) + Expect(err).NotTo(HaveOccurred(), "failed to create configmap %s in namespace: %s", configmap.Name, skippedNamespaceName) } func testAttachingPodWebhook(f *framework.Framework) { @@ -707,15 +707,15 @@ func testAttachingPodWebhook(f *framework.Framework) { client := f.ClientSet pod := toBeAttachedPod(f) _, err := client.CoreV1().Pods(f.Namespace.Name).Create(pod) - Expect(err).To(BeNil()) + Expect(err).NotTo(HaveOccurred(), "failed to create pod %s in namespace: %s", pod.Name, f.Namespace.Name) err = framework.WaitForPodNameRunningInNamespace(client, pod.Name, f.Namespace.Name) - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred(), "error while waiting for pod %s to go to Running phase in namespace: %s", pod.Name, f.Namespace.Name) By("'kubectl attach' the pod, should be denied by the webhook") timer := time.NewTimer(30 * time.Second) defer timer.Stop() _, err = framework.NewKubectlCommand("attach", fmt.Sprintf("--namespace=%v", f.Namespace.Name), pod.Name, "-i", "-c=container1").WithTimeout(timer.C).Exec() - Expect(err).NotTo(BeNil()) + Expect(err).To(HaveOccurred(), "'kubectl attach' the pod, should be denied by the webhook") if e, a := "attaching to pod 'to-be-attached-pod' is not allowed", err.Error(); !strings.Contains(a, e) { framework.Failf("unexpected 'kubectl attach' error message. expected to contain %q, got %q", e, a) } @@ -804,7 +804,7 @@ func testFailClosedWebhook(f *framework.Framework) { }, } _, err = client.CoreV1().ConfigMaps(failNamespaceName).Create(configmap) - Expect(err).To(HaveOccurred()) + Expect(err).To(HaveOccurred(), "create configmap in namespace: %s should be unconditionally rejected by the webhook", failNamespaceName) if !errors.IsInternalError(err) { framework.Failf("expect an internal error, got %#v", err) } @@ -1242,12 +1242,13 @@ func registerMutatingWebhookForCustomResource(f *framework.Framework, context *c func testCustomResourceWebhook(f *framework.Framework, crd *apiextensionsv1beta1.CustomResourceDefinition, customResourceClient dynamic.ResourceInterface) { By("Creating a custom resource that should be denied by the webhook") + crInstanceName := "cr-instance-1" crInstance := &unstructured.Unstructured{ Object: map[string]interface{}{ "kind": crd.Spec.Names.Kind, "apiVersion": crd.Spec.Group + "/" + crd.Spec.Version, "metadata": map[string]interface{}{ - "name": "cr-instance-1", + "name": crInstanceName, "namespace": f.Namespace.Name, }, "data": map[string]interface{}{ @@ -1256,7 +1257,7 @@ func testCustomResourceWebhook(f *framework.Framework, crd *apiextensionsv1beta1 }, } _, err := customResourceClient.Create(crInstance, metav1.CreateOptions{}) - Expect(err).NotTo(BeNil()) + Expect(err).To(HaveOccurred(), "create custom resource %s in namespace %s should be denied by webhook", crInstanceName, f.Namespace.Name) expectedErrMsg := "the custom resource contains unwanted data" if !strings.Contains(err.Error(), expectedErrMsg) { framework.Failf("expect error contains %q, got %q", expectedErrMsg, err.Error()) @@ -1265,12 +1266,13 @@ func testCustomResourceWebhook(f *framework.Framework, crd *apiextensionsv1beta1 func testMutatingCustomResourceWebhook(f *framework.Framework, crd *apiextensionsv1beta1.CustomResourceDefinition, customResourceClient dynamic.ResourceInterface) { By("Creating a custom resource that should be mutated by the webhook") + crName := "cr-instance-1" cr := &unstructured.Unstructured{ Object: map[string]interface{}{ "kind": crd.Spec.Names.Kind, "apiVersion": crd.Spec.Group + "/" + crd.Spec.Version, "metadata": map[string]interface{}{ - "name": "cr-instance-1", + "name": crName, "namespace": f.Namespace.Name, }, "data": map[string]interface{}{ @@ -1279,7 +1281,7 @@ func testMutatingCustomResourceWebhook(f *framework.Framework, crd *apiextension }, } mutatedCR, err := customResourceClient.Create(cr, metav1.CreateOptions{}) - Expect(err).To(BeNil()) + Expect(err).NotTo(HaveOccurred(), "failed to create custom resource %s in namespace: %s", crName, f.Namespace.Name) expectedCRData := map[string]interface{}{ "mutation-start": "yes", "mutation-stage-1": "yes", @@ -1382,7 +1384,7 @@ func testCRDDenyWebhook(f *framework.Framework) { // create CRD _, err = apiExtensionClient.ApiextensionsV1beta1().CustomResourceDefinitions().Create(crd) - Expect(err).NotTo(BeNil()) + Expect(err).To(HaveOccurred(), "create custom resource definition %s should be denied by webhook", testcrd.GetMetaName()) expectedErrMsg := "the crd contains unwanted label" if !strings.Contains(err.Error(), expectedErrMsg) { framework.Failf("expect error contains %q, got %q", expectedErrMsg, err.Error())