Skip to content

Commit 5769970

Browse files
committed
test(teardown): filter for tags and labels
1 parent 4c16b21 commit 5769970

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

test/e2e/frmwrk/shared_cluster.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ func (e2e *E2ECluster) setupNodeNetwork(ctx context.Context) {
148148
Name: e2e.ClusterName + "-node",
149149
Description: fmt.Sprintf("Node network for %s", e2e.ClusterName),
150150
Labels: map[string]string{
151-
"e2e-test": e2e.SpecName,
151+
"e2e-test": e2e.SpecName,
152+
capmsv1alpha1.TagInfraClusterResource: e2e.NamespaceName + "." + e2e.ClusterName,
152153
},
153154
}
154155
net, err := e2e.E2EContext.Environment.Metal.Network().AllocateNetwork(metalnetwork.NewAllocateNetworkParamsWithContext(ctx).WithBody(nar), nil)
@@ -180,7 +181,7 @@ func (e2e *E2ECluster) setupFirewall(ctx context.Context) {
180181
Sizeid: &e2e.FirewallSize,
181182
Imageid: &e2e.FirewallImage,
182183
Tags: []string{
183-
fmt.Sprintf("%s=%s", capmsv1alpha1.TagInfraClusterResource, e2e.ClusterName),
184+
fmt.Sprintf("%s=%s.%s", capmsv1alpha1.TagInfraClusterResource, e2e.NamespaceName, e2e.ClusterName),
184185
fmt.Sprintf("%s=%s", "e2e-test", e2e.SpecName),
185186
},
186187
Networks: []*metalmodels.V1MachineAllocationNetwork{
@@ -268,7 +269,7 @@ func (e2e *E2ECluster) setupControlPlaneIP(ctx context.Context) {
268269
Name: e2e.ClusterName + "-cp-ip",
269270
Description: "Control plane IP for " + e2e.ClusterName,
270271
Tags: []string{
271-
fmt.Sprintf("%s=%s", capmsv1alpha1.TagInfraClusterResource, e2e.ClusterName),
272+
fmt.Sprintf("%s=%s.%s", capmsv1alpha1.TagInfraClusterResource, e2e.NamespaceName, e2e.ClusterName),
272273
fmt.Sprintf("%s=%s", "e2e-test", e2e.SpecName),
273274
},
274275
Networkid: ptr.To(e2e.E2EContext.Environment.publicNetwork),

test/e2e/frmwrk/shared_context.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"io"
77
"os"
88
"path"
9+
"slices"
910
"strings"
1011

1112
. "github.com/onsi/ginkgo/v2" //nolint:staticcheck
@@ -254,6 +255,10 @@ func (ee *E2EContext) TeardownMetalStackProject(ctx context.Context) {
254255
}
255256
}
256257

258+
isE2ETestTag := func(tag string) bool {
259+
return strings.HasPrefix(tag, capmsv1alpha1.TagInfraClusterResource+"="+ee.projectNamespacePrefix())
260+
}
261+
257262
By("Cleanup all remaining machines")
258263
ms, err := ee.Environment.Metal.Machine().FindMachines(machine.NewFindMachinesParamsWithContext(ctx).WithBody(&models.V1MachineFindRequest{
259264
PartitionID: ee.Environment.partition,
@@ -262,6 +267,9 @@ func (ee *E2EContext) TeardownMetalStackProject(ctx context.Context) {
262267
Expect(err).ToNot(HaveOccurred(), "failed to list metal machines for project")
263268

264269
for _, m := range ms.Payload {
270+
if !slices.ContainsFunc(m.Tags, isE2ETestTag) {
271+
continue
272+
}
265273
By(fmt.Sprintf("Freeing machine %s", *m.ID))
266274
_, err := ee.Environment.Metal.Machine().FreeMachine(machine.NewFreeMachineParamsWithContext(ctx).WithID(*m.ID), nil)
267275
Expect(err).ToNot(HaveOccurred(), fmt.Sprintf("failed to free metal machine %s", *m.ID))
@@ -274,6 +282,9 @@ func (ee *E2EContext) TeardownMetalStackProject(ctx context.Context) {
274282
Expect(err).ToNot(HaveOccurred(), "failed to list metal IPs for project")
275283

276284
for _, addr := range ips.Payload {
285+
if !slices.ContainsFunc(addr.Tags, isE2ETestTag) {
286+
continue
287+
}
277288
_, err := ee.Environment.Metal.IP().FreeIP(ip.NewFreeIPParamsWithContext(ctx).WithID(*addr.Ipaddress), nil)
278289
Expect(err).ToNot(HaveOccurred(), fmt.Sprintf("failed to free metal IP %s", *addr.Ipaddress))
279290
}
@@ -285,12 +296,18 @@ func (ee *E2EContext) TeardownMetalStackProject(ctx context.Context) {
285296
Expect(err).ToNot(HaveOccurred(), "failed to list metal networks for project")
286297

287298
for _, net := range nets.Payload {
299+
if label, ok := net.Labels[capmsv1alpha1.TagInfraClusterResource]; !ok || !strings.HasPrefix(label, ee.projectNamespacePrefix()) {
300+
continue
301+
}
288302
_, err := ee.Environment.Metal.Network().FreeNetwork(network.NewFreeNetworkParamsWithContext(ctx).WithID(*net.ID), nil)
289303
Expect(err).ToNot(HaveOccurred(), fmt.Sprintf("failed to free metal network %s", *net.ID))
290304
}
291305

292306
By("Wait for all machines to be waiting")
293307
for _, m := range allMachinesInUse.Payload {
308+
if !slices.ContainsFunc(m.Tags, isE2ETestTag) {
309+
continue
310+
}
294311
By(fmt.Sprintf("Waiting for machine %s", *m.ID))
295312
Eventually(ctx, func(g Gomega) {
296313
mr, err := ee.Environment.Metal.Machine().FindMachine(machine.NewFindMachineParamsWithContext(ctx).WithID(*m.ID), nil)

0 commit comments

Comments
 (0)