Skip to content

Commit

Permalink
Add testcase for stack coming without tg tag and in `ROLLBACK_IN_PROG…
Browse files Browse the repository at this point in the history
…RESS` state

Signed-off-by: Mustafa Abdelrahman <[email protected]>
  • Loading branch information
MustafaSaber committed Jan 9, 2024
1 parent 9f51119 commit 3834620
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion aws/cf.go
Original file line number Diff line number Diff line change
Expand Up @@ -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), ",")
}
Expand Down
35 changes: 35 additions & 0 deletions aws/cf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit 3834620

Please sign in to comment.