Skip to content

Commit 7c25c7a

Browse files
Create Failed terminal condition Feature Group Creating requeue (#51)
Summary: Set terminal condition for feature group in "Create Failed" state. Also factored out common custom_update_conditions code between feature group, monitoring schedule, and endpoint. Secondly, added requeue on Creating functionality for feature group in order to allow for the feature group status to be updated to Created. Files Added: - pkg/common/custom_set_terminal_state.go - Contains functionality of custom_update_conditions.go from previous endpoint / monitoring files (that is also reused with feature group). - pkg/common/custom_set_synced_condition.go - Contains general functionality of customSetOutput from previous model package group hooks.go (that is also reused with feature group). - pkg/common/custom_utilities.go - Contains helper function IsModifyingStatus that is used for both this PR and [PR #52](#52). Derived from previous model package group hooks.go. - pkg/resource/feature_group/custom_update_conditions.go - added call to custom_set_terminal_state.go to set the terminal condition if the feature group "Create Failed" state is reached. - pkg/resource/feature_group/hooks.go - Contains helper function isCreating, and ackrequeue variable requeueWaitWhileCreating which are referenced from (also new) resource manager customSetOutput function that is called post read One. Files Edited: - generator.yaml - Added custom update for featuregroup and updated captalization for custom update functions for endpoint and monitoring schedule to be consistent. Also included sdk_read_one_post_set_output hook calling to customSetOutput function. - pkg/resource/endpoint/custom_update_conditions.go - factored out common code into custom_set_terminal_state.go - pkg/resource/monitoring_schedule/custom_update_conditions.go - factored out common code into custom_set_terminal_state.go. Also replaced hardcoded string with library defined reference. - pkg/resource/model_package_group/hooks.go - factored out common code into custom_set_synced_condition.go.
1 parent efa5a65 commit 7c25c7a

File tree

12 files changed

+199
-95
lines changed

12 files changed

+199
-95
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
ack_generate_info:
2-
build_date: "2021-07-22T20:36:39Z"
2+
build_date: "2021-07-23T02:02:51Z"
33
build_hash: 6911f924191f5315747c8e81fbcbf29b4edc8cb1
44
go_version: go1.16.4 linux/amd64
55
version: v0.3.1
66
api_directory_checksum: 4906740ff8ff6ebfffbaea971f7e8aa5a858edd8
77
api_version: v1alpha1
88
aws_sdk_go_version: v1.38.11
99
generator_config_info:
10-
file_checksum: c05fa636159c1f79ab353fd790587a5b36f8b95b
10+
file_checksum: 8e1b7e085d2ff8673e0d239e05e0a1403825c355
1111
original_file_name: generator.yaml
1212
last_modification:
1313
reason: API generation
14-
timestamp: 2021-07-22 20:36:41.771709478 +0000 UTC
14+
timestamp: 2021-07-23 02:02:53.613950676 +0000 UTC

generator.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ resources:
6969
Endpoint:
7070
reconcile:
7171
requeue_on_success_seconds: 30
72-
update_conditions_custom_method_name: customUpdateConditions
72+
update_conditions_custom_method_name: CustomUpdateConditions
7373
exceptions:
7474
errors:
7575
404:
@@ -429,7 +429,7 @@ resources:
429429
MonitoringSchedule:
430430
reconcile:
431431
requeue_on_success_seconds: 30
432-
update_conditions_custom_method_name: customUpdateConditions
432+
update_conditions_custom_method_name: CustomUpdateConditions
433433
exceptions:
434434
errors:
435435
404:
@@ -490,6 +490,7 @@ resources:
490490
operation: DescribeMonitoringSchedule
491491
path: LastMonitoringExecutionSummary
492492
FeatureGroup:
493+
update_conditions_custom_method_name: CustomUpdateConditions
493494
exceptions:
494495
errors:
495496
404:
@@ -514,6 +515,8 @@ resources:
514515
template_path: common/sdk_delete_pre_build_request.go.tpl
515516
sdk_delete_post_request:
516517
template_path: common/sdk_delete_post_request.go.tpl
518+
sdk_read_one_post_set_output:
519+
code: rm.customSetOutput(&resource{ko})
517520
fields:
518521
FailureReason:
519522
is_read_only: true

pkg/common/custom_conditions.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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+
// Use this file if conditions need to be updated based on the latest status
15+
// of endpoint which is not evident from API response
16+
17+
package common
18+
19+
import (
20+
ackcondition "github.com/aws-controllers-k8s/runtime/pkg/condition"
21+
acktypes "github.com/aws-controllers-k8s/runtime/pkg/types"
22+
corev1 "k8s.io/api/core/v1"
23+
)
24+
25+
// SetSyncedCondition sets the ACK Synced Condition
26+
// status to true if the resource status exists but
27+
// is not in one of the given modifying statuses,
28+
// or false if the resource status is one of the
29+
// given modifying statuses.
30+
func SetSyncedCondition(
31+
r acktypes.AWSResource,
32+
latestStatus *string,
33+
resourceName *string,
34+
modifyingStatuses *[]string,
35+
) {
36+
if latestStatus == nil {
37+
return
38+
}
39+
40+
msg := *resourceName + " is in " + *latestStatus + " status."
41+
conditionStatus := corev1.ConditionTrue
42+
if IsModifyingStatus(latestStatus, modifyingStatuses) {
43+
conditionStatus = corev1.ConditionFalse
44+
}
45+
46+
ackcondition.SetSynced(r, conditionStatus, &msg, nil)
47+
}
48+
49+
// SetTerminalState sets conditions (terminal) on
50+
// a resource's supplied status conditions if the
51+
// latest status matches the terminal status.
52+
// It returns true if conditions are updated.
53+
func SetTerminalState(
54+
r acktypes.AWSResource,
55+
latestStatus *string,
56+
resourceName *string,
57+
terminalStatus string,
58+
) bool {
59+
if latestStatus == nil || *latestStatus != terminalStatus {
60+
return false
61+
}
62+
63+
terminalCondition := ackcondition.Terminal(r)
64+
if terminalCondition != nil && terminalCondition.Status == corev1.ConditionTrue {
65+
// some other exception already put the resource in terminal condition
66+
return false
67+
}
68+
69+
// setting terminal condition since controller can no longer recover by retrying
70+
terminalMessage := *resourceName + " status reached terminal state: " + terminalStatus + ". Check the FailureReason."
71+
ackcondition.SetTerminal(r, corev1.ConditionTrue, &terminalMessage, nil)
72+
73+
return true
74+
}

pkg/resource/endpoint/custom_update_conditions.go

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -17,48 +17,24 @@
1717
package endpoint
1818

1919
import (
20-
ackv1alpha1 "github.com/aws-controllers-k8s/runtime/apis/core/v1alpha1"
2120
svcapitypes "github.com/aws-controllers-k8s/sagemaker-controller/apis/v1alpha1"
22-
"github.com/aws/aws-sdk-go/aws"
21+
svccommon "github.com/aws-controllers-k8s/sagemaker-controller/pkg/common"
2322
svcsdk "github.com/aws/aws-sdk-go/service/sagemaker"
24-
corev1 "k8s.io/api/core/v1"
2523
)
2624

27-
// CustomUpdateConditions sets conditions (terminal) on supplied endpoint
25+
// CustomUpdateConditions sets conditions (terminal) on supplied endpoint.
2826
// it examines supplied resource to determine conditions.
29-
// It returns true if conditions are updated
30-
func (rm *resourceManager) customUpdateConditions(
27+
// It returns true if conditions are updated.
28+
func (rm *resourceManager) CustomUpdateConditions(
3129
ko *svcapitypes.Endpoint,
3230
r *resource,
3331
err error,
3432
) bool {
3533
latestStatus := r.ko.Status.EndpointStatus
36-
37-
if latestStatus == nil || *latestStatus != svcsdk.EndpointStatusFailed {
38-
return false
39-
}
40-
var terminalCondition *ackv1alpha1.Condition = nil
41-
42-
for _, condition := range ko.Status.Conditions {
43-
if condition.Type == ackv1alpha1.ConditionTypeTerminal {
44-
terminalCondition = condition
45-
break
46-
}
47-
}
48-
if terminalCondition != nil && terminalCondition.Status == corev1.ConditionTrue {
49-
// some other exception already put the resource in terminal condition
50-
return false
51-
}
52-
53-
// setting terminal condition since controller can no longer recover by retrying
54-
if terminalCondition == nil {
55-
terminalCondition = &ackv1alpha1.Condition{
56-
Type: ackv1alpha1.ConditionTypeTerminal,
57-
}
58-
ko.Status.Conditions = append(ko.Status.Conditions, terminalCondition)
59-
}
60-
terminalCondition.Status = corev1.ConditionTrue
61-
terminalCondition.Message = aws.String("endpoint status: Failed. check FailureReason")
62-
63-
return true
34+
terminalStatus := svcsdk.EndpointStatusFailed
35+
conditionManager := &resource{ko}
36+
resourceName := resourceGK.Kind
37+
// If the latestStatus == terminalStatus we will set
38+
// the terminal condition and terminal message.
39+
return svccommon.SetTerminalState(conditionManager, latestStatus, &resourceName, terminalStatus)
6440
}

pkg/resource/endpoint/sdk.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
svcapitypes "github.com/aws-controllers-k8s/sagemaker-controller/apis/v1alpha1"
18+
svccommon "github.com/aws-controllers-k8s/sagemaker-controller/pkg/common"
19+
svcsdk "github.com/aws/aws-sdk-go/service/sagemaker"
20+
)
21+
22+
// CustomUpdateConditions sets conditions (terminal) on supplied feature group.
23+
// it examines supplied resource to determine conditions.
24+
// It returns true if conditions are updated.
25+
func (rm *resourceManager) CustomUpdateConditions(
26+
ko *svcapitypes.FeatureGroup,
27+
r *resource,
28+
err error,
29+
) bool {
30+
latestStatus := r.ko.Status.FeatureGroupStatus
31+
terminalStatus := svcsdk.FeatureGroupStatusCreateFailed
32+
conditionManager := &resource{ko}
33+
// If the latestStatus == terminalStatus we will set
34+
// the terminal condition and terminal message.
35+
return svccommon.SetTerminalState(conditionManager, latestStatus, &resourceName, terminalStatus)
36+
}

pkg/resource/feature_group/hooks.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,11 @@ func (rm *resourceManager) requeueUntilCanModify(
4343
latestStatus := r.ko.Status.FeatureGroupStatus
4444
return svccommon.RequeueIfModifying(latestStatus, &resourceName, &modifyingStatuses)
4545
}
46+
47+
// customSetOutput sets the ack syncedCondition depending on
48+
// whether the latest status of the resource is one of the
49+
// defined modifyingStatuses.
50+
func (rm *resourceManager) customSetOutput(r *resource) {
51+
latestStatus := r.ko.Status.FeatureGroupStatus
52+
svccommon.SetSyncedCondition(r, latestStatus, &resourceName, &modifyingStatuses)
53+
}

pkg/resource/feature_group/sdk.go

Lines changed: 4 additions & 1 deletion
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: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@ import (
1717
"context"
1818
"errors"
1919

20-
ackcondition "github.com/aws-controllers-k8s/runtime/pkg/condition"
2120
ackrequeue "github.com/aws-controllers-k8s/runtime/pkg/requeue"
2221
svccommon "github.com/aws-controllers-k8s/sagemaker-controller/pkg/common"
2322
svcsdk "github.com/aws/aws-sdk-go/service/sagemaker"
24-
corev1 "k8s.io/api/core/v1"
2523
)
2624

2725
var (
@@ -38,16 +36,8 @@ var (
3836
)
3937

4038
func (rm *resourceManager) customSetOutput(r *resource) {
41-
if r.ko.Status.ModelPackageGroupStatus == nil {
42-
return
43-
}
44-
ModelPackageGroupStatus := *r.ko.Status.ModelPackageGroupStatus
45-
msg := "ModelPackageGroup is in" + ModelPackageGroupStatus + "status"
46-
if !svccommon.IsModifyingStatus(&ModelPackageGroupStatus, &modifyingStatuses) {
47-
ackcondition.SetSynced(r, corev1.ConditionTrue, &msg, nil)
48-
} else {
49-
ackcondition.SetSynced(r, corev1.ConditionFalse, &msg, nil)
50-
}
39+
latestStatus := r.ko.Status.ModelPackageGroupStatus
40+
svccommon.SetSyncedCondition(r, latestStatus, &resourceName, &modifyingStatuses)
5141
}
5242

5343
// requeueUntilCanModify creates and returns an

pkg/resource/monitoring_schedule/custom_update_conditions.go

Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,46 +17,24 @@
1717
package monitoring_schedule
1818

1919
import (
20-
ackv1alpha1 "github.com/aws-controllers-k8s/runtime/apis/core/v1alpha1"
2120
svcapitypes "github.com/aws-controllers-k8s/sagemaker-controller/apis/v1alpha1"
22-
"github.com/aws/aws-sdk-go/aws"
23-
corev1 "k8s.io/api/core/v1"
21+
svccommon "github.com/aws-controllers-k8s/sagemaker-controller/pkg/common"
22+
svcsdk "github.com/aws/aws-sdk-go/service/sagemaker"
2423
)
2524

26-
// CustomUpdateConditions sets conditions (terminal) on supplied resource
25+
// CustomUpdateConditions sets conditions (terminal) on supplied monitoring schedule.
2726
// it examines supplied resource to determine conditions.
28-
// It returns true if conditions are updated
29-
func (rm *resourceManager) customUpdateConditions(
27+
// It returns true if conditions are updated.
28+
func (rm *resourceManager) CustomUpdateConditions(
3029
ko *svcapitypes.MonitoringSchedule,
3130
r *resource,
3231
err error,
3332
) bool {
3433
latestStatus := r.ko.Status.MonitoringScheduleStatus
35-
36-
if latestStatus == nil || *latestStatus != "Failed" {
37-
return false
38-
}
39-
40-
var terminalCondition *ackv1alpha1.Condition = nil
41-
for _, condition := range ko.Status.Conditions {
42-
if condition.Type == ackv1alpha1.ConditionTypeTerminal {
43-
terminalCondition = condition
44-
break
45-
}
46-
}
47-
if terminalCondition != nil && terminalCondition.Status == corev1.ConditionTrue {
48-
// some other exception already put the resource in terminal condition
49-
return false
50-
}
51-
52-
if terminalCondition == nil {
53-
terminalCondition = &ackv1alpha1.Condition{
54-
Type: ackv1alpha1.ConditionTypeTerminal,
55-
}
56-
ko.Status.Conditions = append(ko.Status.Conditions, terminalCondition)
57-
}
58-
terminalCondition.Status = corev1.ConditionTrue
59-
terminalCondition.Message = aws.String("MonitoringScheduleStatus Failed. Check FailureReason")
60-
61-
return true
34+
terminalStatus := svcsdk.ScheduleStatusFailed
35+
conditionManager := &resource{ko}
36+
resourceName := resourceGK.Kind
37+
// If the latestStatus == terminalStatus we will set
38+
// the terminal condition and terminal message.
39+
return svccommon.SetTerminalState(conditionManager, latestStatus, &resourceName, terminalStatus)
6240
}

pkg/resource/monitoring_schedule/sdk.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)