Skip to content

Commit 8c43988

Browse files
authored
Endpoint: fix terminal condition showing up as recoverable (#18)
1 parent d13c6fb commit 8c43988

File tree

10 files changed

+47
-73
lines changed

10 files changed

+47
-73
lines changed

generator.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ resources:
8484
- MalformedQueryString
8585
- InvalidAction
8686
- UnrecognizedClientException
87+
# Custom error
88+
- EndpointUpdateError
8789
hooks:
8890
sdk_create_post_set_output:
8991
code: rm.customSetOutput(r, aws.String(svcsdk.EndpointStatusCreating), ko)

pkg/resource/endpoint/custom_set_output.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,10 @@ func (rm *resourceManager) customSetOutput(
8585
}
8686

8787
var resourceSyncedCondition *ackv1alpha1.Condition = nil
88-
if ko.Status.Conditions == nil {
89-
ko.Status.Conditions = []*ackv1alpha1.Condition{}
90-
} else {
91-
for _, condition := range ko.Status.Conditions {
92-
if condition.Type == ackv1alpha1.ConditionTypeResourceSynced {
93-
resourceSyncedCondition = condition
94-
break
95-
}
88+
for _, condition := range ko.Status.Conditions {
89+
if condition.Type == ackv1alpha1.ConditionTypeResourceSynced {
90+
resourceSyncedCondition = condition
91+
break
9692
}
9793
}
9894

pkg/resource/endpoint/custom_update_api.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ package endpoint
1919
import (
2020
"context"
2121
"errors"
22-
"fmt"
2322
"strings"
2423

2524
ackcompare "github.com/aws-controllers-k8s/runtime/pkg/compare"
2625
"github.com/aws-controllers-k8s/runtime/pkg/requeue"
26+
"github.com/aws/aws-sdk-go/aws/awserr"
2727
svcsdk "github.com/aws/aws-sdk-go/service/sagemaker"
2828
)
2929

3030
var (
31-
FailUpdateError = fmt.Errorf("Unable to update Endpoint. Check FailureReason")
31+
FailUpdateError = awserr.New("EndpointUpdateError", "unable to update endpoint. check FailureReason", nil)
3232

3333
FailureReasonInternalServiceErrorPrefix = "Request to service failed"
3434
)

pkg/resource/endpoint/custom_update_conditions.go

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -33,43 +33,32 @@ func (rm *resourceManager) customUpdateConditions(
3333
err error,
3434
) bool {
3535
latestStatus := r.ko.Status.EndpointStatus
36-
failureReason := r.ko.Status.FailureReason
3736

38-
if latestStatus == nil || failureReason == nil {
37+
if latestStatus == nil || *latestStatus != svcsdk.EndpointStatusFailed {
3938
return false
4039
}
4140
var terminalCondition *ackv1alpha1.Condition = nil
42-
if ko.Status.Conditions == nil {
43-
ko.Status.Conditions = []*ackv1alpha1.Condition{}
44-
} else {
45-
for _, condition := range ko.Status.Conditions {
46-
if condition.Type == ackv1alpha1.ConditionTypeTerminal {
47-
terminalCondition = condition
48-
break
49-
}
50-
}
51-
if terminalCondition != nil && terminalCondition.Status == corev1.ConditionTrue {
52-
// some other exception already put the resource in terminal condition
53-
return false
41+
42+
for _, condition := range ko.Status.Conditions {
43+
if condition.Type == ackv1alpha1.ConditionTypeTerminal {
44+
terminalCondition = condition
45+
break
5446
}
5547
}
48+
if terminalCondition != nil && terminalCondition.Status == corev1.ConditionTrue {
49+
// some other exception already put the resource in terminal condition
50+
return false
51+
}
5652

57-
if (err != nil && err == FailUpdateError) || (latestStatus != nil && *latestStatus == svcsdk.EndpointStatusFailed) {
58-
// setting terminal condition since controller can no longer recover by retrying
59-
if terminalCondition == nil {
60-
terminalCondition = &ackv1alpha1.Condition{
61-
Type: ackv1alpha1.ConditionTypeTerminal,
62-
}
63-
ko.Status.Conditions = append(ko.Status.Conditions, terminalCondition)
64-
}
65-
terminalCondition.Status = corev1.ConditionTrue
66-
if *latestStatus == svcsdk.EndpointStatusFailed {
67-
terminalCondition.Message = aws.String("Cannot update endpoint with Failed status")
68-
} else {
69-
terminalCondition.Message = aws.String(FailUpdateError.Error())
53+
// setting terminal condition since controller can no longer recover by retrying
54+
if terminalCondition == nil {
55+
terminalCondition = &ackv1alpha1.Condition{
56+
Type: ackv1alpha1.ConditionTypeTerminal,
7057
}
71-
return true
58+
ko.Status.Conditions = append(ko.Status.Conditions, terminalCondition)
7259
}
60+
terminalCondition.Status = corev1.ConditionTrue
61+
terminalCondition.Message = aws.String("endpoint status: Failed. check FailureReason")
7362

74-
return false
63+
return true
7564
}

pkg/resource/endpoint/sdk.go

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

pkg/resource/hyper_parameter_tuning_job/custom_set_output.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,10 @@ func (rm *resourceManager) customSetOutput(
4343
}
4444

4545
var resourceSyncedCondition *ackv1alpha1.Condition = nil
46-
if ko.Status.Conditions == nil {
47-
ko.Status.Conditions = []*ackv1alpha1.Condition{}
48-
} else {
49-
for _, condition := range ko.Status.Conditions {
50-
if condition.Type == ackv1alpha1.ConditionTypeResourceSynced {
51-
resourceSyncedCondition = condition
52-
break
53-
}
46+
for _, condition := range ko.Status.Conditions {
47+
if condition.Type == ackv1alpha1.ConditionTypeResourceSynced {
48+
resourceSyncedCondition = condition
49+
break
5450
}
5551
}
5652

pkg/resource/processing_job/custom_set_output.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,10 @@ func (rm *resourceManager) customSetOutput(
4343
}
4444

4545
var resourceSyncedCondition *ackv1alpha1.Condition = nil
46-
if ko.Status.Conditions == nil {
47-
ko.Status.Conditions = []*ackv1alpha1.Condition{}
48-
} else {
49-
for _, condition := range ko.Status.Conditions {
50-
if condition.Type == ackv1alpha1.ConditionTypeResourceSynced {
51-
resourceSyncedCondition = condition
52-
break
53-
}
46+
for _, condition := range ko.Status.Conditions {
47+
if condition.Type == ackv1alpha1.ConditionTypeResourceSynced {
48+
resourceSyncedCondition = condition
49+
break
5450
}
5551
}
5652

pkg/resource/training_job/custom_set_output.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,10 @@ func (rm *resourceManager) customSetOutput(
7373
}
7474

7575
var resourceSyncedCondition *ackv1alpha1.Condition = nil
76-
if ko.Status.Conditions == nil {
77-
ko.Status.Conditions = []*ackv1alpha1.Condition{}
78-
} else {
79-
for _, condition := range ko.Status.Conditions {
80-
if condition.Type == ackv1alpha1.ConditionTypeResourceSynced {
81-
resourceSyncedCondition = condition
82-
break
83-
}
76+
for _, condition := range ko.Status.Conditions {
77+
if condition.Type == ackv1alpha1.ConditionTypeResourceSynced {
78+
resourceSyncedCondition = condition
79+
break
8480
}
8581
}
8682

pkg/resource/transform_job/custom_set_output.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,10 @@ func (rm *resourceManager) customSetOutput(
4343
}
4444

4545
var resourceSyncedCondition *ackv1alpha1.Condition = nil
46-
if ko.Status.Conditions == nil {
47-
ko.Status.Conditions = []*ackv1alpha1.Condition{}
48-
} else {
49-
for _, condition := range ko.Status.Conditions {
50-
if condition.Type == ackv1alpha1.ConditionTypeResourceSynced {
51-
resourceSyncedCondition = condition
52-
break
53-
}
46+
for _, condition := range ko.Status.Conditions {
47+
if condition.Type == ackv1alpha1.ConditionTypeResourceSynced {
48+
resourceSyncedCondition = condition
49+
break
5450
}
5551
}
5652

test/e2e/tests/test_endpoint.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
)
3535
from e2e.replacement_values import REPLACEMENT_VALUES
3636

37+
FAIL_UPDATE_ERROR_MESSAGE = "unable to update endpoint. check FailureReason"
38+
3739

3840
@pytest.fixture(scope="module")
3941
def name_suffix():
@@ -286,7 +288,7 @@ def update_endpoint_failed_test(
286288
endpoint_reference,
287289
"ACK.Terminal",
288290
"True",
289-
"Unable to update Endpoint. Check FailureReason",
291+
FAIL_UPDATE_ERROR_MESSAGE,
290292
)
291293

292294
endpoint_resource = k8s.get_resource(endpoint_reference)

0 commit comments

Comments
 (0)