@@ -15,6 +15,8 @@ package replication_group
1515
1616import (
1717 "context"
18+ "encoding/json"
19+
1820 svcapitypes "github.com/aws-controllers-k8s/elasticache-controller/apis/v1alpha1"
1921 ackv1alpha1 "github.com/aws-controllers-k8s/runtime/apis/core/v1alpha1"
2022 "github.com/aws/aws-sdk-go/service/elasticache"
@@ -54,6 +56,7 @@ func (rm *resourceManager) CustomCreateReplicationGroupSetOutput(
5456 ko * svcapitypes.ReplicationGroup ,
5557) (* svcapitypes.ReplicationGroup , error ) {
5658 rm .customSetOutput (resp .ReplicationGroup , ko )
59+ rm .setAnnotationsFields (r , ko )
5760 return ko , nil
5861}
5962
@@ -64,6 +67,16 @@ func (rm *resourceManager) CustomModifyReplicationGroupSetOutput(
6467 ko * svcapitypes.ReplicationGroup ,
6568) (* svcapitypes.ReplicationGroup , error ) {
6669 rm .customSetOutput (resp .ReplicationGroup , ko )
70+
71+ // reset latest.spec.LDC to original value in desired to prevent stale data
72+ // from the modify API being merged back into desired upon spec patching
73+ var logDeliveryConfig []* svcapitypes.LogDeliveryConfigurationRequest
74+ for _ , ldc := range r .ko .Spec .LogDeliveryConfigurations {
75+ logDeliveryConfig = append (logDeliveryConfig , ldc .DeepCopy ())
76+ }
77+ ko .Spec .LogDeliveryConfigurations = logDeliveryConfig
78+
79+ rm .setAnnotationsFields (r , ko )
6780 return ko , nil
6881}
6982
@@ -142,31 +155,8 @@ func (rm *resourceManager) customSetOutput(
142155 ko .Status .AllowedScaleDownModifications = nil
143156 ko .Status .AllowedScaleUpModifications = nil
144157 }
145- }
146-
147- // newListAllowedNodeTypeModificationsPayLoad returns an SDK-specific struct for the HTTP request
148- // payload of the ListAllowedNodeTypeModifications API call.
149- func (rm * resourceManager ) newListAllowedNodeTypeModificationsPayLoad (respRG * elasticache.ReplicationGroup ) (
150- * svcsdk.ListAllowedNodeTypeModificationsInput , error ) {
151- res := & svcsdk.ListAllowedNodeTypeModificationsInput {}
152-
153- if respRG .ReplicationGroupId != nil {
154- res .SetReplicationGroupId (* respRG .ReplicationGroupId )
155- }
156-
157- return res , nil
158- }
159158
160- func (rm * resourceManager ) customSetOutputSupplementAPIs (
161- ctx context.Context ,
162- r * resource ,
163- respRG * elasticache.ReplicationGroup ,
164- ko * svcapitypes.ReplicationGroup ,
165- ) error {
166- events , err := rm .provideEvents (ctx , r .ko .Spec .ReplicationGroupID , 20 )
167- if err != nil {
168- return err
169- }
159+ // populate status logDeliveryConfigurations struct
170160 if respRG .LogDeliveryConfigurations != nil {
171161 var f11 []* svcapitypes.LogDeliveryConfiguration
172162 for _ , f11iter := range respRG .LogDeliveryConfigurations {
@@ -210,6 +200,31 @@ func (rm *resourceManager) customSetOutputSupplementAPIs(
210200 } else {
211201 ko .Status .LogDeliveryConfigurations = nil
212202 }
203+ }
204+
205+ // newListAllowedNodeTypeModificationsPayLoad returns an SDK-specific struct for the HTTP request
206+ // payload of the ListAllowedNodeTypeModifications API call.
207+ func (rm * resourceManager ) newListAllowedNodeTypeModificationsPayLoad (respRG * elasticache.ReplicationGroup ) (
208+ * svcsdk.ListAllowedNodeTypeModificationsInput , error ) {
209+ res := & svcsdk.ListAllowedNodeTypeModificationsInput {}
210+
211+ if respRG .ReplicationGroupId != nil {
212+ res .SetReplicationGroupId (* respRG .ReplicationGroupId )
213+ }
214+
215+ return res , nil
216+ }
217+
218+ func (rm * resourceManager ) customSetOutputSupplementAPIs (
219+ ctx context.Context ,
220+ r * resource ,
221+ respRG * elasticache.ReplicationGroup ,
222+ ko * svcapitypes.ReplicationGroup ,
223+ ) error {
224+ events , err := rm .provideEvents (ctx , r .ko .Spec .ReplicationGroupID , 20 )
225+ if err != nil {
226+ return err
227+ }
213228 ko .Status .Events = events
214229 return nil
215230}
@@ -249,3 +264,36 @@ func (rm *resourceManager) provideEvents(
249264 }
250265 return events , nil
251266}
267+
268+ // setAnnotationsFields copies the desired object's annotations, populates any
269+ // relevant fields, and sets the latest object's annotations to this newly populated map.
270+ // This should only be called upon a successful create or modify call.
271+ func (rm * resourceManager ) setAnnotationsFields (
272+ r * resource ,
273+ ko * svcapitypes.ReplicationGroup ,
274+ ) {
275+ desiredAnnotations := r .ko .ObjectMeta .GetAnnotations ()
276+ annotations := make (map [string ]string )
277+ for k , v := range desiredAnnotations {
278+ annotations [k ] = v
279+ }
280+
281+ rm .setLastRequestedLogDeliveryConfigurations (r , annotations )
282+
283+ ko .ObjectMeta .Annotations = annotations
284+ }
285+
286+ // setLastRequestedLogDeliveryConfigurations copies desired.Spec.LogDeliveryConfigurations
287+ // into the annotations of the object.
288+ // r is the desired resource, and annotations is the annotations map modified by this method
289+ func (rm * resourceManager ) setLastRequestedLogDeliveryConfigurations (
290+ r * resource ,
291+ annotations map [string ]string ,
292+ ) {
293+ lastRequestedConfigs , err := json .Marshal (r .ko .Spec .LogDeliveryConfigurations )
294+ if err != nil {
295+ annotations [AnnotationLastRequestedLDCs ] = "null"
296+ } else {
297+ annotations [AnnotationLastRequestedLDCs ] = string (lastRequestedConfigs )
298+ }
299+ }
0 commit comments