Repository: crossplane-contrib/provider-aws
Pull request #2096 (2024-10-02 14:03:52)

fix: attempt to fix the version problems of replicationgroups (#1)
<!--
Thank you for helping to improve Crossplane!

Please read through https://git.io/fj2m9 if this is your first time opening a
Crossplane pull request. Find us in https://slack.crossplane.io/messages/dev if
you need any help contributing.
-->

### Description of your changes

<!--
Briefly describe what this pull request does. Be sure to direct your reviewers'
attention to anything that needs special consideration.

We love pull requests that resolve an open Crossplane issue. If yours does, you
can uncomment the below line to indicate which issue your PR fixes, for example
"Fixes #500":

-->
Manual backport of https://github.com/crossplane-contrib/provider-aws/pull/2088

I have:

- [ ] Read and followed Crossplane's [contribution process].
- [ ] Run `make reviewable test` to ensure this PR is ready for review.

### How has this code been tested

<!--
Before reviewers can be confident in the correctness of this pull request, it
needs to tested and shown to be correct. Briefly describe the testing that has
already been done or which is planned for this change.
-->

[contribution process]: https://git.io/fj2m9



Patch:
diff --git a/pkg/controller/cache/replicationgroup/managed.go b/pkg/controller/cache/replicationgroup/managed.go
index 2df8d5be9..c01282d31 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/ecs/service/setup.go b/pkg/controller/ecs/service/setup.go
index 16a68b0b7..47756840a 100644
--- a/pkg/controller/ecs/service/setup.go
+++ b/pkg/controller/ecs/service/setup.go
@@ -82,7 +82,7 @@ func postObserve(_ context.Context, cr *svcapitypes.Service, resp *svcsdk.Descri
 
 	switch aws.StringValue(resp.Services[0].Status) {
 	case "ACTIVE":
-		if resp.Services[0].DesiredCount == nil || resp.Services[0].RunningCount == nil || *resp.Services[0].DesiredCount != *resp.Services[0].RunningCount {
+		if resp.Services[0].DesiredCount != resp.Services[0].RunningCount {
 			cr.SetConditions(xpv1.Creating())
 		} else {
 			cr.SetConditions(xpv1.Available())
diff --git a/pkg/controller/lambda/function/setup.go b/pkg/controller/lambda/function/setup.go
index cfb2722d2..ba7e32588 100644
--- a/pkg/controller/lambda/function/setup.go
+++ b/pkg/controller/lambda/function/setup.go
@@ -17,7 +17,6 @@ import (
 	"github.com/google/go-cmp/cmp"
 	"github.com/google/go-cmp/cmp/cmpopts"
 	"github.com/pkg/errors"
-	"k8s.io/utils/ptr"
 	ctrl "sigs.k8s.io/controller-runtime"
 
 	svcapitypes "github.com/crossplane-contrib/provider-aws/apis/lambda/v1beta1"
@@ -132,13 +131,7 @@ func postObserve(_ context.Context, cr *svcapitypes.Function, resp *svcsdk.GetFu
 		cr.SetConditions(xpv1.Available())
 	case string(svcapitypes.State_Pending):
 		cr.SetConditions(xpv1.Creating())
-	case string(svcapitypes.State_Inactive):
-		if aws.StringValue(resp.Configuration.StateReasonCode) == string(svcapitypes.StateReasonCode_Idle) {
-			cr.SetConditions(xpv1.Available().WithMessage(ptr.Deref(resp.Configuration.StateReason, "")))
-		} else {
-			cr.SetConditions(xpv1.Unavailable().WithMessage(ptr.Deref(resp.Configuration.StateReason, "")))
-		}
-	case string(svcapitypes.State_Failed):
+	case string(svcapitypes.State_Failed), string(svcapitypes.State_Inactive):
 		cr.SetConditions(xpv1.Unavailable())
 	}
 	return obs, nil


Test patch:
diff --git a/pkg/controller/cache/replicationgroup/managed_test.go b/pkg/controller/cache/replicationgroup/managed_test.go
index 1137d4f56..e43a83a34 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"
-	engineVersionToTest = "5.0.2"
+	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 {