diff --git a/e2e/drift/drift_test.go b/e2e/drift/drift_test.go index 0de9030e60..72dbf56666 100644 --- a/e2e/drift/drift_test.go +++ b/e2e/drift/drift_test.go @@ -2,6 +2,7 @@ package examples_test import ( "encoding/json" + "fmt" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -32,13 +33,24 @@ var _ = Describe("Drift", Ordered, func() { b := getBundle(bundleName, k) return b.Status.Summary.Ready == 1 }).Should(BeTrue()) + + defer func() { + if r := recover(); r != nil { + bundle := getBundle(bundleName, k) + GinkgoWriter.Printf("bundle status: %v", bundle.Status) + } + }() }) AfterEach(func() { - out, err := k.Namespace(env.Namespace).Delete("-f", testenv.AssetPath(asset)) + out, err := k.Namespace(env.Namespace).Delete("-f", testenv.AssetPath(asset), "--wait") Expect(err).ToNot(HaveOccurred(), out) }) + AfterAll(func() { + _, _ = k.Delete("ns", namespace) + }) + When("Drift correction is not enabled", func() { BeforeEach(func() { asset = "drift/correction-disabled/gitrepo.yaml" @@ -50,10 +62,12 @@ var _ = Describe("Drift", Ordered, func() { kw := k.Namespace(namespace) out, err := kw.Patch( "service", "nginx-service", + "-o=json", "--type=json", "-p", `[{"op": "replace", "path": "/spec/externalName", "value": "modified"}]`, ) Expect(err).ToNot(HaveOccurred(), out) + GinkgoWriter.Print(out) }) It("Bundle is modified", func() { @@ -81,10 +95,12 @@ var _ = Describe("Drift", Ordered, func() { kw := k.Namespace(namespace) out, err := kw.Patch( "service", "nginx-service", + "-o=json", "--type=json", "-p", `[{"op": "replace", "path": "/spec/externalName", "value": "modified"}]`, ) Expect(err).ToNot(HaveOccurred(), out) + GinkgoWriter.Print(out) }) It("Drift is corrected", func() { @@ -107,10 +123,12 @@ var _ = Describe("Drift", Ordered, func() { kw := k.Namespace(namespace) out, err := kw.Patch( "deployment", "nginx-deployment", + "-o=json", "--type=json", "-p", `[{"op": "replace", "path": "/spec/template/spec/containers/0/image", "value": "nginx:modified"}]`, ) Expect(err).ToNot(HaveOccurred(), out) + GinkgoWriter.Print(out) }) It("Drift is corrected", func() { @@ -133,10 +151,12 @@ var _ = Describe("Drift", Ordered, func() { kw := k.Namespace(namespace) out, err := kw.Patch( "configmap", "configmap", + "-o=json", "--type=json", "-p", `[{"op": "replace", "path": "/data/foo", "value": "modified"}]`, ) Expect(err).ToNot(HaveOccurred(), out) + GinkgoWriter.Print(out) }) It("Drift is corrected", func() { @@ -169,10 +189,12 @@ var _ = Describe("Drift", Ordered, func() { kw := k.Namespace(namespace) out, err := kw.Patch( "service", "nginx-service", + "-o=json", "--type=json", "-p", `[{"op": "replace", "path": "/spec/ports/0/port", "value": 1234}]`, ) Expect(err).ToNot(HaveOccurred(), out) + GinkgoWriter.Print(out) }) It("Status is modified", func() { @@ -209,17 +231,20 @@ var _ = Describe("Drift", Ordered, func() { kw := k.Namespace(namespace) out, err := kw.Patch( "service", "nginx-service", + "-o=json", "--type=json", "-p", `[{"op": "replace", "path": "/spec/ports/0/port", "value": 1234}]`, ) Expect(err).ToNot(HaveOccurred(), out) + GinkgoWriter.Print(out) }) It("Bundle Status is Ready, and changes are rolled back", func() { - Eventually(func() bool { - b := getBundle(bundleName, k) - return b.Status.Summary.Ready == 1 - }).Should(BeTrue()) + var bundle fleet.Bundle + Eventually(func() int { + bundle = getBundle(bundleName, k) + return bundle.Status.Summary.Ready + }).Should(Equal(1), fmt.Sprintf("Summary: %+v", bundle.Status.Summary)) Eventually(func() bool { kw := k.Namespace(namespace) out, _ := kw.Get("services", "nginx-service", "-o=json") diff --git a/e2e/metrics/bundledeployment_test.go b/e2e/metrics/bundledeployment_test.go index c716129bb0..cf38ccf437 100644 --- a/e2e/metrics/bundledeployment_test.go +++ b/e2e/metrics/bundledeployment_test.go @@ -24,6 +24,8 @@ var _ = Describe("BundleDeployment Metrics", Label("bundledeployment"), func() { // random namespace, like it is the case for the other tests. objName string + targetNS string + r = rand.New(rand.NewSource(GinkgoRandomSeed())) ) @@ -31,7 +33,7 @@ var _ = Describe("BundleDeployment Metrics", Label("bundledeployment"), func() { k = env.Kubectl.Namespace(env.Namespace) kw = k.Namespace(namespace) objName = testenv.AddRandomSuffix("metrics", r) - targetNS := testenv.NewNamespaceName("metrics", r) + targetNS = testenv.NewNamespaceName("metrics", r) err := testenv.CreateGitRepo( kw, @@ -51,6 +53,9 @@ var _ = Describe("BundleDeployment Metrics", Label("bundledeployment"), func() { DeferCleanup(func() { out, err := k.Delete("gitrepo", objName) Expect(err).ToNot(HaveOccurred(), out) + + out, err = k.Delete("ns", targetNS, "--wait=false") + Expect(err).ToNot(HaveOccurred(), out) }) }) diff --git a/e2e/single-cluster/delete_namespaces_test.go b/e2e/single-cluster/delete_namespaces_test.go index 19dce94a1f..b8a2b8e114 100644 --- a/e2e/single-cluster/delete_namespaces_test.go +++ b/e2e/single-cluster/delete_namespaces_test.go @@ -30,7 +30,7 @@ var _ = Describe("delete namespaces", func() { deleteNamespace = false DeferCleanup(func() { - _, _ = k.Delete("ns", "my-custom-namespace", "--wait=false") + _, _ = k.Delete("ns", "my-custom-namespace") }) }) diff --git a/e2e/single-cluster/finalizers_test.go b/e2e/single-cluster/finalizers_test.go index 815933eaa4..0e2b7dcdec 100644 --- a/e2e/single-cluster/finalizers_test.go +++ b/e2e/single-cluster/finalizers_test.go @@ -45,6 +45,7 @@ var _ = Describe("Deleting a resource with finalizers", func() { _, _ = k.Delete("gitrepo", gitrepoName) _, _ = k.Delete("bundle", fmt.Sprintf("%s-%s", gitrepoName, path)) + _, _ = k.Delete("ns", targetNamespace, "--wait=false") }) When("deleting an existing GitRepo", func() { @@ -277,8 +278,8 @@ var _ = Describe("Deleting a resource with finalizers", func() { Expect(out).ToNot(BeZero()) By("checking that the configmap created by the bundle deployment still exists") - _, err = k.Namespace(targetNamespace).Get("configmap", "test-simple-chart-config") - Expect(err).ToNot(HaveOccurred()) + out, err = k.Namespace(targetNamespace).Get("configmap", "test-simple-chart-config") + Expect(err).ToNot(HaveOccurred(), out) }) }) }) diff --git a/e2e/single-cluster/gitrepo_polling_disabled_test.go b/e2e/single-cluster/gitrepo_polling_disabled_test.go index c83513f319..a2e67dc323 100644 --- a/e2e/single-cluster/gitrepo_polling_disabled_test.go +++ b/e2e/single-cluster/gitrepo_polling_disabled_test.go @@ -67,7 +67,15 @@ var _ = Describe("GitRepoPollingDisabled", Label("infra-setup"), func() { "fleet-controller", ) Expect(err).ToNot(HaveOccurred()) - Expect(out).ToNot(ContainSubstring("ERROR")) + + // Errors about resources other than bundles or bundle deployments not being found at deletion time + // should be ignored, as they may result from other test suites. + Expect(out).ToNot(MatchRegexp( + `ERROR.*Reconciler error.*Bundle(Deployment)?.fleet.cattle.io \\".*\\" not found`, + )) + + _, err = k.Delete("ns", targetNamespace) + Expect(err).ToNot(HaveOccurred()) }) When("applying a gitrepo with disable polling", func() { diff --git a/e2e/single-cluster/gitrepo_test.go b/e2e/single-cluster/gitrepo_test.go index 855037f9ac..5c9792c257 100644 --- a/e2e/single-cluster/gitrepo_test.go +++ b/e2e/single-cluster/gitrepo_test.go @@ -49,6 +49,7 @@ var _ = Describe("Monitoring Git repos via HTTP for change", Label("infra-setup" }) JustBeforeEach(func() { + // Build git repo URL reachable _within_ the cluster, for the GitRepo host, err := githelper.BuildGitHostname(env.Namespace) Expect(err).ToNot(HaveOccurred()) @@ -87,7 +88,15 @@ var _ = Describe("Monitoring Git repos via HTTP for change", Label("infra-setup" "fleet-controller", ) Expect(err).ToNot(HaveOccurred()) - Expect(out).ToNot(ContainSubstring("ERROR")) + + // Errors about resources other than bundles or bundle deployments not being found at deletion time + // should be ignored, as they may result from other test suites. + Expect(out).ToNot(MatchRegexp( + `ERROR.*Reconciler error.*Bundle(Deployment)?.fleet.cattle.io \\".*\\" not found`, + )) + + _, err = k.Delete("ns", targetNamespace) + Expect(err).ToNot(HaveOccurred()) }) When("updating a git repository monitored via polling", func() { diff --git a/e2e/single-cluster/helm_auth_test.go b/e2e/single-cluster/helm_auth_test.go index 80799e519c..89fb677913 100644 --- a/e2e/single-cluster/helm_auth_test.go +++ b/e2e/single-cluster/helm_auth_test.go @@ -1,6 +1,7 @@ package singlecluster_test import ( + "fmt" "os" "path" @@ -14,10 +15,11 @@ import ( var _ = Describe("Single Cluster Examples", Label("infra-setup"), func() { var ( - gitRepoPath string - tmpdir string - k kubectl.Command - gh *githelper.Git + gitRepoPath string + tmpdir string + k kubectl.Command + gh *githelper.Git + targetNamespace string ) JustBeforeEach(func() { @@ -47,6 +49,7 @@ var _ = Describe("Single Cluster Examples", Label("infra-setup"), func() { Context("containing a private OCI-based helm chart", Label("oci-registry"), func() { BeforeEach(func() { gitRepoPath = "oci-with-auth" + targetNamespace = fmt.Sprintf("fleet-helm-%s", gitRepoPath) k = env.Kubectl.Namespace(env.Namespace) tmpdir, gh = setupGitRepo(gitRepoPath, repoName, port) @@ -54,7 +57,7 @@ var _ = Describe("Single Cluster Examples", Label("infra-setup"), func() { It("deploys the helm chart", func() { Eventually(func() string { - out, _ := k.Namespace("fleet-helm-oci-with-auth").Get("pods", "--field-selector=status.phase==Running") + out, _ := k.Namespace(targetNamespace).Get("pods", "--field-selector=status.phase==Running") return out }).Should(ContainSubstring("sleeper-")) }) @@ -62,6 +65,7 @@ var _ = Describe("Single Cluster Examples", Label("infra-setup"), func() { Context("containing a private HTTP-based helm chart with repo path", Label("helm-registry"), func() { BeforeEach(func() { gitRepoPath = "http-with-auth-repo-path" + targetNamespace = fmt.Sprintf("fleet-helm-%s", gitRepoPath) k = env.Kubectl.Namespace(env.Namespace) tmpdir, gh = setupGitRepo(gitRepoPath, repoName, port) @@ -69,7 +73,7 @@ var _ = Describe("Single Cluster Examples", Label("infra-setup"), func() { It("deploys the helm chart", func() { Eventually(func() string { - out, _ := k.Namespace("fleet-helm-http-with-auth-repo-path").Get("pods", "--field-selector=status.phase==Running") + out, _ := k.Namespace(targetNamespace).Get("pods", "--field-selector=status.phase==Running") return out }).Should(ContainSubstring("sleeper-")) }) @@ -77,6 +81,7 @@ var _ = Describe("Single Cluster Examples", Label("infra-setup"), func() { Context("containing a private HTTP-based helm chart with chart path", Label("helm-registry"), func() { BeforeEach(func() { gitRepoPath = "http-with-auth-chart-path" + targetNamespace = fmt.Sprintf("fleet-helm-%s", gitRepoPath) k = env.Kubectl.Namespace(env.Namespace) tmpdir, gh = setupGitRepo(gitRepoPath, repoName, port) @@ -84,7 +89,7 @@ var _ = Describe("Single Cluster Examples", Label("infra-setup"), func() { It("deploys the helm chart", func() { Eventually(func() string { - out, _ := k.Namespace("fleet-helm-http-with-auth-chart-path").Get("pods", "--field-selector=status.phase==Running") + out, _ := k.Namespace(targetNamespace).Get("pods", "--field-selector=status.phase==Running") return out }).Should(ContainSubstring("sleeper-")) }) @@ -95,6 +100,7 @@ var _ = Describe("Single Cluster Examples", Label("infra-setup"), func() { os.RemoveAll(tmpdir) _, _ = k.Delete("gitrepo", "helm") + _, _ = k.Delete("ns", targetNamespace, "--wait=false") }) }) diff --git a/e2e/single-cluster/imagescan_test.go b/e2e/single-cluster/imagescan_test.go index 1e29f74ac1..aa37695d85 100644 --- a/e2e/single-cluster/imagescan_test.go +++ b/e2e/single-cluster/imagescan_test.go @@ -279,9 +279,13 @@ func tagAndPushImage(baseImage, image, tag string) string { } func initRegistryWithImageAndTag(baseImage string, tag string) (string, string) { - cmd := exec.Command("docker", "pull", baseImage) - err := cmd.Run() - Expect(err).ToNot(HaveOccurred()) + Eventually(func() error { + cmd := exec.Command("docker", "pull", baseImage) + err := cmd.Run() + + return err + }, 20*time.Second, 1*time.Second).Should(Succeed()) + // generate a new uuid for this test uuid := uuid.NewUUID() image := fmt.Sprintf("ttl.sh/%s-fleet-test", uuid) diff --git a/e2e/single-cluster/sharding_test.go b/e2e/single-cluster/sharding_test.go index 8466c517be..700fa080d8 100644 --- a/e2e/single-cluster/sharding_test.go +++ b/e2e/single-cluster/sharding_test.go @@ -115,6 +115,7 @@ var _ = Describe("Filtering events by shard", Label("sharding"), Ordered, func() AfterEach(func() { _, _ = k.Delete("gitrepo", gitrepoName) + _, _ = k.Delete("ns", targetNamespace, "--wait=false") }) }) } @@ -178,6 +179,7 @@ var _ = Describe("Filtering events by shard", Label("sharding"), Ordered, func() AfterEach(func() { _, _ = k.Delete("gitrepo", gitrepoName) + _, _ = k.Delete("ns", targetNamespace, "--wait=false") }) }) }) diff --git a/e2e/single-cluster/single_cluster_test.go b/e2e/single-cluster/single_cluster_test.go index e50f6ead67..8308d265dd 100644 --- a/e2e/single-cluster/single_cluster_test.go +++ b/e2e/single-cluster/single_cluster_test.go @@ -29,6 +29,7 @@ var _ = Describe("Single Cluster Deployments", func() { out, err := k.Delete("-f", testenv.AssetPath(asset)) Expect(err).ToNot(HaveOccurred(), out) + _, _ = k.Delete("ns", "helm-kustomize-disabled") }) When("creating a gitrepo resource", func() { @@ -37,6 +38,10 @@ var _ = Describe("Single Cluster Deployments", func() { asset = "single-cluster/helm-oci.yaml" }) + AfterEach(func() { + _, _ = k.Delete("ns", "fleet-helm-oci-example") + }) + It("deploys the helm chart", func() { Eventually(func() string { out, _ := k.Namespace("fleet-helm-oci-example").Get("configmaps") @@ -63,6 +68,11 @@ var _ = Describe("Single Cluster Deployments", func() { asset = "single-cluster/multiple-paths.yaml" }) + AfterEach(func() { + _, _ = k.Delete("ns", "test-fleet-mp-config") + _, _ = k.Delete("ns", "test-fleet-mp-service") + }) + It("sets status fields for gitrepo on deployment", func() { Eventually(func() bool { out, err := k.Get("gitrepo", "multiple-paths", "-n", "fleet-local", "-o", "jsonpath='{.status.summary}'") @@ -80,11 +90,19 @@ var _ = Describe("Single Cluster Deployments", func() { ContainSubstring("multiple-paths-multiple-paths-service"), )) - Eventually(func() bool { - out, err := k.Get("bundle", "multiple-paths-multiple-paths-config", "-n", "fleet-local", "-o", "jsonpath='{.status.summary}'") - Expect(err).ToNot(HaveOccurred(), out) - return strings.Contains(out, "\"ready\":1") - }).Should(BeTrue()) + Eventually(func(g Gomega) { + out, err := k.Get( + "bundle", + "multiple-paths-multiple-paths-config", + "-n", + "fleet-local", + "-o", + "jsonpath='{.status.summary}'", + ) + g.Expect(err).ToNot(HaveOccurred(), out) + + g.Expect(out).To(ContainSubstring(`"ready":1`)) + }).Should(Succeed()) Eventually(func() bool { out, err := k.Get("bundle", "multiple-paths-multiple-paths-service", "-n", "fleet-local", "-o", "jsonpath='{.status.summary}'") diff --git a/e2e/single-cluster/status_test.go b/e2e/single-cluster/status_test.go index beff13a21b..a8c9a58169 100644 --- a/e2e/single-cluster/status_test.go +++ b/e2e/single-cluster/status_test.go @@ -11,7 +11,7 @@ import ( "github.com/rancher/fleet/e2e/testenv/kubectl" ) -var _ = Describe("Checks status updates happen for a simple deployment", func() { +var _ = Describe("Checks status updates happen for a simple deployment", Ordered, func() { var ( k kubectl.Command targetNamespace string @@ -26,10 +26,6 @@ var _ = Describe("Checks status updates happen for a simple deployment", func() BeforeEach(func() { k = env.Kubectl.Namespace(env.Namespace) deleteNamespace = false - - DeferCleanup(func() { - _, _ = k.Delete("ns", "my-custom-namespace", "--wait=false") - }) }) JustBeforeEach(func() { @@ -51,6 +47,11 @@ var _ = Describe("Checks status updates happen for a simple deployment", func() }).ShouldNot(HaveOccurred()) }) + AfterAll(func() { + _, _ = k.Delete("gitrepo", "my-gitrepo") + _, _ = k.Delete("ns", "my-custom-namespace", "--wait=false") + }) + When("deployment is successful", func() { BeforeEach(func() { targetNamespace = "my-custom-namespace" diff --git a/integrationtests/controller/clustergroup/status_test.go b/integrationtests/controller/clustergroup/status_test.go index 63dc663d70..9322e28cc0 100644 --- a/integrationtests/controller/clustergroup/status_test.go +++ b/integrationtests/controller/clustergroup/status_test.go @@ -1,6 +1,8 @@ package clustergroup import ( + "fmt" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -61,8 +63,27 @@ var _ = Describe("ClusterGroup Status Fields", func() { } return k8sClient.Update(ctx, clusterGroup) }).ShouldNot(HaveOccurred()) - Expect(clusterGroup.Status.ClusterCount).To(Equal(1)) - Expect(clusterGroup.Status.Display.ReadyClusters).To(Equal("1/1")) + + Eventually(func() error { + if clusterGroup.Status.ClusterCount != 1 { + return fmt.Errorf( + "cluster group %s/%s has ClusterCount=%d, expected 1", + namespace, + groupName, + clusterGroup.Status.ClusterCount, + ) + } + if clusterGroup.Status.Display.ReadyClusters != "1/1" { + return fmt.Errorf( + "cluster group %s/%s has ReadyClusters=%s, expected '1/1'", + namespace, + groupName, + clusterGroup.Status.Display.ReadyClusters, + ) + } + + return nil + }).ShouldNot(HaveOccurred()) }) }) }) diff --git a/integrationtests/gitcloner/clone_test.go b/integrationtests/gitcloner/clone_test.go index 76dda32208..09f472457d 100644 --- a/integrationtests/gitcloner/clone_test.go +++ b/integrationtests/gitcloner/clone_test.go @@ -428,7 +428,7 @@ func createGogsContainerWithHTTPS() (testcontainers.Container, error) { gogsClient.SetHTTPClient(httpClient) return nil - }, timeout, "2s").ShouldNot(HaveOccurred()) + }, timeout, "10s").ShouldNot(HaveOccurred()) return container, nil }