@@ -17,16 +17,29 @@ import (
1717 "context"
1818 "errors"
1919
20- svcsdk "github.com/aws/aws-sdk-go/service/memorydb"
21- corev1 "k8s.io/api/core/v1"
22- metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23-
24- svcapitypes "github.com/aws-controllers-k8s/memorydb-controller/apis/v1alpha1"
2520 ackv1alpha1 "github.com/aws-controllers-k8s/runtime/apis/core/v1alpha1"
2621 ackcompare "github.com/aws-controllers-k8s/runtime/pkg/compare"
2722 ackerr "github.com/aws-controllers-k8s/runtime/pkg/errors"
23+ ackrequeue "github.com/aws-controllers-k8s/runtime/pkg/requeue"
2824 ackrtlog "github.com/aws-controllers-k8s/runtime/pkg/runtime/log"
2925 ackutil "github.com/aws-controllers-k8s/runtime/pkg/util"
26+ svcsdk "github.com/aws/aws-sdk-go/service/memorydb"
27+ corev1 "k8s.io/api/core/v1"
28+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
29+
30+ svcapitypes "github.com/aws-controllers-k8s/memorydb-controller/apis/v1alpha1"
31+ )
32+
33+ var (
34+ condMsgCurrentlyDeleting string = "snapshot currently being deleted"
35+ deleteStatus string = "deleting"
36+ )
37+
38+ var (
39+ requeueWaitWhileDeleting = ackrequeue .NeededAfter (
40+ errors .New ("delete is in progress" ),
41+ ackrequeue .DefaultRequeueAfterDuration ,
42+ )
3043)
3144
3245func (rm * resourceManager ) customDescribeSnapshotSetOutput (
@@ -248,6 +261,131 @@ func (rm *resourceManager) newCopySnapshotPayload(
248261 return res , nil
249262}
250263
264+ // isDeleting returns true if supplied snapshot resource state is 'deleting'
265+ func isDeleting (r * resource ) bool {
266+ if r == nil || r .ko .Status .Status == nil {
267+ return false
268+ }
269+ status := * r .ko .Status .Status
270+ return status == deleteStatus
271+ }
272+
273+ func (rm * resourceManager ) setSnapshotOutput (
274+ r * resource ,
275+ obj * svcsdk.Snapshot ,
276+ ) (* resource , error ) {
277+ if obj == nil ||
278+ r == nil ||
279+ r .ko == nil {
280+ return nil , nil
281+ }
282+ resp := & svcsdk.DeleteSnapshotOutput {Snapshot : obj }
283+
284+ // Merge in the information we read from the API call above to the copy of
285+ // the original Kubernetes object we passed to the function
286+ ko := r .ko .DeepCopy ()
287+
288+ if ko .Status .ACKResourceMetadata == nil {
289+ ko .Status .ACKResourceMetadata = & ackv1alpha1.ResourceMetadata {}
290+ }
291+ if resp .Snapshot .ARN != nil {
292+ arn := ackv1alpha1 .AWSResourceName (* resp .Snapshot .ARN )
293+ ko .Status .ACKResourceMetadata .ARN = & arn
294+ }
295+ if resp .Snapshot .ClusterConfiguration != nil {
296+ f1 := & svcapitypes.ClusterConfiguration {}
297+ if resp .Snapshot .ClusterConfiguration .Description != nil {
298+ f1 .Description = resp .Snapshot .ClusterConfiguration .Description
299+ }
300+ if resp .Snapshot .ClusterConfiguration .EngineVersion != nil {
301+ f1 .EngineVersion = resp .Snapshot .ClusterConfiguration .EngineVersion
302+ }
303+ if resp .Snapshot .ClusterConfiguration .MaintenanceWindow != nil {
304+ f1 .MaintenanceWindow = resp .Snapshot .ClusterConfiguration .MaintenanceWindow
305+ }
306+ if resp .Snapshot .ClusterConfiguration .Name != nil {
307+ f1 .Name = resp .Snapshot .ClusterConfiguration .Name
308+ }
309+ if resp .Snapshot .ClusterConfiguration .NodeType != nil {
310+ f1 .NodeType = resp .Snapshot .ClusterConfiguration .NodeType
311+ }
312+ if resp .Snapshot .ClusterConfiguration .NumShards != nil {
313+ f1 .NumShards = resp .Snapshot .ClusterConfiguration .NumShards
314+ }
315+ if resp .Snapshot .ClusterConfiguration .ParameterGroupName != nil {
316+ f1 .ParameterGroupName = resp .Snapshot .ClusterConfiguration .ParameterGroupName
317+ }
318+ if resp .Snapshot .ClusterConfiguration .Port != nil {
319+ f1 .Port = resp .Snapshot .ClusterConfiguration .Port
320+ }
321+ if resp .Snapshot .ClusterConfiguration .Shards != nil {
322+ f1f8 := []* svcapitypes.ShardDetail {}
323+ for _ , f1f8iter := range resp .Snapshot .ClusterConfiguration .Shards {
324+ f1f8elem := & svcapitypes.ShardDetail {}
325+ if f1f8iter .Configuration != nil {
326+ f1f8elemf0 := & svcapitypes.ShardConfiguration {}
327+ if f1f8iter .Configuration .ReplicaCount != nil {
328+ f1f8elemf0 .ReplicaCount = f1f8iter .Configuration .ReplicaCount
329+ }
330+ if f1f8iter .Configuration .Slots != nil {
331+ f1f8elemf0 .Slots = f1f8iter .Configuration .Slots
332+ }
333+ f1f8elem .Configuration = f1f8elemf0
334+ }
335+ if f1f8iter .Name != nil {
336+ f1f8elem .Name = f1f8iter .Name
337+ }
338+ if f1f8iter .Size != nil {
339+ f1f8elem .Size = f1f8iter .Size
340+ }
341+ if f1f8iter .SnapshotCreationTime != nil {
342+ f1f8elem .SnapshotCreationTime = & metav1.Time {* f1f8iter .SnapshotCreationTime }
343+ }
344+ f1f8 = append (f1f8 , f1f8elem )
345+ }
346+ f1 .Shards = f1f8
347+ }
348+ if resp .Snapshot .ClusterConfiguration .SnapshotRetentionLimit != nil {
349+ f1 .SnapshotRetentionLimit = resp .Snapshot .ClusterConfiguration .SnapshotRetentionLimit
350+ }
351+ if resp .Snapshot .ClusterConfiguration .SnapshotWindow != nil {
352+ f1 .SnapshotWindow = resp .Snapshot .ClusterConfiguration .SnapshotWindow
353+ }
354+ if resp .Snapshot .ClusterConfiguration .SubnetGroupName != nil {
355+ f1 .SubnetGroupName = resp .Snapshot .ClusterConfiguration .SubnetGroupName
356+ }
357+ if resp .Snapshot .ClusterConfiguration .TopicArn != nil {
358+ f1 .TopicARN = resp .Snapshot .ClusterConfiguration .TopicArn
359+ }
360+ if resp .Snapshot .ClusterConfiguration .VpcId != nil {
361+ f1 .VPCID = resp .Snapshot .ClusterConfiguration .VpcId
362+ }
363+ ko .Status .ClusterConfiguration = f1
364+ } else {
365+ ko .Status .ClusterConfiguration = nil
366+ }
367+ if resp .Snapshot .KmsKeyId != nil {
368+ ko .Spec .KMSKeyID = resp .Snapshot .KmsKeyId
369+ } else {
370+ ko .Spec .KMSKeyID = nil
371+ }
372+ if resp .Snapshot .Source != nil {
373+ ko .Status .Source = resp .Snapshot .Source
374+ } else {
375+ ko .Status .Source = nil
376+ }
377+ if resp .Snapshot .Status != nil {
378+ ko .Status .Status = resp .Snapshot .Status
379+ } else {
380+ ko .Status .Status = nil
381+ }
382+
383+ rm .setStatusDefaults (ko )
384+ // custom set output from response
385+ rm .customSetOutput (obj , ko )
386+ return & resource {ko }, nil
387+ }
388+
251389// getTags gets tags from given ParameterGroup.
252390func (rm * resourceManager ) getTags (
253391 ctx context.Context ,
@@ -346,8 +484,8 @@ func computeTagsDelta(
346484 if ! equalStrings (latestElement .Value , desiredElement .Value ) {
347485 addedOrUpdated = append (addedOrUpdated , desiredElement )
348486 }
349- continue
350487 }
488+ continue
351489 }
352490 removed = append (removed , latestElement .Key )
353491 }
0 commit comments