Skip to content

Commit

Permalink
Fixes flaky tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyrie Chen committed Feb 3, 2023
1 parent d2483d2 commit a38db76
Show file tree
Hide file tree
Showing 25 changed files with 271 additions and 168 deletions.
8 changes: 4 additions & 4 deletions apis/v1alpha1/ack-generate-metadata.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
ack_generate_info:
build_date: "2023-01-10T21:58:28Z"
build_hash: 1b20baf45a0b73a11b296050322a384c705fa897
go_version: go1.17.5
version: v0.22.0
build_date: "2023-02-03T00:39:12Z"
build_hash: c6651c200ba136e5c7f50ad8be751fae060a38e6
go_version: go1.19
version: v0.22.0-1-gc6651c2
api_directory_checksum: ee32acc4d4a0ba7e2823dd20fdbe2c4ef1d9e0f4
api_version: v1alpha1
aws_sdk_go_version: v1.44.93
Expand Down
4 changes: 2 additions & 2 deletions apis/v1alpha1/subnet_group.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions apis/v1alpha1/types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions helm/crds/memorydb.services.k8s.aws_subnetgroups.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ spec:
type: object
spec:
description: "SubnetGroupSpec defines the desired state of SubnetGroup.
\n Represents the output of one of the following operations: \n * CreateSubnetGroup
\n * UpdateSubnetGroup \n A subnet group is a collection of subnets
\n Represents the output of one of the following operations: \n - CreateSubnetGroup
\n - UpdateSubnetGroup \n A subnet group is a collection of subnets
(typically private) that you can designate for your clusters running
in an Amazon Virtual Private Cloud (VPC) environment."
properties:
Expand Down
22 changes: 20 additions & 2 deletions pkg/resource/acl/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,18 @@ import (
svcsdk "github.com/aws/aws-sdk-go/service/memorydb"
)

var (
resourceStatusActive string = "active"
)

// validateACLNeedsUpdate this function's purpose is to requeue if the resource is currently unavailable
func (rm *resourceManager) validateACLNeedsUpdate(
latest *resource,
) error {

// requeue if necessary
latestStatus := latest.ko.Status.Status
if latestStatus == nil || *latestStatus != "active" {
if latestStatus == nil || *latestStatus != resourceStatusActive {
return requeue.NeededAfter(
errors.New("ACL cannot be modified as its status is not 'active'."),
requeue.DefaultRequeueAfterDuration)
Expand All @@ -41,6 +45,14 @@ func (rm *resourceManager) validateACLNeedsUpdate(
return nil
}

// aclActive returns true when the status of the given ACL is set to `active`
func (rm *resourceManager) aclActive(
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,
Expand Down Expand Up @@ -114,17 +126,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
}
removed = append(removed, latestElement.Key)
}
for _, desiredElement := range desired {
Expand Down
12 changes: 7 additions & 5 deletions pkg/resource/acl/sdk.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 18 additions & 3 deletions pkg/resource/cluster/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ import (
)

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"
resourceStatusActive string = "active"
)

var (
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
}
removed = append(removed, latestElement.Key)
}
for _, desiredElement := range desired {
Expand Down
12 changes: 7 additions & 5 deletions pkg/resource/cluster/sdk.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 44 additions & 30 deletions pkg/resource/parameter_group/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package parameter_group

import (
"context"
ackutil "github.com/aws-controllers-k8s/runtime/pkg/util"

ackv1alpha1 "github.com/aws-controllers-k8s/runtime/apis/core/v1alpha1"
ackerr "github.com/aws-controllers-k8s/runtime/pkg/errors"
Expand Down Expand Up @@ -173,13 +174,7 @@ func (rm *resourceManager) getTags(
if err != nil {
return nil, err
}
tags := make([]*svcapitypes.Tag, 0, len(resp.TagList))
for _, tag := range resp.TagList {
tags = append(tags, &svcapitypes.Tag{
Key: tag.Key,
Value: tag.Value,
})
}
tags := resourceTagsFromSDKTags(resp.TagList)
return tags, nil
}

Expand Down Expand Up @@ -235,34 +230,33 @@ func (rm *resourceManager) updateTags(
func computeTagsDelta(
desired []*svcapitypes.Tag,
latest []*svcapitypes.Tag,
) (added []*svcapitypes.Tag, removed []*string) {
toDelete := []*string{}
toAdd := []*svcapitypes.Tag{}

desiredTags := map[string]string{}
key := ""
value := ""
for _, tag := range desired {
if tag.Key != nil {
key = *tag.Key
value = ""
if tag.Value != nil {
value = *tag.Value
) (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)
}
break
}
desiredTags[key] = value
}
if hasSameKey {
continue
}
removed = append(removed, latestElement.Key)
}

for _, tag := range desired {
toAdd = append(toAdd, tag)
}
for _, tag := range latest {
_, ok := desiredTags[*tag.Key]
if !ok {
toDelete = append(toDelete, tag.Key)
for _, desiredElement := range desired {
if !ackutil.InStrings(*desiredElement.Key, visitedIndexes) {
addedOrUpdated = append(addedOrUpdated, desiredElement)
}
}
return toAdd, toDelete
return addedOrUpdated, removed
}

func sdkTagsFromResourceTags(
Expand All @@ -277,3 +271,23 @@ func sdkTagsFromResourceTags(
}
return tags
}

func resourceTagsFromSDKTags(
sdkTags []*svcsdk.Tag,
) []*svcapitypes.Tag {
tags := make([]*svcapitypes.Tag, len(sdkTags))
for i := range sdkTags {
tags[i] = &svcapitypes.Tag{
Key: sdkTags[i].Key,
Value: sdkTags[i].Value,
}
}
return tags
}

func equalStrings(a, b *string) bool {
if a == nil {
return b == nil || *b == ""
}
return (*a == "" && b == nil) || *a == *b
}
30 changes: 24 additions & 6 deletions pkg/resource/snapshot/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,20 @@ import (
"context"
"errors"

svcsdk "github.com/aws/aws-sdk-go/service/memorydb"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

svcapitypes "github.com/aws-controllers-k8s/memorydb-controller/apis/v1alpha1"
ackv1alpha1 "github.com/aws-controllers-k8s/runtime/apis/core/v1alpha1"
ackcompare "github.com/aws-controllers-k8s/runtime/pkg/compare"
ackerr "github.com/aws-controllers-k8s/runtime/pkg/errors"
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"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

svcapitypes "github.com/aws-controllers-k8s/memorydb-controller/apis/v1alpha1"
)

var (
resourceStatusActive string = "active"
)

func (rm *resourceManager) customDescribeSnapshotSetOutput(
Expand Down Expand Up @@ -248,6 +252,14 @@ func (rm *resourceManager) newCopySnapshotPayload(
return res, nil
}

// snapshotActive returns true when the status of the given Snapshot is set to `active`
func (rm *resourceManager) snapshotActive(
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,
Expand Down Expand Up @@ -338,17 +350,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
}
removed = append(removed, latestElement.Key)
}
for _, desiredElement := range desired {
Expand Down
13 changes: 8 additions & 5 deletions pkg/resource/snapshot/sdk.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a38db76

Please sign in to comment.