Skip to content

Commit 92e726d

Browse files
authored
Return an error message if snapshot is not ready for deleting (#77)
Issue #, if available: If `snapshot` is not ready for deleting and is called by `sdkDelete`, it will have an error `InvalidSnapshotStateFault`. Description of changes: Check whether `snapshot` is in the `status` to be deleted. If not, then output an error message. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 0353e79 commit 92e726d

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

apis/v1alpha1/ack-generate-metadata.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
ack_generate_info:
2-
build_date: "2023-03-16T20:02:03Z"
2+
build_date: "2023-03-20T20:22:37Z"
33
build_hash: 0888419ec6825035cae1fdee2ceffd7c1ac73ca8
44
go_version: go1.19
55
version: v0.24.3-5-g0888419

pkg/resource/snapshot/sdk.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/resource/snapshot/utility.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package snapshot
22

33
import (
44
"errors"
5+
"fmt"
56
svcapitypes "github.com/aws-controllers-k8s/memorydb-controller/apis/v1alpha1"
67
ackv1alpha1 "github.com/aws-controllers-k8s/runtime/apis/core/v1alpha1"
78
ackrequeue "github.com/aws-controllers-k8s/runtime/pkg/requeue"
@@ -11,14 +12,20 @@ import (
1112

1213
var (
1314
condMsgCurrentlyDeleting string = "snapshot currently being deleted"
15+
availableStatus string = "available"
1416
deleteStatus string = "deleting"
17+
failedStatus string = "failed"
1518
)
1619

1720
var (
1821
requeueWaitWhileDeleting = ackrequeue.NeededAfter(
1922
errors.New("delete is in progress"),
2023
ackrequeue.DefaultRequeueAfterDuration,
2124
)
25+
requeueWaitSnapshotIsReadyForDeleting = ackrequeue.NeededAfter(
26+
fmt.Errorf("snapshot is not ready for deletion - must be in either %q or %q state", availableStatus, failedStatus),
27+
ackrequeue.DefaultRequeueAfterDuration,
28+
)
2229
)
2330

2431
// isDeleting returns true if supplied snapshot resource state is 'deleting'
@@ -30,6 +37,15 @@ func isDeleting(r *resource) bool {
3037
return status == deleteStatus
3138
}
3239

40+
// isNotReadyForDeleting returns true if supplied cluster resource state is not 'deleting', 'available', or 'failed'
41+
func isNotReadyForDeleting(r *resource) bool {
42+
if r == nil || r.ko.Status.Status == nil {
43+
return false
44+
}
45+
status := *r.ko.Status.Status
46+
return status != deleteStatus && status != availableStatus && status != failedStatus
47+
}
48+
3349
func (rm *resourceManager) setSnapshotOutput(
3450
r *resource,
3551
obj *svcsdk.Snapshot,

templates/hooks/snapshot/sdk_delete_pre_build_request.go.tpl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,9 @@
1313
// - reconciler.handleRequeues() is not invoked for delete code path.
1414
// TODO: return err as nil when reconciler is updated.
1515
return r, requeueWaitWhileDeleting
16+
}
17+
18+
if isNotReadyForDeleting(r) {
19+
// return a requeue if snapshot is not ready to be deleted
20+
return r, requeueWaitSnapshotIsReadyForDeleting
1621
}

0 commit comments

Comments
 (0)