Skip to content

Commit 65d59c5

Browse files
authored
Handle server-side defaults (#12)
The ScalableTarget Resource has two fields which do not work with the existing ACK CompareResource functionality. This PR fixes this issue by adding these two fields to the ignore list for compare and then adding custom logic. More details discussed in [Issue #796](aws-controllers-k8s/community#796) ### Testing - I tested that the logs were as expected at each step - before any changes; after removing the compare logic entirely; after adding the custom compare function with no changes and finally the custom compare with the new checks. - I also checked the logs after manually testing with the suspendedState field added to the spec.
1 parent 470b45f commit 65d59c5

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

generator.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ resources:
1414
hooks:
1515
sdk_read_many_post_build_request:
1616
code: rm.customDescribeScalableTarget(ctx, r, input)
17+
delta_pre_compare:
18+
code: customSetDefaults(a, b)
1719
fields:
1820
ResourceID:
1921
is_name: true
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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 scalable_target
15+
16+
import (
17+
svcapitypes "github.com/aws-controllers-k8s/applicationautoscaling-controller/apis/v1alpha1"
18+
)
19+
20+
func customSetDefaults(
21+
a *resource,
22+
b *resource,
23+
) {
24+
if a.ko.Spec.SuspendedState == nil && b.ko.Spec.SuspendedState != nil {
25+
a.ko.Spec.SuspendedState = &svcapitypes.SuspendedState{}
26+
}
27+
if a.ko.Spec.SuspendedState.DynamicScalingInSuspended == nil && b.ko.Spec.SuspendedState.DynamicScalingInSuspended != nil {
28+
a.ko.Spec.SuspendedState.DynamicScalingInSuspended = b.ko.Spec.SuspendedState.DynamicScalingInSuspended
29+
}
30+
if a.ko.Spec.SuspendedState.DynamicScalingOutSuspended == nil && b.ko.Spec.SuspendedState.DynamicScalingOutSuspended != nil {
31+
a.ko.Spec.SuspendedState.DynamicScalingOutSuspended = b.ko.Spec.SuspendedState.DynamicScalingOutSuspended
32+
}
33+
if a.ko.Spec.SuspendedState.ScheduledScalingSuspended == nil && b.ko.Spec.SuspendedState.ScheduledScalingSuspended != nil {
34+
a.ko.Spec.SuspendedState.ScheduledScalingSuspended = b.ko.Spec.SuspendedState.ScheduledScalingSuspended
35+
}
36+
37+
if a.ko.Spec.RoleARN == nil && b.ko.Spec.RoleARN != nil {
38+
a.ko.Spec.RoleARN = b.ko.Spec.RoleARN
39+
}
40+
41+
}

pkg/resource/scalable_target/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)