diff --git a/tests/e2e/sp_container_status_test.go b/tests/e2e/sp_container_status_test.go index 76e4964..297f6b9 100644 --- a/tests/e2e/sp_container_status_test.go +++ b/tests/e2e/sp_container_status_test.go @@ -307,8 +307,11 @@ var _ = Describe("Container SP Status Events", Label("sp", "container", "nats"), By("waiting for RUNNING status") collector.WaitForStatus(containerID, "RUNNING", 60*time.Second) + By("resolving the actual Deployment name (SP uses GenerateName)") + deployName := findDeploymentName(containerID) + By("scaling the Deployment to zero via kubectl") - _, err := runKubectl("scale", "deployment", name, "--replicas=0") + _, err := runKubectl("scale", "deployment", deployName, "--replicas=0") Expect(err).NotTo(HaveOccurred()) By("waiting for a non-RUNNING status event") diff --git a/tests/e2e/sp_helpers_test.go b/tests/e2e/sp_helpers_test.go index ccce86e..c1320bf 100644 --- a/tests/e2e/sp_helpers_test.go +++ b/tests/e2e/sp_helpers_test.go @@ -274,14 +274,33 @@ func requireKubectl() { } } -// runKubectl executes a kubectl/oc command and returns stdout. +// runKubectl executes a kubectl/oc command and returns combined output. func runKubectl(args ...string) (string, error) { fullArgs := append([]string{"-n", spNamespace}, args...) cmd := exec.Command(kubectlBin, fullArgs...) out, err := cmd.CombinedOutput() + if err != nil { + GinkgoWriter.Printf("kubectl %v failed: %s\n", args, string(out)) + } return string(out), err } +// findDeploymentName returns the Kubernetes Deployment name for a DCM +// container instance. The SP uses GenerateName so the actual Deployment +// name has a random suffix; this helper resolves it via label selector. +func findDeploymentName(containerID string) string { + selector := "dcm.project/dcm-instance-id=" + containerID + out, err := runKubectl("get", "deployment", + "-l", selector, + "-o", "jsonpath={.items[0].metadata.name}") + ExpectWithOffset(1, err).NotTo(HaveOccurred(), + "failed to look up Deployment for container %s", containerID) + name := strings.TrimSpace(out) + ExpectWithOffset(1, name).NotTo(BeEmpty(), + "no Deployment found with label %s", selector) + return name +} + // --- Podman helpers ------------------------------------------------------- //