Skip to content

Commit efa5a65

Browse files
Feature group delete failed requeue (#52)
This PR assumes feature group testing code from PR #50 is already in place, and that the feature group create failed terminal condition code from PR #51 is already in place. Summary: Added requeue on delete if the feature group "Delete Failed" state is reached. This is because the design decision was made to retry to delete if a delete ever fails / does not complete successfully. Files Added: - pkg/resource/feature_group/hooks.go - Contains helper function isDeleteFailed, and ackrequeue variable requeueWaitWhileDeleteFailed which are referenced from the feature group sdk_delete template files. - pkg/common/custom_pre_build_delete_requeue_logic.go - contains functionality of requeueUntilCanModify from old model package group hooks.go. - pkg/common/custom_utilities.go - Contains helper function IsModifyingStatus that is used for both this PR and [PR #51](#51). Derived from previous model package group hooks.go. Files Edited: - generator.yaml - Added feature group hooks for sdk_delete_pre_build_request sdk_delete_post_request. - test/e2e/tests/test_feature_group.py - Removed delete failed TODO comments. - pkg/resource/model_package_group/hooks.go - refactored to use common code from pkg/common directory. - templates/common/sdk_delete_post_request.go.tpl - fixed indentation and missing line at EOF. - templates/common/sdk_delete_pre_build_request.go.tpl - fixed indentation and missing line at EOF.
1 parent 097e403 commit efa5a65

File tree

11 files changed

+169
-46
lines changed

11 files changed

+169
-46
lines changed
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
ack_generate_info:
2-
build_date: "2021-07-16T17:33:59Z"
3-
build_hash: 9c35918f8a98b41ada10cb3aa460dbf463428463
4-
go_version: go1.16.4 darwin/amd64
2+
build_date: "2021-07-22T20:36:39Z"
3+
build_hash: 6911f924191f5315747c8e81fbcbf29b4edc8cb1
4+
go_version: go1.16.4 linux/amd64
55
version: v0.3.1
66
api_directory_checksum: 4906740ff8ff6ebfffbaea971f7e8aa5a858edd8
77
api_version: v1alpha1
8-
aws_sdk_go_version: ""
8+
aws_sdk_go_version: v1.38.11
99
generator_config_info:
10-
file_checksum: 00f02858bed96e1add2a40c7f6d165fdf94689cc
10+
file_checksum: c05fa636159c1f79ab353fd790587a5b36f8b95b
1111
original_file_name: generator.yaml
1212
last_modification:
1313
reason: API generation
14-
timestamp: 2021-07-16 17:34:06.202223 +0000 UTC
14+
timestamp: 2021-07-22 20:36:41.771709478 +0000 UTC

generator.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,10 @@ resources:
510510
hooks:
511511
delta_pre_compare:
512512
code: customSetDefaults(a, b)
513+
sdk_delete_pre_build_request:
514+
template_path: common/sdk_delete_pre_build_request.go.tpl
515+
sdk_delete_post_request:
516+
template_path: common/sdk_delete_post_request.go.tpl
513517
fields:
514518
FailureReason:
515519
is_read_only: true

pkg/common/custom_requeue.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"). You may
4+
// not use this file except in compliance with the License. A copy of the
5+
// License is located at
6+
//
7+
// http://aws.amazon.com/apache2.0/
8+
//
9+
// or in the "license" file accompanying this file. This file is distributed
10+
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11+
// express or implied. See the License for the specific language governing
12+
// permissions and limitations under the License.
13+
14+
package common
15+
16+
import (
17+
"errors"
18+
ackrequeue "github.com/aws-controllers-k8s/runtime/pkg/requeue"
19+
)
20+
21+
// RequeueIfModifying creates and returns an
22+
// ackrequeue if a resource's latest status matches
23+
// one of the provided modifying statuses.
24+
func RequeueIfModifying(
25+
latestStatus *string,
26+
resourceName *string,
27+
modifyingStatuses *[]string,
28+
) error {
29+
if latestStatus == nil || !IsModifyingStatus(latestStatus, modifyingStatuses) {
30+
return nil
31+
}
32+
33+
errMsg := *resourceName + " in " + *latestStatus + " state cannot be modified or deleted."
34+
requeueWaitWhileModifying := ackrequeue.NeededAfter(
35+
errors.New(errMsg),
36+
ackrequeue.DefaultRequeueAfterDuration,
37+
)
38+
return requeueWaitWhileModifying
39+
}

pkg/common/custom_utilities.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"). You may
4+
// not use this file except in compliance with the License. A copy of the
5+
// License is located at
6+
//
7+
// http://aws.amazon.com/apache2.0/
8+
//
9+
// or in the "license" file accompanying this file. This file is distributed
10+
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11+
// express or implied. See the License for the specific language governing
12+
// permissions and limitations under the License.
13+
14+
package common
15+
16+
// IsModifyingStatus returns true if a
17+
// resource's latest status matches one
18+
// of the provided modifying statuses.
19+
func IsModifyingStatus(
20+
latestStatus *string,
21+
modifyingStatuses *[]string,
22+
) bool {
23+
for _, status := range *modifyingStatuses {
24+
if *latestStatus == status {
25+
return true
26+
}
27+
}
28+
return false
29+
}

pkg/resource/feature_group/hooks.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"). You may
4+
// not use this file except in compliance with the License. A copy of the
5+
// License is located at
6+
//
7+
// http://aws.amazon.com/apache2.0/
8+
//
9+
// or in the "license" file accompanying this file. This file is distributed
10+
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11+
// express or implied. See the License for the specific language governing
12+
// permissions and limitations under the License.
13+
14+
package feature_group
15+
16+
import (
17+
"context"
18+
"errors"
19+
ackrequeue "github.com/aws-controllers-k8s/runtime/pkg/requeue"
20+
svccommon "github.com/aws-controllers-k8s/sagemaker-controller/pkg/common"
21+
svcsdk "github.com/aws/aws-sdk-go/service/sagemaker"
22+
)
23+
24+
var (
25+
modifyingStatuses = []string{svcsdk.FeatureGroupStatusCreating,
26+
svcsdk.FeatureGroupStatusDeleting}
27+
28+
resourceName = resourceGK.Kind
29+
30+
requeueWaitWhileDeleting = ackrequeue.NeededAfter(
31+
errors.New(resourceName+" is deleting."),
32+
ackrequeue.DefaultRequeueAfterDuration,
33+
)
34+
)
35+
36+
// requeueUntilCanModify creates and returns an
37+
// ackrequeue error if a resource's latest status matches
38+
// any of the defined modifying statuses below.
39+
func (rm *resourceManager) requeueUntilCanModify(
40+
ctx context.Context,
41+
r *resource,
42+
) error {
43+
latestStatus := r.ko.Status.FeatureGroupStatus
44+
return svccommon.RequeueIfModifying(latestStatus, &resourceName, &modifyingStatuses)
45+
}

pkg/resource/feature_group/sdk.go

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

pkg/resource/model_package_group/hooks.go

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,20 @@ import (
1919

2020
ackcondition "github.com/aws-controllers-k8s/runtime/pkg/condition"
2121
ackrequeue "github.com/aws-controllers-k8s/runtime/pkg/requeue"
22+
svccommon "github.com/aws-controllers-k8s/sagemaker-controller/pkg/common"
2223
svcsdk "github.com/aws/aws-sdk-go/service/sagemaker"
2324
corev1 "k8s.io/api/core/v1"
2425
)
2526

2627
var (
28+
modifyingStatuses = []string{svcsdk.ModelPackageGroupStatusInProgress,
29+
svcsdk.ModelPackageGroupStatusPending,
30+
svcsdk.ModelPackageGroupStatusDeleting}
31+
32+
resourceName = resourceGK.Kind
33+
2734
requeueWaitWhileDeleting = ackrequeue.NeededAfter(
28-
errors.New("ModelPackageGroup is deleting"),
35+
errors.New(resourceName+" is deleting."),
2936
ackrequeue.DefaultRequeueAfterDuration,
3037
)
3138
)
@@ -36,39 +43,20 @@ func (rm *resourceManager) customSetOutput(r *resource) {
3643
}
3744
ModelPackageGroupStatus := *r.ko.Status.ModelPackageGroupStatus
3845
msg := "ModelPackageGroup is in" + ModelPackageGroupStatus + "status"
39-
if !isModifiying(r) {
46+
if !svccommon.IsModifyingStatus(&ModelPackageGroupStatus, &modifyingStatuses) {
4047
ackcondition.SetSynced(r, corev1.ConditionTrue, &msg, nil)
4148
} else {
4249
ackcondition.SetSynced(r, corev1.ConditionFalse, &msg, nil)
4350
}
4451
}
4552

46-
func (rm *resourceManager) requeueUntilCanModify(ctx context.Context,
47-
latest *resource,
53+
// requeueUntilCanModify creates and returns an
54+
// ackrequeue error if a resource's latest status matches
55+
// any of the defined modifying statuses below.
56+
func (rm *resourceManager) requeueUntilCanModify(
57+
ctx context.Context,
58+
r *resource,
4859
) error {
49-
if latest.ko.Status.ModelPackageGroupStatus == nil {
50-
return nil
51-
}
52-
ModelPackageGroupStatus := *latest.ko.Status.ModelPackageGroupStatus
53-
if isModifiying(latest) {
54-
errMsg := "ModelPackageGroup in" + ModelPackageGroupStatus + "state cannot be modified or deleted"
55-
requeueWaitWhileModifying := ackrequeue.NeededAfter(
56-
errors.New(errMsg),
57-
ackrequeue.DefaultRequeueAfterDuration,
58-
)
59-
return requeueWaitWhileModifying
60-
}
61-
return nil
62-
}
63-
64-
func isModifiying(r *resource) bool {
65-
if r == nil || r.ko.Status.ModelPackageGroupStatus == nil {
66-
return false
67-
}
68-
ModelPackageGroupStatus := *r.ko.Status.ModelPackageGroupStatus
69-
70-
if ModelPackageGroupStatus == string(svcsdk.ModelPackageGroupStatusInProgress) || ModelPackageGroupStatus == string(svcsdk.ModelPackageGroupStatusPending) || ModelPackageGroupStatus == string(svcsdk.ModelPackageGroupStatusDeleting) {
71-
return true
72-
}
73-
return false
60+
latestStatus := r.ko.Status.ModelPackageGroupStatus
61+
return svccommon.RequeueIfModifying(latestStatus, &resourceName, &modifyingStatuses)
7462
}

pkg/resource/model_package_group/sdk.go

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
if err == nil {
2-
if _, err := rm.sdkFind(ctx, r); err != ackerr.NotFound {
1+
2+
if err == nil {
3+
if _, err := rm.sdkFind(ctx, r); err != ackerr.NotFound {
34
if err != nil {
4-
return err
5+
return err
56
}
67
return requeueWaitWhileDeleting
7-
}
8-
}
8+
}
9+
}
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
if err = rm.requeueUntilCanModify(ctx, r); err != nil {
2-
return err
3-
}
1+
2+
if err = rm.requeueUntilCanModify(ctx, r); err != nil {
3+
return err
4+
}

test/e2e/tests/test_feature_group.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,5 @@ def test_create_feature_group(self, feature_group):
117117
# Delete the k8s resource.
118118
_, deleted = k8s.delete_custom_resource(reference, WAIT_PERIOD_COUNT, WAIT_PERIOD_LENGTH)
119119
assert deleted
120-
# TODO: Implement logic to requeueOnDelete.
121-
# TODO: Once the delete requeue PR is merged,
122-
# verify that it works for DeleteFailed state.
123120

124121
assert get_sagemaker_feature_group(feature_group_name) is None

0 commit comments

Comments
 (0)