Skip to content

Commit 4f01380

Browse files
committed
fix(test): only clean up containers created by image tests
- Restrict container cleanup to test-owned ones (cluster-images-populator-* and test-images-verify) - Extract verify container name as a constant - Export PopulatorContainerNamePrefix for reuse in tests
1 parent 7a1fef0 commit 4f01380

2 files changed

Lines changed: 16 additions & 12 deletions

File tree

internal/cluster/images.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,14 @@ var (
2323
)
2424

2525
const (
26-
ClusterImagesVolumePrefix = "cluster-images"
27-
ClusterImagesMountPath = "/var/lib/cluster-images"
28-
populatorContainerNamePrefix = "cluster-images-populator"
29-
26+
ClusterImagesVolumePrefix = "cluster-images"
27+
ClusterImagesMountPath = "/var/lib/cluster-images"
28+
PopulatorContainerNamePrefix = "cluster-images-populator"
3029
)
3130

3231
// PopulatorContainerName returns the populator container name scoped to a kubeadm version.
3332
func PopulatorContainerName(kubeadmVersion string) string {
34-
return populatorContainerNamePrefix + "-" + kubeadmVersion
33+
return PopulatorContainerNamePrefix + "-" + kubeadmVersion
3534
}
3635

3736
// ClusterImagesVolumeName returns the versioned volume name for a given kubeadm version.

test/integration/images_test.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import (
2020
"github.com/bootc-dev/bink/test/integration/helpers"
2121
)
2222

23+
const verifyContainerName = "test-images-verify"
24+
2325
var _ = Describe("Cluster Images Volume", Serial, func() {
2426
var (
2527
podmanClient *podman.Client
@@ -37,8 +39,12 @@ var _ = Describe("Cluster Images Volume", Serial, func() {
3739
containers, err := podmanClient.ContainerList(ctx, "")
3840
Expect(err).ToNot(HaveOccurred())
3941
for _, name := range containers {
40-
_ = podmanClient.ContainerStop(ctx, name)
41-
_ = podmanClient.ContainerRemove(ctx, name, true)
42+
// Only remove containers created by this test suite,
43+
// never touch user containers.
44+
if strings.HasPrefix(name, cluster.PopulatorContainerNamePrefix+"-") || name == verifyContainerName {
45+
_ = podmanClient.ContainerStop(ctx, name)
46+
_ = podmanClient.ContainerRemove(ctx, name, true)
47+
}
4248
}
4349

4450
kubeadmVersion, err := cluster.GetKubeadmVersionFromImage(ctx, podmanClient, config.DefaultNodeImage)
@@ -60,7 +66,7 @@ var _ = Describe("Cluster Images Volume", Serial, func() {
6066
AfterEach(func() {
6167
ctx := context.Background()
6268

63-
_ = podmanClient.ContainerRemove(ctx, "test-images-verify", true)
69+
_ = podmanClient.ContainerRemove(ctx, verifyContainerName, true)
6470
})
6571

6672
It("should populate a versioned cluster-images volume with Kubernetes and Calico images", func() {
@@ -99,9 +105,8 @@ var _ = Describe("Cluster Images Volume", Serial, func() {
99105
Expect(err).ToNot(HaveOccurred(), ".completed marker should exist in the volume")
100106

101107
By("Verifying Calico images are stored in the volume")
102-
verifyContainer := "test-images-verify"
103108
_, err = podmanClient.ContainerCreate(ctx, &podman.ContainerCreateOptions{
104-
Name: verifyContainer,
109+
Name: verifyContainerName,
105110
Image: config.DefaultClusterImage,
106111
Command: []string{"sleep", "infinity"},
107112
Volumes: []*specgen.NamedVolume{{
@@ -111,11 +116,11 @@ var _ = Describe("Cluster Images Volume", Serial, func() {
111116
})
112117
Expect(err).ToNot(HaveOccurred())
113118

114-
err = podmanClient.ContainerExecQuiet(ctx, verifyContainer,
119+
err = podmanClient.ContainerExecQuiet(ctx, verifyContainerName,
115120
[]string{"podman", "image", "exists", config.CalicoImageBase + "/node:" + config.CalicoVersion})
116121
Expect(err).ToNot(HaveOccurred(), "calico/node image should exist in the volume")
117122

118-
err = podmanClient.ContainerExecQuiet(ctx, verifyContainer,
123+
err = podmanClient.ContainerExecQuiet(ctx, verifyContainerName,
119124
[]string{"podman", "image", "exists", config.CalicoImageBase + "/cni:" + config.CalicoVersion})
120125
Expect(err).ToNot(HaveOccurred(), "calico/cni image should exist in the volume")
121126
})

0 commit comments

Comments
 (0)