Skip to content

Commit 3275772

Browse files
authored
requeue until Stopped for job style resources (#88)
Description of changes: - requeue until Stopped for job style resources - integ test changes for the same - Reduce terminal codes to only those which can be fixed by a change in spec. Reason being the latest runtime 0.13+ ignores metadata and status updates leaving customer with no way to get the controller reconcile if the terminal code is not related to spec field change. I will make this change for other resources in a separate PR - consolidate hook related code to one file and refractor to use common pkg to reduce code duplication - removed post `sdk_create_post_set_output` hook because runtime does a readone and paches the status post create TODO: During testing, I found that if there is an error during delete it is not reflected in the resource conditions. Will put a PR to codegen and create a new PR with those changes By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 0292eaa commit 3275772

25 files changed

+329
-389
lines changed
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
ack_generate_info:
2-
build_date: "2021-08-25T04:12:22Z"
2+
build_date: "2021-08-30T20:10:42Z"
33
build_hash: c77aa9c75d944952dee198029ba9822691cd82b0
44
go_version: go1.16.4 linux/amd64
55
version: v0.6.0
6-
api_directory_checksum: f7275158658c496010e6e3d2d24b3aba37e2e1f4
6+
api_directory_checksum: dd5cd5b0cfebeb75eae65c53ab3195a9935a4b87
77
api_version: v1alpha1
88
aws_sdk_go_version: v1.38.11
99
generator_config_info:
10-
file_checksum: 39823b712f9bd1035dc1c5ff1323a91930ce3db0
10+
file_checksum: 84ebf8b8fb4e8a73f6c7fbaab033e3a75436e08e
1111
original_file_name: generator.yaml
1212
last_modification:
1313
reason: API generation
14-
timestamp: 2021-08-25 04:12:25.649196147 +0000 UTC
14+
timestamp: 2021-08-30 20:10:45.71009265 +0000 UTC

apis/v1alpha1/generator.yaml

Lines changed: 15 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -150,28 +150,20 @@ resources:
150150
code: ValidationException
151151
message_prefix: Requested resource not found
152152
terminal_codes:
153-
- ResourceLimitExceeded
154153
- ResourceNotFound
155154
- ResourceInUse
156-
- OptInRequired
157155
- InvalidParameterCombination
158156
- InvalidParameterValue
159157
- MissingParameter
160-
- MissingAction
161-
- InvalidClientTokenId
162-
- InvalidQueryParameter
163-
- MalformedQueryString
164-
- InvalidAction
165-
- UnrecognizedClientException
166158
hooks:
167159
delta_pre_compare:
168160
code: customSetDefaults(a, b)
169-
sdk_create_post_set_output:
170-
code: rm.customCreateTrainingJobSetOutput(&resource{ko})
171161
sdk_read_one_post_set_output:
172-
code: rm.customDescribeTrainingJobSetOutput(&resource{ko})
162+
code: rm.customSetOutput(&resource{ko})
173163
sdk_delete_pre_build_request:
174164
template_path: training_job/sdk_delete_pre_build_request.go.tpl
165+
sdk_delete_post_request:
166+
template_path: common/sdk_delete_post_request.go.tpl
175167
fields:
176168
TrainingJobStatus:
177169
is_read_only: true
@@ -217,28 +209,20 @@ resources:
217209
code: ValidationException
218210
message_prefix: Could not find requested job
219211
terminal_codes:
220-
- ResourceLimitExceeded
221212
- ResourceNotFound
222213
- ResourceInUse
223-
- OptInRequired
224214
- InvalidParameterCombination
225215
- InvalidParameterValue
226216
- MissingParameter
227-
- MissingAction
228-
- InvalidClientTokenId
229-
- InvalidQueryParameter
230-
- MalformedQueryString
231-
- InvalidAction
232-
- UnrecognizedClientException
233217
hooks:
234218
delta_pre_compare:
235219
code: customSetDefaults(a, b)
220+
sdk_read_one_post_set_output:
221+
code: rm.customSetOutput(&resource{ko})
236222
sdk_delete_pre_build_request:
237223
template_path: processing_job/sdk_delete_pre_build_request.go.tpl
238-
sdk_create_post_set_output:
239-
code: rm.customSetOutput(desired, aws.String(svcsdk.ProcessingJobStatusInProgress), ko)
240-
sdk_read_one_post_set_output:
241-
code: rm.customSetOutput(r, resp.ProcessingJobStatus, ko)
224+
sdk_delete_post_request:
225+
template_path: common/sdk_delete_post_request.go.tpl
242226
fields:
243227
ProcessingJobStatus:
244228
is_read_only: true
@@ -262,28 +246,20 @@ resources:
262246
code: ValidationException
263247
message_prefix: Could not find requested job with name
264248
terminal_codes:
265-
- ResourceLimitExceeded
266249
- ResourceNotFound
267250
- ResourceInUse
268-
- OptInRequired
269251
- InvalidParameterCombination
270252
- InvalidParameterValue
271253
- MissingParameter
272-
- MissingAction
273-
- InvalidClientTokenId
274-
- InvalidQueryParameter
275-
- MalformedQueryString
276-
- InvalidAction
277-
- UnrecognizedClientException
278254
hooks:
279255
delta_pre_compare:
280256
code: customSetDefaults(a, b)
257+
sdk_read_one_post_set_output:
258+
code: rm.customSetOutput(&resource{ko})
281259
sdk_delete_pre_build_request:
282260
template_path: transform_job/sdk_delete_pre_build_request.go.tpl
283-
sdk_create_post_set_output:
284-
code: rm.customSetOutput(desired, aws.String(svcsdk.TransformJobStatusInProgress), ko)
285-
sdk_read_one_post_set_output:
286-
code: rm.customSetOutput(r, resp.TransformJobStatus, ko)
261+
sdk_delete_post_request:
262+
template_path: common/sdk_delete_post_request.go.tpl
287263
fields:
288264
TransformJobStatus:
289265
is_read_only: true
@@ -306,28 +282,20 @@ resources:
306282
404:
307283
code: ResourceNotFound
308284
terminal_codes:
309-
- ResourceLimitExceeded
310285
- ResourceNotFound
311286
- ResourceInUse
312-
- OptInRequired
313287
- InvalidParameterCombination
314288
- InvalidParameterValue
315289
- MissingParameter
316-
- MissingAction
317-
- InvalidClientTokenId
318-
- InvalidQueryParameter
319-
- MalformedQueryString
320-
- InvalidAction
321-
- UnrecognizedClientException
322290
hooks:
323291
delta_pre_compare:
324292
code: customSetDefaults(a, b)
293+
sdk_read_one_post_set_output:
294+
code: rm.customSetOutput(&resource{ko})
325295
sdk_delete_pre_build_request:
326296
template_path: hyper_parameter_tuning_job/sdk_delete_pre_build_request.go.tpl
327-
sdk_create_post_set_output:
328-
code: rm.customSetOutput(desired, aws.String(svcsdk.HyperParameterTuningJobStatusInProgress), ko)
329-
sdk_read_one_post_set_output:
330-
code: rm.customSetOutput(r, resp.HyperParameterTuningJobStatus, ko)
297+
sdk_delete_post_request:
298+
template_path: common/sdk_delete_post_request.go.tpl
331299
fields:
332300
HyperParameterTuningJobStatus:
333301
is_read_only: true

generator.yaml

Lines changed: 15 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -150,28 +150,20 @@ resources:
150150
code: ValidationException
151151
message_prefix: Requested resource not found
152152
terminal_codes:
153-
- ResourceLimitExceeded
154153
- ResourceNotFound
155154
- ResourceInUse
156-
- OptInRequired
157155
- InvalidParameterCombination
158156
- InvalidParameterValue
159157
- MissingParameter
160-
- MissingAction
161-
- InvalidClientTokenId
162-
- InvalidQueryParameter
163-
- MalformedQueryString
164-
- InvalidAction
165-
- UnrecognizedClientException
166158
hooks:
167159
delta_pre_compare:
168160
code: customSetDefaults(a, b)
169-
sdk_create_post_set_output:
170-
code: rm.customCreateTrainingJobSetOutput(&resource{ko})
171161
sdk_read_one_post_set_output:
172-
code: rm.customDescribeTrainingJobSetOutput(&resource{ko})
162+
code: rm.customSetOutput(&resource{ko})
173163
sdk_delete_pre_build_request:
174164
template_path: training_job/sdk_delete_pre_build_request.go.tpl
165+
sdk_delete_post_request:
166+
template_path: common/sdk_delete_post_request.go.tpl
175167
fields:
176168
TrainingJobStatus:
177169
is_read_only: true
@@ -217,28 +209,20 @@ resources:
217209
code: ValidationException
218210
message_prefix: Could not find requested job
219211
terminal_codes:
220-
- ResourceLimitExceeded
221212
- ResourceNotFound
222213
- ResourceInUse
223-
- OptInRequired
224214
- InvalidParameterCombination
225215
- InvalidParameterValue
226216
- MissingParameter
227-
- MissingAction
228-
- InvalidClientTokenId
229-
- InvalidQueryParameter
230-
- MalformedQueryString
231-
- InvalidAction
232-
- UnrecognizedClientException
233217
hooks:
234218
delta_pre_compare:
235219
code: customSetDefaults(a, b)
220+
sdk_read_one_post_set_output:
221+
code: rm.customSetOutput(&resource{ko})
236222
sdk_delete_pre_build_request:
237223
template_path: processing_job/sdk_delete_pre_build_request.go.tpl
238-
sdk_create_post_set_output:
239-
code: rm.customSetOutput(desired, aws.String(svcsdk.ProcessingJobStatusInProgress), ko)
240-
sdk_read_one_post_set_output:
241-
code: rm.customSetOutput(r, resp.ProcessingJobStatus, ko)
224+
sdk_delete_post_request:
225+
template_path: common/sdk_delete_post_request.go.tpl
242226
fields:
243227
ProcessingJobStatus:
244228
is_read_only: true
@@ -262,28 +246,20 @@ resources:
262246
code: ValidationException
263247
message_prefix: Could not find requested job with name
264248
terminal_codes:
265-
- ResourceLimitExceeded
266249
- ResourceNotFound
267250
- ResourceInUse
268-
- OptInRequired
269251
- InvalidParameterCombination
270252
- InvalidParameterValue
271253
- MissingParameter
272-
- MissingAction
273-
- InvalidClientTokenId
274-
- InvalidQueryParameter
275-
- MalformedQueryString
276-
- InvalidAction
277-
- UnrecognizedClientException
278254
hooks:
279255
delta_pre_compare:
280256
code: customSetDefaults(a, b)
257+
sdk_read_one_post_set_output:
258+
code: rm.customSetOutput(&resource{ko})
281259
sdk_delete_pre_build_request:
282260
template_path: transform_job/sdk_delete_pre_build_request.go.tpl
283-
sdk_create_post_set_output:
284-
code: rm.customSetOutput(desired, aws.String(svcsdk.TransformJobStatusInProgress), ko)
285-
sdk_read_one_post_set_output:
286-
code: rm.customSetOutput(r, resp.TransformJobStatus, ko)
261+
sdk_delete_post_request:
262+
template_path: common/sdk_delete_post_request.go.tpl
287263
fields:
288264
TransformJobStatus:
289265
is_read_only: true
@@ -306,28 +282,20 @@ resources:
306282
404:
307283
code: ResourceNotFound
308284
terminal_codes:
309-
- ResourceLimitExceeded
310285
- ResourceNotFound
311286
- ResourceInUse
312-
- OptInRequired
313287
- InvalidParameterCombination
314288
- InvalidParameterValue
315289
- MissingParameter
316-
- MissingAction
317-
- InvalidClientTokenId
318-
- InvalidQueryParameter
319-
- MalformedQueryString
320-
- InvalidAction
321-
- UnrecognizedClientException
322290
hooks:
323291
delta_pre_compare:
324292
code: customSetDefaults(a, b)
293+
sdk_read_one_post_set_output:
294+
code: rm.customSetOutput(&resource{ko})
325295
sdk_delete_pre_build_request:
326296
template_path: hyper_parameter_tuning_job/sdk_delete_pre_build_request.go.tpl
327-
sdk_create_post_set_output:
328-
code: rm.customSetOutput(desired, aws.String(svcsdk.HyperParameterTuningJobStatusInProgress), ko)
329-
sdk_read_one_post_set_output:
330-
code: rm.customSetOutput(r, resp.HyperParameterTuningJobStatus, ko)
297+
sdk_delete_post_request:
298+
template_path: common/sdk_delete_post_request.go.tpl
331299
fields:
332300
HyperParameterTuningJobStatus:
333301
is_read_only: true

pkg/resource/hyper_parameter_tuning_job/custom_set_output.go

Lines changed: 0 additions & 61 deletions
This file was deleted.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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 hyper_parameter_tuning_job
15+
16+
import (
17+
"errors"
18+
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{
26+
svcsdk.HyperParameterTuningJobStatusInProgress,
27+
svcsdk.HyperParameterTuningJobStatusStopping,
28+
}
29+
resourceName = resourceGK.Kind
30+
31+
requeueWaitWhileDeleting = ackrequeue.NeededAfter(
32+
errors.New(resourceName+" is Stopping."),
33+
ackrequeue.DefaultRequeueAfterDuration,
34+
)
35+
)
36+
37+
// customSetOutput sets ConditionTypeResourceSynced condition to True or False
38+
// based on the hyperParameterTuningJobStatus on AWS so the reconciler can determine if a
39+
// requeue is needed
40+
func (rm *resourceManager) customSetOutput(r *resource) {
41+
jobStatus := r.ko.Status.HyperParameterTuningJobStatus
42+
svccommon.SetSyncedCondition(r, jobStatus, &resourceName, &modifyingStatuses)
43+
}

0 commit comments

Comments
 (0)