From 3834620b35e3e5b261d3eb8518013591e0fdbf6b Mon Sep 17 00:00:00 2001 From: Mustafa Abdelrahman Date: Tue, 9 Jan 2024 10:40:29 +0100 Subject: [PATCH] Add testcase for stack coming without tg tag and in `ROLLBACK_IN_PROGRESS` state Signed-off-by: Mustafa Abdelrahman --- aws/cf.go | 2 +- aws/cf_test.go | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/aws/cf.go b/aws/cf.go index 3a481515..9eb3a6d4 100644 --- a/aws/cf.go +++ b/aws/cf.go @@ -488,12 +488,12 @@ func mapToManagedStack(stack *cloudformation.Stack) *Stack { // If the stack is in rollback state, the outputs are not available. // We need to store target group ARNs in the tags. + // To restore the ARNs, and keep sending traffic to the right target groups. if aws.StringValue(stack.StackStatus) == cloudformation.StackStatusRollbackInProgress && len(tgARNs) == 0 { if tgARNsTag, ok := tags[targetGroupsArnsTag]; ok { values, err := base64.StdEncoding.DecodeString(tgARNsTag) if err != nil { log.Errorf("failed to decode target group ARNs from tags: %v", err) - tgARNs = []string{} } else { tgARNs = strings.Split(string(values), ",") } diff --git a/aws/cf_test.go b/aws/cf_test.go index a3d27ec3..e247077d 100644 --- a/aws/cf_test.go +++ b/aws/cf_test.go @@ -570,6 +570,41 @@ func TestFindManagedStacks(t *testing.T) { }, }, }, + { + name: "successfull-call-with-rollback-status-and-no-tg-tag", + given: fake.CFOutputs{ + DescribeStackPages: fake.R(nil, nil), + DescribeStacks: fake.R(&cloudformation.DescribeStacksOutput{ + Stacks: []*cloudformation.Stack{ + { + StackName: aws.String("managed-stack-rolling-back"), + StackStatus: aws.String(cloudformation.StackStatusRollbackInProgress), + Tags: []*cloudformation.Tag{ + cfTag(kubernetesCreatorTag, DefaultControllerID), + cfTag(clusterIDTagPrefix+"test-cluster", resourceLifecycleOwned), + cfTag(certificateARNTagPrefix+"cert-arn", time.Time{}.Format(time.RFC3339)), + }, + Outputs: []*cloudformation.Output{}, + }, + }, + }, nil), + }, + want: []*Stack{ + { + Name: "managed-stack-rolling-back", + CertificateARNs: map[string]time.Time{ + "cert-arn": {}, + }, + tags: map[string]string{ + kubernetesCreatorTag: DefaultControllerID, + clusterIDTagPrefix + "test-cluster": resourceLifecycleOwned, + certificateARNTagPrefix + "cert-arn": time.Time{}.Format(time.RFC3339), + }, + status: cloudformation.StackStatusRollbackInProgress, + HTTP2: true, + }, + }, + }, { name: "no-ready-stacks", given: fake.CFOutputs{