Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion tests/e2e/sp_container_status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
21 changes: 20 additions & 1 deletion tests/e2e/sp_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 ------------------------------------------------------- //

Expand Down
Loading