Skip to content

Commit

Permalink
enable deletion of resource if job is complete (aws-controllers-k8s#16)
Browse files Browse the repository at this point in the history
- enable deletion of resource if job is complete
- reduce custom code by using callback hooks
  • Loading branch information
surajkota authored Apr 21, 2021
1 parent 89253de commit 3c1fc55
Show file tree
Hide file tree
Showing 15 changed files with 88 additions and 172 deletions.
45 changes: 29 additions & 16 deletions generator.yaml
Original file line number Diff line number Diff line change
@@ -1,27 +1,15 @@
operations:
CreateTrainingJob:
set_output_custom_method_name: customCreateTrainingJobSetOutput
DescribeTrainingJob:
set_output_custom_method_name: customDescribeTrainingJobSetOutput
StopTrainingJob:
operation_type: Delete
resource_name: TrainingJob
CreateProcessingJob:
set_output_custom_method_name: customCreateProcessingJobSetOutput
DescribeProcessingJob:
set_output_custom_method_name: customDescribeProcessingJobSetOutput
StopProcessingJob:
operation_type: Delete
resource_name: ProcessingJob
CreateTransformJob:
set_output_custom_method_name: customCreateTransformJobSetOutput
DescribeTransformJob:
set_output_custom_method_name: customDescribeTransformJobSetOutput
StopTransformJob:
operation_type: Delete
resource_name: TransformJob
CreateEndpoint:
set_output_custom_method_name: customCreateEndpointSetOutput
DescribeEndpoint:
set_output_custom_method_name: customDescribeEndpointSetOutput
UpdateEndpoint:
Expand All @@ -31,10 +19,6 @@ operations:
RetainAllVariantProperties: true
DeleteEndpoint:
custom_implementation: customDeleteEndpoint
CreateHyperParameterTuningJob:
set_output_custom_method_name: customCreateHyperParameterTuningJobSetOutput
DescribeHyperParameterTuningJob:
set_output_custom_method_name: customDescribeHyperParameterTuningJobSetOutput
StopHyperParameterTuningJob:
operation_type: Delete
resource_name: HyperParameterTuningJob
Expand Down Expand Up @@ -100,6 +84,9 @@ resources:
- MalformedQueryString
- InvalidAction
- UnrecognizedClientException
hooks:
sdk_create_post_set_output:
code: rm.customSetOutput(r, aws.String(svcsdk.EndpointStatusCreating), ko)
fields:
EndpointStatus:
is_read_only: true
Expand Down Expand Up @@ -158,6 +145,11 @@ resources:
- MalformedQueryString
- InvalidAction
- UnrecognizedClientException
hooks:
sdk_create_post_set_output:
code: rm.customSetOutput(r, aws.String(svcsdk.TrainingJobStatusInProgress), ko)
sdk_delete_pre_build_request:
template_path: training_job/sdk_delete_pre_build_request.go.tpl
fields:
TrainingJobStatus:
is_read_only: true
Expand Down Expand Up @@ -202,6 +194,13 @@ resources:
- MalformedQueryString
- InvalidAction
- UnrecognizedClientException
hooks:
sdk_delete_pre_build_request:
template_path: processing_job/sdk_delete_pre_build_request.go.tpl
sdk_create_post_set_output:
code: rm.customSetOutput(r, aws.String(svcsdk.ProcessingJobStatusInProgress), ko)
sdk_read_one_post_set_output:
code: rm.customSetOutput(r, resp.ProcessingJobStatus, ko)
fields:
ProcessingJobStatus:
is_read_only: true
Expand Down Expand Up @@ -235,6 +234,13 @@ resources:
- MalformedQueryString
- InvalidAction
- UnrecognizedClientException
hooks:
sdk_delete_pre_build_request:
template_path: transform_job/sdk_delete_pre_build_request.go.tpl
sdk_create_post_set_output:
code: rm.customSetOutput(r, aws.String(svcsdk.TransformJobStatusInProgress), ko)
sdk_read_one_post_set_output:
code: rm.customSetOutput(r, resp.TransformJobStatus, ko)
fields:
TransformJobStatus:
is_read_only: true
Expand Down Expand Up @@ -267,6 +273,13 @@ resources:
- MalformedQueryString
- InvalidAction
- UnrecognizedClientException
hooks:
sdk_delete_pre_build_request:
template_path: hyper_parameter_tuning_job/sdk_delete_pre_build_request.go.tpl
sdk_create_post_set_output:
code: rm.customSetOutput(r, aws.String(svcsdk.HyperParameterTuningJobStatusInProgress), ko)
sdk_read_one_post_set_output:
code: rm.customSetOutput(r, resp.HyperParameterTuningJobStatus, ko)
fields:
HyperParameterTuningJobStatus:
is_read_only: true
Expand Down
16 changes: 2 additions & 14 deletions pkg/resource/endpoint/custom_set_output.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,7 @@ import (
corev1 "k8s.io/api/core/v1"
)

// customCreateEndpointSetOutput sets the resource in TempOutofSync if endpoint is
// in creating state. At this stage we know call to createEndpoint was successful.
func (rm *resourceManager) customCreateEndpointSetOutput(
ctx context.Context,
r *resource,
resp *svcsdk.CreateEndpointOutput,
ko *svcapitypes.Endpoint,
) (*svcapitypes.Endpoint, error) {
rm.customSetOutput(r, aws.String(svcsdk.EndpointStatusCreating), ko)
return ko, nil
}

// customDescribeEndpointSetOutput sets the resource in TempOutofSync if endpoint is
// customDescribeEndpointSetOutput sets the resource ResourceSynced condition to False if endpoint is
// being modified by AWS
func (rm *resourceManager) customDescribeEndpointSetOutput(
ctx context.Context,
Expand All @@ -63,7 +51,7 @@ func (rm *resourceManager) customDescribeEndpointSetOutput(
return ko, nil
}

// customUpdateEndpointSetOutput sets the resource in TempOutofSync if endpoint is
// customUpdateEndpointSetOutput sets the resource ResourceSynced condition to False if endpoint is
// being updated. At this stage we know call to updateEndpoint was successful.
func (rm *resourceManager) customUpdateEndpointSetOutput(
ctx context.Context,
Expand Down
7 changes: 1 addition & 6 deletions pkg/resource/endpoint/sdk.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 0 additions & 27 deletions pkg/resource/hyper_parameter_tuning_job/custom_set_output.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,39 +17,12 @@
package hyper_parameter_tuning_job

import (
"context"

ackv1alpha1 "github.com/aws-controllers-k8s/runtime/apis/core/v1alpha1"
svcapitypes "github.com/aws-controllers-k8s/sagemaker-controller/apis/v1alpha1"
"github.com/aws/aws-sdk-go/aws"
svcsdk "github.com/aws/aws-sdk-go/service/sagemaker"
corev1 "k8s.io/api/core/v1"
)

// customCreateHyperParameterTuningJobSetOutput sets the resource in TempOutofSync if HyperParameterTuningJob is
// in creating state. At this stage we know call to createHyperParameterTuningJob was successful.
func (rm *resourceManager) customCreateHyperParameterTuningJobSetOutput(
ctx context.Context,
r *resource,
resp *svcsdk.CreateHyperParameterTuningJobOutput,
ko *svcapitypes.HyperParameterTuningJob,
) (*svcapitypes.HyperParameterTuningJob, error) {
rm.customSetOutput(r, aws.String(svcsdk.HyperParameterTuningJobStatusInProgress), ko)
return ko, nil
}

// customDescribeHyperParameterTuningJobSetOutput sets the resource in TempOutofSync if
// HyperParameterTuningJob is being modified by AWS.
func (rm *resourceManager) customDescribeHyperParameterTuningJobSetOutput(
ctx context.Context,
r *resource,
resp *svcsdk.DescribeHyperParameterTuningJobOutput,
ko *svcapitypes.HyperParameterTuningJob,
) (*svcapitypes.HyperParameterTuningJob, error) {
rm.customSetOutput(r, resp.HyperParameterTuningJobStatus, ko)
return ko, nil
}

// customSetOutput sets ConditionTypeResourceSynced condition to True or False
// based on the hyperParameterTuningJobStatus on AWS so the reconciler can determine if a
// requeue is needed
Expand Down
20 changes: 8 additions & 12 deletions pkg/resource/hyper_parameter_tuning_job/sdk.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 0 additions & 27 deletions pkg/resource/processing_job/custom_set_output.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,39 +17,12 @@
package processing_job

import (
"context"

ackv1alpha1 "github.com/aws-controllers-k8s/runtime/apis/core/v1alpha1"
svcapitypes "github.com/aws-controllers-k8s/sagemaker-controller/apis/v1alpha1"
"github.com/aws/aws-sdk-go/aws"
svcsdk "github.com/aws/aws-sdk-go/service/sagemaker"
corev1 "k8s.io/api/core/v1"
)

// customCreateProcessingJobSetOutput sets the resource in TempOutofSync if ProcessingJob is
// in creating state. At this stage we know call to createProcessingJob was successful.
func (rm *resourceManager) customCreateProcessingJobSetOutput(
ctx context.Context,
r *resource,
resp *svcsdk.CreateProcessingJobOutput,
ko *svcapitypes.ProcessingJob,
) (*svcapitypes.ProcessingJob, error) {
rm.customSetOutput(r, aws.String(svcsdk.ProcessingJobStatusInProgress), ko)
return ko, nil
}

// customDescribeProcessingJobSetOutput sets the resource in TempOutofSync if
// ProcessingJob is being modified by AWS.
func (rm *resourceManager) customDescribeProcessingJobSetOutput(
ctx context.Context,
r *resource,
resp *svcsdk.DescribeProcessingJobOutput,
ko *svcapitypes.ProcessingJob,
) (*svcapitypes.ProcessingJob, error) {
rm.customSetOutput(r, resp.ProcessingJobStatus, ko)
return ko, nil
}

// customSetOutput sets ConditionTypeResourceSynced condition to True or False
// based on the processingJobStatus on AWS so the reconciler can determine if a
// requeue is needed
Expand Down
20 changes: 8 additions & 12 deletions pkg/resource/processing_job/sdk.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 1 addition & 13 deletions pkg/resource/training_job/custom_set_output.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,7 @@ import (
corev1 "k8s.io/api/core/v1"
)

// customCreateTrainingJobSetOutput sets the resource in TempOutofSync if TrainingJob is
// in creating state. At this stage we know call to createTrainingJob was successful.
func (rm *resourceManager) customCreateTrainingJobSetOutput(
ctx context.Context,
r *resource,
resp *svcsdk.CreateTrainingJobOutput,
ko *svcapitypes.TrainingJob,
) (*svcapitypes.TrainingJob, error) {
rm.customSetOutput(r, aws.String(svcsdk.TrainingJobStatusInProgress), ko)
return ko, nil
}

// customDescribeTrainingJobSetOutput sets the resource in TempOutofSync if
// customDescribeTrainingJobSetOutput sets the resource ResourceSynced condition to False if
// TrainingJob is being modified by AWS. It has an additional check on the debugger status.
func (rm *resourceManager) customDescribeTrainingJobSetOutput(
ctx context.Context,
Expand Down
13 changes: 7 additions & 6 deletions pkg/resource/training_job/sdk.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 0 additions & 27 deletions pkg/resource/transform_job/custom_set_output.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,39 +17,12 @@
package transform_job

import (
"context"

ackv1alpha1 "github.com/aws-controllers-k8s/runtime/apis/core/v1alpha1"
svcapitypes "github.com/aws-controllers-k8s/sagemaker-controller/apis/v1alpha1"
"github.com/aws/aws-sdk-go/aws"
svcsdk "github.com/aws/aws-sdk-go/service/sagemaker"
corev1 "k8s.io/api/core/v1"
)

// customCreateTransformJobSetOutput sets the resource in TempOutofSync if TransformJob is
// in creating state. At this stage we know call to createTransformJob was successful.
func (rm *resourceManager) customCreateTransformJobSetOutput(
ctx context.Context,
r *resource,
resp *svcsdk.CreateTransformJobOutput,
ko *svcapitypes.TransformJob,
) (*svcapitypes.TransformJob, error) {
rm.customSetOutput(r, aws.String(svcsdk.TransformJobStatusInProgress), ko)
return ko, nil
}

// customDescribeTransformJobSetOutput sets the resource in TempOutofSync if
// TransformJob is being modified by AWS.
func (rm *resourceManager) customDescribeTransformJobSetOutput(
ctx context.Context,
r *resource,
resp *svcsdk.DescribeTransformJobOutput,
ko *svcapitypes.TransformJob,
) (*svcapitypes.TransformJob, error) {
rm.customSetOutput(r, resp.TransformJobStatus, ko)
return ko, nil
}

// customSetOutput sets ConditionTypeResourceSynced condition to True or False
// based on the transformJobStatus on AWS so the reconciler can determine if a
// requeue is needed
Expand Down
Loading

0 comments on commit 3c1fc55

Please sign in to comment.