diff --git a/test/e2e/e2e_helpers.go b/test/e2e/e2e_helpers.go index 63ff1472..f8d39e17 100644 --- a/test/e2e/e2e_helpers.go +++ b/test/e2e/e2e_helpers.go @@ -5,7 +5,9 @@ package e2e import ( "bufio" + "errors" "fmt" + "io" "os" "os/exec" "strings" @@ -249,9 +251,31 @@ func DeployOperator(namespace string, image string) { EventuallyWithOffset(1, verifyControllerUp, 120*time.Second, time.Second).Should(Succeed()) } -func UndeployOperator() { +func UndeployOperator(namespace string) { By("undeploying the controller-manager") ExpectWithOffset(1, RunAndIgnoreOutput(exec.Command("make", "undeploy"))).To(Succeed()) + + // We need to wait until the namespace is really gone, otherwise the next test/suite that tries to create the operator + // will run into issues when trying to recreate the namespace which is still in the process of being deleted. + ExpectWithOffset(1, RunAndIgnoreOutput(exec.Command( + "kubectl", + "wait", + "--for=delete", + fmt.Sprintf("namespace/%s", namespace), + "--timeout=60s", + ))).To(Succeed()) +} + +func DeployDash0Resource(namespace string) { + ExpectWithOffset(1, + RunAndIgnoreOutput(exec.Command( + "kubectl", "apply", "-n", namespace, "-k", "config/samples"))).To(Succeed()) +} + +func UndeployDash0Resource(namespace string) { + ExpectWithOffset(1, + RunAndIgnoreOutput(exec.Command( + "kubectl", "delete", "-n", namespace, "-k", "config/samples"))).To(Succeed()) } func InstallNodeJsDeployment(namespace string) error { @@ -381,3 +405,23 @@ func GetProjectDir() (string, error) { wd = strings.Replace(wd, "/test/e2e", "", -1) return wd, nil } + +func CopyFile(source string, destination string) error { + src, err := os.Open(source) + if err != nil { + return err + } + defer func() { + err = errors.Join(err, src.Close()) + }() + + dst, err := os.Create(destination) + if err != nil { + return err + } + defer func() { + err = errors.Join(err, dst.Close()) + }() + _, err = io.Copy(dst, src) + return err +} diff --git a/test/e2e/e2e_test.go b/test/e2e/e2e_test.go index 7dcbaa6b..9786c330 100644 --- a/test/e2e/e2e_test.go +++ b/test/e2e/e2e_test.go @@ -4,9 +4,7 @@ package e2e import ( - "errors" "fmt" - "io" "os" "os/exec" "strings" @@ -63,7 +61,7 @@ var _ = Describe("Dash0 Kubernetes Operator", Ordered, func() { fmt.Fprintf(GinkgoWriter, "original imagePullPolicy: %s\n", originalImagePullPolicy) if originalImagePullPolicy != "Never" { - err = copyFile(managerYaml, managerYamlBackup) + err = CopyFile(managerYaml, managerYamlBackup) ExpectWithOffset(1, err).NotTo(HaveOccurred()) managerYamlNeedsRevert = true By("temporarily changing imagePullPolicy to \"Never\"") @@ -92,7 +90,7 @@ var _ = Describe("Dash0 Kubernetes Operator", Ordered, func() { applicationNamespaceHasBeenCreated = EnsureNamespaceExists(applicationUnderTestNamespace) - By("installing the collector") + By("(re)installing the collector") ExpectWithOffset(1, ReinstallCollectorAndClearExportedTelemetry(applicationUnderTestNamespace)).To(Succeed()) By("creating manager namespace") @@ -112,7 +110,7 @@ var _ = Describe("Dash0 Kubernetes Operator", Ordered, func() { if managerYamlNeedsRevert { By("reverting changes to " + managerYaml) - err := copyFile(managerYamlBackup, managerYaml) + err := CopyFile(managerYamlBackup, managerYaml) ExpectWithOffset(1, err).NotTo(HaveOccurred()) err = os.Remove(managerYamlBackup) ExpectWithOffset(1, err).NotTo(HaveOccurred()) @@ -146,38 +144,35 @@ var _ = Describe("Dash0 Kubernetes Operator", Ordered, func() { BeforeAll(func() { DeployOperator(operatorNamespace, operatorImage) - fmt.Fprint(GinkgoWriter, "waiting 10 seconds\n") + fmt.Fprint(GinkgoWriter, "waiting 10 seconds to give the webook some time to get ready\n") time.Sleep(10 * time.Second) }) AfterAll(func() { - UndeployOperator() + UndeployOperator(operatorNamespace) }) It("should modify new deployments", func() { By("installing the Node.js deployment") Expect(InstallNodeJsDeployment(applicationUnderTestNamespace)).To(Succeed()) + By("verifying that the Node.js deployment has been instrumented by the webhook") SendRequestsAndVerifySpansHaveBeenProduced() }) }) -}) -func copyFile(source string, destination string) error { - src, err := os.Open(source) - if err != nil { - return err - } - defer func() { - err = errors.Join(err, src.Close()) - }() - - dst, err := os.Create(destination) - if err != nil { - return err - } - defer func() { - err = errors.Join(err, dst.Close()) - }() - _, err = io.Copy(dst, src) - return err -} + Context("the Dash0 operator controller", func() { + AfterAll(func() { + UndeployDash0Resource(applicationUnderTestNamespace) + UndeployOperator(operatorNamespace) + }) + + It("should modify existing deployments", func() { + By("installing the Node.js deployment") + Expect(InstallNodeJsDeployment(applicationUnderTestNamespace)).To(Succeed()) + DeployOperator(operatorNamespace, operatorImage) + DeployDash0Resource(applicationUnderTestNamespace) + By("verifying that the Node.js deployment has been instrumented by the controller") + SendRequestsAndVerifySpansHaveBeenProduced() + }) + }) +})