From 47de9d6bdf58861624c88b86f9d01a7b9850bdbe Mon Sep 17 00:00:00 2001 From: dhumphries-sainsburys <110051852+dhumphries-sainsburys@users.noreply.github.com> Date: Mon, 26 Aug 2024 13:57:39 +0100 Subject: [PATCH 1/2] chore: attempt to fix the version problems of replicationgroups (#1) Signed-off-by: Daniel.Humphries --- .../cache/replicationgroup/managed.go | 12 +++-- .../cache/replicationgroup/managed_test.go | 52 ++++++++++++++++++- 2 files changed, 59 insertions(+), 5 deletions(-) diff --git a/pkg/controller/cache/replicationgroup/managed.go b/pkg/controller/cache/replicationgroup/managed.go index 2df8d5be9f..c01282d314 100644 --- a/pkg/controller/cache/replicationgroup/managed.go +++ b/pkg/controller/cache/replicationgroup/managed.go @@ -364,11 +364,15 @@ func getVersion(version *string) (*string, error) { } versionOut := strconv.Itoa(version1) if len(versionSplit) > 1 { - version2, err := strconv.Atoi(versionSplit[1]) - if err != nil { - return nil, errors.Wrap(err, errVersionInput) + if versionSplit[1] != "x" { + version2, err := strconv.Atoi(versionSplit[1]) + if err != nil { + return nil, errors.Wrap(err, errVersionInput) + } + versionOut += "." + strconv.Itoa(version2) + } else { + versionOut += ".x" } - versionOut += "." + strconv.Itoa(version2) } return &versionOut, nil } diff --git a/pkg/controller/cache/replicationgroup/managed_test.go b/pkg/controller/cache/replicationgroup/managed_test.go index 1137d4f569..8661ca65a6 100644 --- a/pkg/controller/cache/replicationgroup/managed_test.go +++ b/pkg/controller/cache/replicationgroup/managed_test.go @@ -37,8 +37,9 @@ import ( ) const ( - name = "coolGroup" + name = "coolGroup" engineVersionToTest = "5.0.2" + alternateEngineVersionToTest = "6.x" ) var ( @@ -46,6 +47,7 @@ var ( autoFailoverEnabled = true cacheParameterGroupName = "coolParamGroup" engineVersion = "5.0" + alternateEngineVersion = "6.x" port = 6379 host = "172.16.0.1" maintenanceWindow = "tomorrow" @@ -789,6 +791,54 @@ func TestUpdate(t *testing.T) { ), returnsErr: false, }, + { + name: "IncreaseReplicationsAndCheckBehaviourVersionx", + e: &external{client: &fake.MockClient{ + MockDescribeReplicationGroups: func(ctx context.Context, _ *elasticache.DescribeReplicationGroupsInput, opts []func(*elasticache.Options)) (*elasticache.DescribeReplicationGroupsOutput, error) { + return &elasticache.DescribeReplicationGroupsOutput{ + ReplicationGroups: []types.ReplicationGroup{{ + Status: aws.String(v1beta1.StatusAvailable), + MemberClusters: cacheClusters, + AutomaticFailover: types.AutomaticFailoverStatusEnabled, + CacheNodeType: aws.String(cacheNodeType), + SnapshotRetentionLimit: aws.Int32(int32(snapshotRetentionLimit)), + SnapshotWindow: aws.String(snapshotWindow), + ClusterEnabled: aws.Bool(true), + ConfigurationEndpoint: &types.Endpoint{Address: aws.String(host), Port: int32(port)}, + }}, + }, nil + }, + MockDescribeCacheClusters: func(ctx context.Context, _ *elasticache.DescribeCacheClustersInput, opts []func(*elasticache.Options)) (*elasticache.DescribeCacheClustersOutput, error) { + return &elasticache.DescribeCacheClustersOutput{ + CacheClusters: []types.CacheCluster{ + {EngineVersion: aws.String(engineVersion)}, + {EngineVersion: aws.String(engineVersion)}, + {EngineVersion: aws.String(engineVersion)}, + }, + }, nil + }, + MockIncreaseReplicaCount: func(ctx context.Context, _ *elasticache.IncreaseReplicaCountInput, opts []func(*elasticache.Options)) (*elasticache.IncreaseReplicaCountOutput, error) { + return &elasticache.IncreaseReplicaCountOutput{}, nil + }, + }}, + r: replicationGroup( + withEngineVersion(alternateEngineVersionToTest), + withReplicationGroupID(name), + withProviderStatus(v1beta1.StatusAvailable), + withConditions(xpv1.Available()), + withMemberClusters(cacheClusters), + withNumCacheClusters(4), + ), + want: replicationGroup( + withEngineVersion(alternateEngineVersion), + withReplicationGroupID(name), + withProviderStatus(v1beta1.StatusAvailable), + withConditions(xpv1.Available()), + withMemberClusters(cacheClusters), + withNumCacheClusters(4), + ), + returnsErr: false, + }, } for _, tc := range cases { From 049a2c4c953576a152fe76065e6f007f3f9f2a71 Mon Sep 17 00:00:00 2001 From: "Daniel.Humphries" Date: Tue, 17 Sep 2024 12:24:17 +0100 Subject: [PATCH 2/2] chore: fix linting Signed-off-by: Daniel.Humphries --- pkg/controller/cache/replicationgroup/managed_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/controller/cache/replicationgroup/managed_test.go b/pkg/controller/cache/replicationgroup/managed_test.go index 8661ca65a6..e43a83a348 100644 --- a/pkg/controller/cache/replicationgroup/managed_test.go +++ b/pkg/controller/cache/replicationgroup/managed_test.go @@ -37,8 +37,8 @@ import ( ) const ( - name = "coolGroup" - engineVersionToTest = "5.0.2" + name = "coolGroup" + engineVersionToTest = "5.0.2" alternateEngineVersionToTest = "6.x" ) @@ -47,7 +47,7 @@ var ( autoFailoverEnabled = true cacheParameterGroupName = "coolParamGroup" engineVersion = "5.0" - alternateEngineVersion = "6.x" + alternateEngineVersion = "6.x" port = 6379 host = "172.16.0.1" maintenanceWindow = "tomorrow"