Skip to content

Commit 59ae446

Browse files
committed
chore(test): fix overlap NAT test for hlab
Signed-off-by: Pau Capdevila <[email protected]>
1 parent 573ce6d commit 59ae446

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

pkg/hhfab/release.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2966,30 +2966,33 @@ func (testCtx *VPCPeeringTestCtx) gatewayPeeringOverlapNATTest(ctx context.Conte
29662966
// Initialize reverts slice early
29672967
reverts := []RevertFunc{}
29682968

2969-
// Use server-02 and detach it from vpc-02
2970-
serverToDetach := "server-02"
2971-
2972-
// Discover server-02's attachment to vpc-02 dynamically by listing all and filtering
2969+
// Dynamically discover any server's attachment to vpc-02 by listing all and filtering
29732970
allAttList := &vpcapi.VPCAttachmentList{}
29742971
if err := testCtx.kube.List(ctx, allAttList); err != nil {
29752972
return false, reverts, fmt.Errorf("listing VPCAttachments: %w", err)
29762973
}
29772974

29782975
var attachmentToRemove string
29792976
var connectionName string
2977+
var serverToDetach string
29802978
for _, att := range allAttList.Items {
2981-
// Match attachments that belong to server-02 and vpc-02
2982-
// Format: server-02--{connection}--vpc-02--subnet-01
2983-
if strings.Contains(att.Name, serverToDetach+"--") && strings.Contains(att.Name, "--vpc-02--") {
2979+
// Match attachments that belong to vpc-02
2980+
// Format: {server}--{connection}--vpc-02--subnet-01
2981+
if strings.Contains(att.Name, "--vpc-02--") {
29842982
attachmentToRemove = att.Name
29852983
connectionName = att.Spec.Connection
2984+
// Extract server name from attachment name (format: server--connection--vpc--subnet)
2985+
parts := strings.Split(att.Name, "--")
2986+
if len(parts) >= 4 {
2987+
serverToDetach = parts[0]
2988+
}
29862989

29872990
break
29882991
}
29892992
}
29902993

2991-
if attachmentToRemove == "" {
2992-
return false, reverts, fmt.Errorf("no VPCAttachment found for server %s in vpc-02 (checked %d attachments)", serverToDetach, len(allAttList.Items)) //nolint:err113
2994+
if attachmentToRemove == "" || serverToDetach == "" {
2995+
return true, reverts, fmt.Errorf("no VPCAttachment found for any server in vpc-02 (checked %d attachments)", len(allAttList.Items)) //nolint:err113
29932996
}
29942997

29952998
slog.Debug("Discovered server attachment", "server", serverToDetach, "attachment", attachmentToRemove, "connection", connectionName)

0 commit comments

Comments
 (0)