Skip to content

Commit 2460dd0

Browse files
committed
enable deletion of resource if job is complete
- reduce custom code by using callback hooks
1 parent 9ea4636 commit 2460dd0

File tree

16 files changed

+92
-172
lines changed

16 files changed

+92
-172
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@
55
/docs/site
66
bin
77
build
8+
9+
__pycache__/
10+
*.py[cod]
11+
**/bootstrap.yaml

generator.yaml

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,15 @@
11
operations:
2-
CreateTrainingJob:
3-
set_output_custom_method_name: customCreateTrainingJobSetOutput
42
DescribeTrainingJob:
53
set_output_custom_method_name: customDescribeTrainingJobSetOutput
64
StopTrainingJob:
75
operation_type: Delete
86
resource_name: TrainingJob
9-
CreateProcessingJob:
10-
set_output_custom_method_name: customCreateProcessingJobSetOutput
11-
DescribeProcessingJob:
12-
set_output_custom_method_name: customDescribeProcessingJobSetOutput
137
StopProcessingJob:
148
operation_type: Delete
159
resource_name: ProcessingJob
16-
CreateTransformJob:
17-
set_output_custom_method_name: customCreateTransformJobSetOutput
18-
DescribeTransformJob:
19-
set_output_custom_method_name: customDescribeTransformJobSetOutput
2010
StopTransformJob:
2111
operation_type: Delete
2212
resource_name: TransformJob
23-
CreateEndpoint:
24-
set_output_custom_method_name: customCreateEndpointSetOutput
2513
DescribeEndpoint:
2614
set_output_custom_method_name: customDescribeEndpointSetOutput
2715
UpdateEndpoint:
@@ -31,10 +19,6 @@ operations:
3119
RetainAllVariantProperties: true
3220
DeleteEndpoint:
3321
custom_implementation: customDeleteEndpoint
34-
CreateHyperParameterTuningJob:
35-
set_output_custom_method_name: customCreateHyperParameterTuningJobSetOutput
36-
DescribeHyperParameterTuningJob:
37-
set_output_custom_method_name: customDescribeHyperParameterTuningJobSetOutput
3822
StopHyperParameterTuningJob:
3923
operation_type: Delete
4024
resource_name: HyperParameterTuningJob
@@ -100,6 +84,9 @@ resources:
10084
- MalformedQueryString
10185
- InvalidAction
10286
- UnrecognizedClientException
87+
hooks:
88+
sdk_create_post_set_output:
89+
code: rm.customSetOutput(r, aws.String(svcsdk.EndpointStatusCreating), ko)
10390
fields:
10491
EndpointStatus:
10592
is_read_only: true
@@ -158,6 +145,11 @@ resources:
158145
- MalformedQueryString
159146
- InvalidAction
160147
- UnrecognizedClientException
148+
hooks:
149+
sdk_create_post_set_output:
150+
code: rm.customSetOutput(r, aws.String(svcsdk.TrainingJobStatusInProgress), ko)
151+
sdk_delete_pre_build_request:
152+
template_path: training_job/sdk_delete_pre_build_request.go.tpl
161153
fields:
162154
TrainingJobStatus:
163155
is_read_only: true
@@ -202,6 +194,13 @@ resources:
202194
- MalformedQueryString
203195
- InvalidAction
204196
- UnrecognizedClientException
197+
hooks:
198+
sdk_delete_pre_build_request:
199+
template_path: processing_job/sdk_delete_pre_build_request.go.tpl
200+
sdk_create_post_set_output:
201+
code: rm.customSetOutput(r, aws.String(svcsdk.ProcessingJobStatusInProgress), ko)
202+
sdk_read_one_post_set_output:
203+
code: rm.customSetOutput(r, resp.ProcessingJobStatus, ko)
205204
fields:
206205
ProcessingJobStatus:
207206
is_read_only: true
@@ -235,6 +234,13 @@ resources:
235234
- MalformedQueryString
236235
- InvalidAction
237236
- UnrecognizedClientException
237+
hooks:
238+
sdk_delete_pre_build_request:
239+
template_path: transform_job/sdk_delete_pre_build_request.go.tpl
240+
sdk_create_post_set_output:
241+
code: rm.customSetOutput(r, aws.String(svcsdk.TransformJobStatusInProgress), ko)
242+
sdk_read_one_post_set_output:
243+
code: rm.customSetOutput(r, resp.TransformJobStatus, ko)
238244
fields:
239245
TransformJobStatus:
240246
is_read_only: true
@@ -267,6 +273,13 @@ resources:
267273
- MalformedQueryString
268274
- InvalidAction
269275
- UnrecognizedClientException
276+
hooks:
277+
sdk_delete_pre_build_request:
278+
template_path: hyper_parameter_tuning_job/sdk_delete_pre_build_request.go.tpl
279+
sdk_create_post_set_output:
280+
code: rm.customSetOutput(r, aws.String(svcsdk.HyperParameterTuningJobStatusInProgress), ko)
281+
sdk_read_one_post_set_output:
282+
code: rm.customSetOutput(r, resp.HyperParameterTuningJobStatus, ko)
270283
fields:
271284
HyperParameterTuningJobStatus:
272285
is_read_only: true

pkg/resource/endpoint/custom_set_output.go

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,7 @@ import (
2626
corev1 "k8s.io/api/core/v1"
2727
)
2828

29-
// customCreateEndpointSetOutput sets the resource in TempOutofSync if endpoint is
30-
// in creating state. At this stage we know call to createEndpoint was successful.
31-
func (rm *resourceManager) customCreateEndpointSetOutput(
32-
ctx context.Context,
33-
r *resource,
34-
resp *svcsdk.CreateEndpointOutput,
35-
ko *svcapitypes.Endpoint,
36-
) (*svcapitypes.Endpoint, error) {
37-
rm.customSetOutput(r, aws.String(svcsdk.EndpointStatusCreating), ko)
38-
return ko, nil
39-
}
40-
41-
// customDescribeEndpointSetOutput sets the resource in TempOutofSync if endpoint is
29+
// customDescribeEndpointSetOutput sets the resource ResourceSynced condition to False if endpoint is
4230
// being modified by AWS
4331
func (rm *resourceManager) customDescribeEndpointSetOutput(
4432
ctx context.Context,
@@ -63,7 +51,7 @@ func (rm *resourceManager) customDescribeEndpointSetOutput(
6351
return ko, nil
6452
}
6553

66-
// customUpdateEndpointSetOutput sets the resource in TempOutofSync if endpoint is
54+
// customUpdateEndpointSetOutput sets the resource ResourceSynced condition to False if endpoint is
6755
// being updated. At this stage we know call to updateEndpoint was successful.
6856
func (rm *resourceManager) customUpdateEndpointSetOutput(
6957
ctx context.Context,

pkg/resource/endpoint/sdk.go

Lines changed: 1 addition & 6 deletions
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: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,39 +17,12 @@
1717
package hyper_parameter_tuning_job
1818

1919
import (
20-
"context"
21-
2220
ackv1alpha1 "github.com/aws-controllers-k8s/runtime/apis/core/v1alpha1"
2321
svcapitypes "github.com/aws-controllers-k8s/sagemaker-controller/apis/v1alpha1"
24-
"github.com/aws/aws-sdk-go/aws"
2522
svcsdk "github.com/aws/aws-sdk-go/service/sagemaker"
2623
corev1 "k8s.io/api/core/v1"
2724
)
2825

29-
// customCreateHyperParameterTuningJobSetOutput sets the resource in TempOutofSync if HyperParameterTuningJob is
30-
// in creating state. At this stage we know call to createHyperParameterTuningJob was successful.
31-
func (rm *resourceManager) customCreateHyperParameterTuningJobSetOutput(
32-
ctx context.Context,
33-
r *resource,
34-
resp *svcsdk.CreateHyperParameterTuningJobOutput,
35-
ko *svcapitypes.HyperParameterTuningJob,
36-
) (*svcapitypes.HyperParameterTuningJob, error) {
37-
rm.customSetOutput(r, aws.String(svcsdk.HyperParameterTuningJobStatusInProgress), ko)
38-
return ko, nil
39-
}
40-
41-
// customDescribeHyperParameterTuningJobSetOutput sets the resource in TempOutofSync if
42-
// HyperParameterTuningJob is being modified by AWS.
43-
func (rm *resourceManager) customDescribeHyperParameterTuningJobSetOutput(
44-
ctx context.Context,
45-
r *resource,
46-
resp *svcsdk.DescribeHyperParameterTuningJobOutput,
47-
ko *svcapitypes.HyperParameterTuningJob,
48-
) (*svcapitypes.HyperParameterTuningJob, error) {
49-
rm.customSetOutput(r, resp.HyperParameterTuningJobStatus, ko)
50-
return ko, nil
51-
}
52-
5326
// customSetOutput sets ConditionTypeResourceSynced condition to True or False
5427
// based on the hyperParameterTuningJobStatus on AWS so the reconciler can determine if a
5528
// requeue is needed

pkg/resource/hyper_parameter_tuning_job/sdk.go

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

pkg/resource/processing_job/custom_set_output.go

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,39 +17,12 @@
1717
package processing_job
1818

1919
import (
20-
"context"
21-
2220
ackv1alpha1 "github.com/aws-controllers-k8s/runtime/apis/core/v1alpha1"
2321
svcapitypes "github.com/aws-controllers-k8s/sagemaker-controller/apis/v1alpha1"
24-
"github.com/aws/aws-sdk-go/aws"
2522
svcsdk "github.com/aws/aws-sdk-go/service/sagemaker"
2623
corev1 "k8s.io/api/core/v1"
2724
)
2825

29-
// customCreateProcessingJobSetOutput sets the resource in TempOutofSync if ProcessingJob is
30-
// in creating state. At this stage we know call to createProcessingJob was successful.
31-
func (rm *resourceManager) customCreateProcessingJobSetOutput(
32-
ctx context.Context,
33-
r *resource,
34-
resp *svcsdk.CreateProcessingJobOutput,
35-
ko *svcapitypes.ProcessingJob,
36-
) (*svcapitypes.ProcessingJob, error) {
37-
rm.customSetOutput(r, aws.String(svcsdk.ProcessingJobStatusInProgress), ko)
38-
return ko, nil
39-
}
40-
41-
// customDescribeProcessingJobSetOutput sets the resource in TempOutofSync if
42-
// ProcessingJob is being modified by AWS.
43-
func (rm *resourceManager) customDescribeProcessingJobSetOutput(
44-
ctx context.Context,
45-
r *resource,
46-
resp *svcsdk.DescribeProcessingJobOutput,
47-
ko *svcapitypes.ProcessingJob,
48-
) (*svcapitypes.ProcessingJob, error) {
49-
rm.customSetOutput(r, resp.ProcessingJobStatus, ko)
50-
return ko, nil
51-
}
52-
5326
// customSetOutput sets ConditionTypeResourceSynced condition to True or False
5427
// based on the processingJobStatus on AWS so the reconciler can determine if a
5528
// requeue is needed

pkg/resource/processing_job/sdk.go

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

pkg/resource/training_job/custom_set_output.go

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,7 @@ import (
2626
corev1 "k8s.io/api/core/v1"
2727
)
2828

29-
// customCreateTrainingJobSetOutput sets the resource in TempOutofSync if TrainingJob is
30-
// in creating state. At this stage we know call to createTrainingJob was successful.
31-
func (rm *resourceManager) customCreateTrainingJobSetOutput(
32-
ctx context.Context,
33-
r *resource,
34-
resp *svcsdk.CreateTrainingJobOutput,
35-
ko *svcapitypes.TrainingJob,
36-
) (*svcapitypes.TrainingJob, error) {
37-
rm.customSetOutput(r, aws.String(svcsdk.TrainingJobStatusInProgress), ko)
38-
return ko, nil
39-
}
40-
41-
// customDescribeTrainingJobSetOutput sets the resource in TempOutofSync if
29+
// customDescribeTrainingJobSetOutput sets the resource ResourceSynced condition to False if
4230
// TrainingJob is being modified by AWS. It has an additional check on the debugger status.
4331
func (rm *resourceManager) customDescribeTrainingJobSetOutput(
4432
ctx context.Context,

pkg/resource/training_job/sdk.go

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

0 commit comments

Comments
 (0)