-
Notifications
You must be signed in to change notification settings - Fork 12
Modify tags related functions and some test files to fix flaky assertion errors #51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,14 +24,15 @@ import ( | |
ackrequeue "github.com/aws-controllers-k8s/runtime/pkg/requeue" | ||
ackrtlog "github.com/aws-controllers-k8s/runtime/pkg/runtime/log" | ||
ackutil "github.com/aws-controllers-k8s/runtime/pkg/util" | ||
svcsdk "github.com/aws/aws-sdk-go/service/memorydb" | ||
|
||
svcapitypes "github.com/aws-controllers-k8s/memorydb-controller/apis/v1alpha1" | ||
svcsdk "github.com/aws/aws-sdk-go/service/memorydb" | ||
) | ||
|
||
var ( | ||
condMsgCurrentlyDeleting = "cluster currently being deleted" | ||
condMsgNoDeleteWhileUpdating = "cluster is being updated. cannot delete" | ||
condMsgCurrentlyDeleting = "cluster currently being deleted" | ||
condMsgNoDeleteWhileUpdating = "cluster is being updated. cannot delete" | ||
Comment on lines
+33
to
+34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we make messages a bit consistent? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These two variables are not related to flaky tests. I didn't modify or create them in this PR, so I will mark it and change it in a new PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes please. The english grammar for these two messages should be improved. |
||
resourceStatusActive string = "active" | ||
) | ||
|
||
var ( | ||
|
@@ -264,6 +265,14 @@ func (rm *resourceManager) newMemoryDBClusterUploadPayload( | |
return res | ||
} | ||
|
||
// clusterActive returns true when the status of the given Cluster is set to `active` | ||
func (rm *resourceManager) clusterActive( | ||
latest *resource, | ||
) bool { | ||
latestStatus := latest.ko.Status.Status | ||
return latestStatus != nil && *latestStatus == resourceStatusActive | ||
} | ||
|
||
// getTags gets tags from given ParameterGroup. | ||
func (rm *resourceManager) getTags( | ||
ctx context.Context, | ||
|
@@ -337,17 +346,23 @@ func computeTagsDelta( | |
latest []*svcapitypes.Tag, | ||
) (addedOrUpdated []*svcapitypes.Tag, removed []*string) { | ||
var visitedIndexes []string | ||
var hasSameKey bool | ||
|
||
for _, latestElement := range latest { | ||
hasSameKey = false | ||
visitedIndexes = append(visitedIndexes, *latestElement.Key) | ||
for _, desiredElement := range desired { | ||
if equalStrings(latestElement.Key, desiredElement.Key) { | ||
hasSameKey = true | ||
if !equalStrings(latestElement.Value, desiredElement.Value) { | ||
addedOrUpdated = append(addedOrUpdated, desiredElement) | ||
} | ||
continue | ||
break | ||
} | ||
} | ||
if hasSameKey { | ||
continue | ||
} | ||
Comment on lines
+363
to
+365
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see that you wanna ignore duplicated keys +++ |
||
removed = append(removed, latestElement.Key) | ||
} | ||
for _, desiredElement := range desired { | ||
|
@@ -386,7 +401,9 @@ func resourceTagsFromSDKTags( | |
|
||
func equalStrings(a, b *string) bool { | ||
if a == nil { | ||
return b == nil || *b == "" | ||
return b == nil | ||
} else if b == nil { | ||
return false | ||
} | ||
return (*a == "" && b == nil) || *a == *b | ||
return *a == *b | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like we are reusing the
computeTagsDelta
in everyhooks.go
file. We can reduce this duplication by moving this method into a package that is accessible by all resources. RDS puts theirs inpkg/utils/tags.go
and then imports that module insidehooks.go
- https://github.com/aws-controllers-k8s/rds-controller/blob/main/pkg/util/tags.goThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will create another PR to do it.