Skip to content

Commit 749c5cb

Browse files
authored
Add default values to the comparison checker (#36)
* Add default values to the comparison checker * Remove hardcoded defaults and assign server side values instead * Use the IsNil and IsNotNil instead of simple nil checks * Fix Nil Checks
1 parent 3e1d5d4 commit 749c5cb

File tree

9 files changed

+201
-0
lines changed

9 files changed

+201
-0
lines changed

generator.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ operations:
2424
resource_name: HyperParameterTuningJob
2525
resources:
2626
Model:
27+
hooks:
28+
delta_pre_compare:
29+
code: customSetDefaults(a, b)
2730
exceptions:
2831
errors:
2932
404:
@@ -148,6 +151,8 @@ resources:
148151
- InvalidAction
149152
- UnrecognizedClientException
150153
hooks:
154+
delta_pre_compare:
155+
code: customSetDefaults(a, b)
151156
sdk_create_post_set_output:
152157
code: rm.customSetOutput(r, aws.String(svcsdk.TrainingJobStatusInProgress), ko)
153158
sdk_delete_pre_build_request:
@@ -197,6 +202,8 @@ resources:
197202
- InvalidAction
198203
- UnrecognizedClientException
199204
hooks:
205+
delta_pre_compare:
206+
code: customSetDefaults(a, b)
200207
sdk_delete_pre_build_request:
201208
template_path: processing_job/sdk_delete_pre_build_request.go.tpl
202209
sdk_create_post_set_output:
@@ -237,6 +244,8 @@ resources:
237244
- InvalidAction
238245
- UnrecognizedClientException
239246
hooks:
247+
delta_pre_compare:
248+
code: customSetDefaults(a, b)
240249
sdk_delete_pre_build_request:
241250
template_path: transform_job/sdk_delete_pre_build_request.go.tpl
242251
sdk_create_post_set_output:

pkg/resource/model/custom_delta.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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 model
15+
16+
import (
17+
ackcompare "github.com/aws-controllers-k8s/runtime/pkg/compare"
18+
svcapitypes "github.com/aws-controllers-k8s/sagemaker-controller/apis/v1alpha1"
19+
)
20+
21+
func customSetDefaults(
22+
a *resource,
23+
b *resource,
24+
) {
25+
// PrimaryContainer is not a required field, so this check is required
26+
if ackcompare.IsNil(a.ko.Spec.PrimaryContainer) && ackcompare.IsNotNil(b.ko.Spec.PrimaryContainer) {
27+
a.ko.Spec.PrimaryContainer = &svcapitypes.ContainerDefinition{}
28+
}
29+
30+
if ackcompare.IsNotNil(a.ko.Spec.PrimaryContainer) && ackcompare.IsNotNil(b.ko.Spec.PrimaryContainer) {
31+
if ackcompare.IsNil(a.ko.Spec.PrimaryContainer.Mode) && ackcompare.IsNotNil(b.ko.Spec.PrimaryContainer.Mode) {
32+
a.ko.Spec.PrimaryContainer.Mode = b.ko.Spec.PrimaryContainer.Mode
33+
}
34+
}
35+
36+
if ackcompare.IsNil(a.ko.Spec.EnableNetworkIsolation) && ackcompare.IsNotNil(b.ko.Spec.EnableNetworkIsolation) {
37+
a.ko.Spec.EnableNetworkIsolation = b.ko.Spec.EnableNetworkIsolation
38+
}
39+
}

pkg/resource/model/delta.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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 processing_job
15+
16+
import (
17+
ackcompare "github.com/aws-controllers-k8s/runtime/pkg/compare"
18+
svcapitypes "github.com/aws-controllers-k8s/sagemaker-controller/apis/v1alpha1"
19+
)
20+
21+
func customSetDefaults(
22+
a *resource,
23+
b *resource,
24+
) {
25+
// StoppingCondition is not a required field, so first create it
26+
if ackcompare.IsNil(a.ko.Spec.StoppingCondition) && ackcompare.IsNotNil(b.ko.Spec.StoppingCondition) {
27+
a.ko.Spec.StoppingCondition = &svcapitypes.ProcessingStoppingCondition{}
28+
}
29+
30+
if ackcompare.IsNotNil(a.ko.Spec.StoppingCondition) && ackcompare.IsNotNil(b.ko.Spec.StoppingCondition) {
31+
if ackcompare.IsNil(a.ko.Spec.StoppingCondition.MaxRuntimeInSeconds) && ackcompare.IsNotNil(b.ko.Spec.StoppingCondition.MaxRuntimeInSeconds) {
32+
a.ko.Spec.StoppingCondition.MaxRuntimeInSeconds = b.ko.Spec.StoppingCondition.MaxRuntimeInSeconds
33+
}
34+
}
35+
}

pkg/resource/processing_job/delta.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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 training_job
15+
16+
import (
17+
ackcompare "github.com/aws-controllers-k8s/runtime/pkg/compare"
18+
)
19+
20+
func customSetDefaults(
21+
a *resource,
22+
b *resource,
23+
) {
24+
if ackcompare.IsNil(a.ko.Spec.EnableInterContainerTrafficEncryption) && ackcompare.IsNotNil(b.ko.Spec.EnableInterContainerTrafficEncryption) {
25+
a.ko.Spec.EnableInterContainerTrafficEncryption = b.ko.Spec.EnableInterContainerTrafficEncryption
26+
}
27+
28+
if ackcompare.IsNil(a.ko.Spec.EnableManagedSpotTraining) && ackcompare.IsNotNil(b.ko.Spec.EnableManagedSpotTraining) {
29+
a.ko.Spec.EnableManagedSpotTraining = b.ko.Spec.EnableManagedSpotTraining
30+
}
31+
32+
if ackcompare.IsNil(a.ko.Spec.EnableNetworkIsolation) && ackcompare.IsNotNil(b.ko.Spec.EnableNetworkIsolation) {
33+
a.ko.Spec.EnableNetworkIsolation = b.ko.Spec.EnableNetworkIsolation
34+
}
35+
36+
// AlgorithmSpecification is a required field
37+
if ackcompare.IsNotNil(a.ko.Spec.AlgorithmSpecification) && ackcompare.IsNotNil(b.ko.Spec.AlgorithmSpecification) {
38+
if ackcompare.IsNil(a.ko.Spec.AlgorithmSpecification.EnableSageMakerMetricsTimeSeries) && ackcompare.IsNotNil(b.ko.Spec.AlgorithmSpecification.EnableSageMakerMetricsTimeSeries) {
39+
a.ko.Spec.AlgorithmSpecification.EnableSageMakerMetricsTimeSeries = b.ko.Spec.AlgorithmSpecification.EnableSageMakerMetricsTimeSeries
40+
}
41+
}
42+
43+
// OutputDataConfig is a required field but the KMS Key is an empty string by default, it cannot be nil.
44+
if ackcompare.IsNotNil(a.ko.Spec.OutputDataConfig) && ackcompare.IsNotNil(b.ko.Spec.OutputDataConfig) {
45+
if ackcompare.IsNil(a.ko.Spec.OutputDataConfig.KMSKeyID) && ackcompare.IsNotNil(b.ko.Spec.OutputDataConfig.KMSKeyID) {
46+
a.ko.Spec.OutputDataConfig.KMSKeyID = b.ko.Spec.OutputDataConfig.KMSKeyID
47+
}
48+
}
49+
}

pkg/resource/training_job/delta.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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 transform_job
15+
16+
import (
17+
ackcompare "github.com/aws-controllers-k8s/runtime/pkg/compare"
18+
svcapitypes "github.com/aws-controllers-k8s/sagemaker-controller/apis/v1alpha1"
19+
)
20+
21+
func customSetDefaults(
22+
a *resource,
23+
b *resource,
24+
) {
25+
// TransformInput is a required field.
26+
if ackcompare.IsNil(a.ko.Spec.TransformInput.CompressionType) && ackcompare.IsNotNil(b.ko.Spec.TransformInput.CompressionType) {
27+
a.ko.Spec.TransformInput.CompressionType = b.ko.Spec.TransformInput.CompressionType
28+
}
29+
30+
if ackcompare.IsNil(a.ko.Spec.TransformInput.SplitType) && ackcompare.IsNotNil(b.ko.Spec.TransformInput.SplitType) {
31+
a.ko.Spec.TransformInput.SplitType = b.ko.Spec.TransformInput.SplitType
32+
}
33+
34+
// DataProcessing is not a required field, so first create it.
35+
if ackcompare.IsNil(a.ko.Spec.DataProcessing) && ackcompare.IsNotNil(b.ko.Spec.DataProcessing) {
36+
a.ko.Spec.DataProcessing = &svcapitypes.DataProcessing{}
37+
}
38+
39+
if ackcompare.IsNotNil(a.ko.Spec.DataProcessing) && ackcompare.IsNotNil(b.ko.Spec.DataProcessing) {
40+
if ackcompare.IsNil(a.ko.Spec.DataProcessing.InputFilter) && ackcompare.IsNotNil(b.ko.Spec.DataProcessing.InputFilter) {
41+
a.ko.Spec.DataProcessing.InputFilter = b.ko.Spec.DataProcessing.InputFilter
42+
}
43+
if ackcompare.IsNil(a.ko.Spec.DataProcessing.JoinSource) && ackcompare.IsNotNil(b.ko.Spec.DataProcessing.JoinSource) {
44+
a.ko.Spec.DataProcessing.JoinSource = b.ko.Spec.DataProcessing.JoinSource
45+
}
46+
if ackcompare.IsNil(a.ko.Spec.DataProcessing.OutputFilter) && ackcompare.IsNotNil(b.ko.Spec.DataProcessing.OutputFilter) {
47+
a.ko.Spec.DataProcessing.OutputFilter = b.ko.Spec.DataProcessing.OutputFilter
48+
}
49+
}
50+
51+
// TODO: TransformOutput is a required field, so this check should not be required
52+
if ackcompare.IsNil(a.ko.Spec.TransformOutput) && ackcompare.IsNotNil(b.ko.Spec.TransformOutput) {
53+
a.ko.Spec.TransformOutput = &svcapitypes.TransformOutput{}
54+
}
55+
56+
if ackcompare.IsNotNil(a.ko.Spec.TransformOutput) && ackcompare.IsNotNil(b.ko.Spec.TransformOutput) {
57+
if ackcompare.IsNil(a.ko.Spec.TransformOutput.AssembleWith) && ackcompare.IsNotNil(b.ko.Spec.TransformOutput.AssembleWith) {
58+
a.ko.Spec.TransformOutput.AssembleWith = b.ko.Spec.TransformOutput.AssembleWith
59+
}
60+
if ackcompare.IsNil(a.ko.Spec.TransformOutput.KMSKeyID) && ackcompare.IsNotNil(b.ko.Spec.TransformOutput.KMSKeyID) {
61+
a.ko.Spec.TransformOutput.KMSKeyID = b.ko.Spec.TransformOutput.KMSKeyID
62+
}
63+
}
64+
65+
}

pkg/resource/transform_job/delta.go

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

0 commit comments

Comments
 (0)