From d40e02bc383b0de63a036c13a3d1a192975ecdee Mon Sep 17 00:00:00 2001 From: Aditya Bhatia <7274741+adityabhatia@users.noreply.github.com> Date: Wed, 20 Sep 2023 18:48:33 +0200 Subject: [PATCH] attempt to fix tests and lint issues --- test/e2e/quick_start_test.go | 24 +++++++++++++----------- test/framework/finalizers_helpers.go | 19 +++++++++++-------- test/framework/ownerreference_helpers.go | 2 +- 3 files changed, 25 insertions(+), 20 deletions(-) diff --git a/test/e2e/quick_start_test.go b/test/e2e/quick_start_test.go index 6f04ed3f1038..4335b7579c59 100644 --- a/test/e2e/quick_start_test.go +++ b/test/e2e/quick_start_test.go @@ -185,11 +185,12 @@ var _ = Describe("When following the Cluster API quick-start with dualstack and var _ = Describe("When following the Cluster API quick-start check finalizers resilience after deletion", func() { QuickStartSpec(ctx, func() QuickStartSpecInput { return QuickStartSpecInput{ - E2EConfig: e2eConfig, - ClusterctlConfigPath: clusterctlConfigPath, - BootstrapClusterProxy: bootstrapClusterProxy, - ArtifactFolder: artifactFolder, - SkipCleanup: skipCleanup, + E2EConfig: e2eConfig, + ClusterctlConfigPath: clusterctlConfigPath, + BootstrapClusterProxy: bootstrapClusterProxy, + ArtifactFolder: artifactFolder, + SkipCleanup: skipCleanup, + InfrastructureProvider: pointer.String("docker"), PostMachinesProvisioned: func(proxy framework.ClusterProxy, namespace, clusterName string) { // This check ensures that finalizers are resilient - i.e. correctly re-reconciled - when removed. framework.ValidateFinalizersResilience(ctx, proxy, namespace, clusterName) @@ -201,12 +202,13 @@ var _ = Describe("When following the Cluster API quick-start check finalizers re var _ = Describe("When following the Cluster API quick-start with ClusterClass check finalizers resilience after deletion [ClusterClass]", func() { QuickStartSpec(ctx, func() QuickStartSpecInput { return QuickStartSpecInput{ - E2EConfig: e2eConfig, - ClusterctlConfigPath: clusterctlConfigPath, - BootstrapClusterProxy: bootstrapClusterProxy, - ArtifactFolder: artifactFolder, - SkipCleanup: skipCleanup, - Flavor: pointer.String("topology"), + E2EConfig: e2eConfig, + ClusterctlConfigPath: clusterctlConfigPath, + BootstrapClusterProxy: bootstrapClusterProxy, + ArtifactFolder: artifactFolder, + SkipCleanup: skipCleanup, + Flavor: pointer.String("topology"), + InfrastructureProvider: pointer.String("docker"), PostMachinesProvisioned: func(proxy framework.ClusterProxy, namespace, clusterName string) { // This check ensures that finalizers are resilient - i.e. correctly re-reconciled - when removed. framework.ValidateFinalizersResilience(ctx, proxy, namespace, clusterName) diff --git a/test/framework/finalizers_helpers.go b/test/framework/finalizers_helpers.go index a4ab71e5469e..c77bc0227070 100644 --- a/test/framework/finalizers_helpers.go +++ b/test/framework/finalizers_helpers.go @@ -19,14 +19,14 @@ package framework import ( "context" "fmt" - "sigs.k8s.io/cluster-api/util/patch" "time" . "github.com/onsi/gomega" - "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" - clusterctlcluster "sigs.k8s.io/cluster-api/cmd/clusterctl/client/cluster" "sigs.k8s.io/controller-runtime/pkg/client" + + clusterctlcluster "sigs.k8s.io/cluster-api/cmd/clusterctl/client/cluster" + "sigs.k8s.io/cluster-api/util/patch" ) // ValidateFinalizersResilience checks that expected finalizers are in place, deletes them, and verifies that expected finalizers are properly added again. @@ -58,18 +58,21 @@ func ValidateFinalizersResilience(ctx context.Context, proxy ClusterProxy, names func getFinalizersFromAllObjs(ctx context.Context, proxy ClusterProxy, namespace string) map[string][]string { finalizers := map[string][]string{} - graph, err := clusterctlcluster.GetOwnerGraph(ctx, proxy.GetKubeconfigPath(), namespace) - Expect(err).To(BeNil()) + + graph, err := clusterctlcluster.GetOwnerGraph(ctx, namespace, proxy.GetKubeconfigPath()) + Expect(err).ToNot(HaveOccurred()) + for _, v := range graph { obj := &unstructured.Unstructured{} obj.SetAPIVersion(v.Object.APIVersion) obj.SetKind(v.Object.Kind) - err := proxy.GetClient().Get(ctx, client.ObjectKey{Namespace: v.Object.Namespace, Name: v.Object.Name}, obj) - Expect(err).To(BeNil()) + err = proxy.GetClient().Get(ctx, client.ObjectKey{Namespace: v.Object.Namespace, Name: v.Object.Name}, obj) + Expect(err).ToNot(HaveOccurred()) if obj.GetFinalizers() != nil { finalizers[fmt.Sprintf("%s/%s", v.Object.Kind, client.ObjectKey{Name: v.Object.Name, Namespace: v.Object.Namespace}.String())] = obj.GetFinalizers() } } + return finalizers } @@ -105,6 +108,6 @@ func assertFinalizersExist(ctx context.Context, proxy ClusterProxy, namespace st for k, v := range missing { missingString = fmt.Sprintf("%s\n%s %s", missingString, k, v) } - Expect(len(missing)).To(Equal(0), missingString) + Expect(missing).To(BeEmpty(), missingString) }).WithTimeout(5 * time.Minute).WithPolling(2 * time.Second).Should(Succeed()) } diff --git a/test/framework/ownerreference_helpers.go b/test/framework/ownerreference_helpers.go index 0b727891df58..24acf0861e6e 100644 --- a/test/framework/ownerreference_helpers.go +++ b/test/framework/ownerreference_helpers.go @@ -104,7 +104,7 @@ func AssertOwnerReferences(namespace, kubeconfigPath string, assertFuncs ...map[ } } Eventually(func() error { - allErrs := []error{} + var allErrs []error ctx := context.Background() graph, err := clusterctlcluster.GetOwnerGraph(ctx, namespace, kubeconfigPath)