Skip to content

Commit b5bb14d

Browse files
committed
Update NodeGroupConfiguration in ReadOne
Delta was not getting generated for the NodeGroupConfiguration this resulted in Test failure.
1 parent 8d854fd commit b5bb14d

File tree

11 files changed

+62
-17
lines changed

11 files changed

+62
-17
lines changed

pkg/resource/replication_group/annotations.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ const (
3131
// AnnotationLastRequestedNGC is an annotation whose value is the marshaled list of pointers to
3232
// NodeGroupConfiguration structs passed in as input to either the create or modify API called most
3333
// recently
34-
AnnotationLastRequestedNGC = svcapitypes.AnnotationPrefix + "last-requested-num-group-configuration"
34+
AnnotationLastRequestedNGC = svcapitypes.AnnotationPrefix + "last-requested-node-group-configuration"
3535
)

pkg/resource/replication_group/custom_update_api.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -761,8 +761,9 @@ func nodeGroupRequiresUpdate(desired *resource) bool {
761761

762762
desiredNodeGroupConfig := desired.ko.Spec.NodeGroupConfiguration
763763
if val, ok := annotations[AnnotationLastRequestedNGC]; ok && val != "null" {
764-
_ = json.Unmarshal([]byte(val), &desiredNodeGroupConfig)
765-
return !reflect.DeepEqual(desiredNodeGroupConfig, val)
764+
var lastRequestedNodeGroupConfig []*svcapitypes.NodeGroupConfiguration
765+
_ = json.Unmarshal([]byte(val), &lastRequestedNodeGroupConfig)
766+
return !reflect.DeepEqual(desiredNodeGroupConfig, lastRequestedNodeGroupConfig)
766767
}
767768

768769
// This means there is delta and no value in annotation or in Spec

pkg/resource/replication_group/post_set_output.go

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ package replication_group
1515

1616
import (
1717
"context"
18+
svcapitypes "github.com/aws-controllers-k8s/elasticache-controller/apis/v1alpha1"
1819

1920
svcsdk "github.com/aws/aws-sdk-go/service/elasticache"
2021
)
@@ -35,8 +36,7 @@ func (rm *resourceManager) updateSpecFields(
3536
}
3637
// populate relevant ko.Spec fields with observed state of respRG.NodeGroups
3738
setReplicasPerNodeGroup(respRG, resource)
38-
39-
//TODO: set Spec NodeGroupConfiguration
39+
setNodeGroupConfiguration(respRG, resource)
4040

4141
// updating some Spec fields requires a DescribeCacheClusters call
4242
latestCacheCluster, err := rm.describeCacheCluster(ctx, resource)
@@ -47,6 +47,50 @@ func (rm *resourceManager) updateSpecFields(
4747
}
4848
}
4949

50+
// if NodeGroupConfiguration was given in the desired.Spec, update ko.Spec with the latest observed value
51+
func setNodeGroupConfiguration(
52+
respRG *svcsdk.ReplicationGroup,
53+
resource *resource,
54+
) {
55+
ko := resource.ko
56+
if respRG.NodeGroups != nil && ko.Spec.NodeGroupConfiguration != nil {
57+
nodeGroupConfigurations := []*svcapitypes.NodeGroupConfiguration{}
58+
for _, nodeGroup := range respRG.NodeGroups {
59+
nodeGroupConfiguration := &svcapitypes.NodeGroupConfiguration{}
60+
61+
if nodeGroup.NodeGroupId != nil {
62+
nodeGroupConfiguration.NodeGroupID = nodeGroup.NodeGroupId
63+
}
64+
replicaAZs := []*string{}
65+
66+
for _, nodeGroupMember := range nodeGroup.NodeGroupMembers {
67+
if nodeGroupMember.CurrentRole != nil && *nodeGroupMember.CurrentRole == "primary" {
68+
nodeGroupConfiguration.PrimaryAvailabilityZone = nodeGroupMember.PreferredAvailabilityZone
69+
}
70+
71+
// In this case we cannot say what is primary AZ and replica AZ.
72+
if nodeGroupMember.CurrentRole == nil && nodeGroupConfiguration.PrimaryAvailabilityZone == nil {
73+
// We cannot determine the correct AZ so we would use the first node group member as primary
74+
nodeGroupConfiguration.PrimaryAvailabilityZone = nodeGroupMember.PreferredAvailabilityZone
75+
}
76+
77+
if nodeGroupConfiguration.PrimaryAvailabilityZone != nil || *nodeGroupMember.CurrentRole == "replica" {
78+
replicaAZs = append(replicaAZs, nodeGroupMember.PreferredAvailabilityZone)
79+
}
80+
}
81+
82+
if len(replicaAZs) > 0 {
83+
nodeGroupConfiguration.ReplicaAvailabilityZones = replicaAZs
84+
}
85+
86+
replicaCount := int64(len(replicaAZs))
87+
nodeGroupConfiguration.ReplicaCount = &replicaCount
88+
}
89+
90+
ko.Spec.NodeGroupConfiguration = nodeGroupConfigurations
91+
}
92+
}
93+
5094
//TODO: for all the fields here, reevaluate if the latest observed state should always be populated,
5195
// even if the corresponding field was not specified in desired
5296

test/e2e/scenarios/Resharding/cme_scale_in_config_rollback.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ steps:
2929
conditions:
3030
ACK.ResourceSynced:
3131
status: "True"
32-
timeout: 1800
32+
timeout: 2800
3333
expect:
3434
status:
3535
status: "available"

test/e2e/scenarios/Resharding/cme_scale_in_rollback.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ steps:
2424
conditions:
2525
ACK.ResourceSynced:
2626
status: "True"
27-
timeout: 1800
27+
timeout: 2800
2828
expect:
2929
status:
3030
status: "available"

test/e2e/scenarios/ScaleUpAndDown/cmd_basic_create_update.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ steps:
2323
conditions:
2424
ACK.ResourceSynced:
2525
status: "True"
26-
timeout: 1800
26+
timeout: 2800
2727
expect:
2828
status:
2929
status: "available"

test/e2e/scenarios/ScaleUpAndDown/cmd_scale_down.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ steps:
2020
conditions:
2121
ACK.ResourceSynced:
2222
status: "True"
23-
timeout: 1800
23+
timeout: 2800
2424
expect:
2525
status:
2626
status: "available"
@@ -34,7 +34,7 @@ steps:
3434
conditions:
3535
ACK.ResourceSynced:
3636
status: "True"
37-
timeout: 1800
37+
timeout: 2800
3838
expect:
3939
status:
4040
status: "available"

test/e2e/scenarios/ScaleUpAndDown/cmd_scale_up.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ steps:
2020
conditions:
2121
ACK.ResourceSynced:
2222
status: "True"
23-
timeout: 1800
23+
timeout: 2800
2424
expect:
2525
status:
2626
status: "available"
@@ -34,7 +34,7 @@ steps:
3434
conditions:
3535
ACK.ResourceSynced:
3636
status: "True"
37-
timeout: 1800
37+
timeout: 2800
3838
expect:
3939
status:
4040
status: "available"

test/e2e/scenarios/ScaleUpAndDown/cme_scale_down.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ steps:
2020
conditions:
2121
ACK.ResourceSynced:
2222
status: "True"
23-
timeout: 1800
23+
timeout: 2800
2424
expect:
2525
status:
2626
status: "available"
@@ -34,7 +34,7 @@ steps:
3434
conditions:
3535
ACK.ResourceSynced:
3636
status: "True"
37-
timeout: 1800
37+
timeout: 2800
3838
expect:
3939
status:
4040
status: "available"

test/e2e/scenarios/ScaleUpAndDown/cme_scale_down_rollback.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ steps:
2424
conditions:
2525
ACK.ResourceSynced:
2626
status: "True"
27-
timeout: 1800
27+
timeout: 2800
2828
expect:
2929
status:
3030
status: "available"

0 commit comments

Comments
 (0)