Skip to content

Set policyName in DescribeScalingPolicies input request #105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions apis/v1alpha1/ack-generate-metadata.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
ack_generate_info:
build_date: "2023-05-15T22:45:51Z"
build_date: "2023-06-26T18:59:44Z"
build_hash: 8f3ba427974fd6e769926778d54834eaee3b81a3
go_version: go1.19
go_version: go1.20.1
version: v0.26.1
api_directory_checksum: 81d152c4602b014d435a9ba3d716ed5112273013
api_version: v1alpha1
aws_sdk_go_version: v1.44.93
generator_config_info:
file_checksum: b2ac33cc79c75dfc65066ea3fca66ad781d4ae18
file_checksum: e5f40f1e7ac3be9113553960bfcb5945c7c08ab7
original_file_name: generator.yaml
last_modification:
reason: API generation
2 changes: 2 additions & 0 deletions apis/v1alpha1/generator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ resources:
code: rm.customSetLastModifiedTimeToCreationTime(ko)
sdk_update_post_set_output:
code: rm.customSetLastModifiedTimeToCurrentTime(ko)
sdk_read_many_post_build_request:
code: rm.customDescribeScalingPolicies(ctx, r, input)
fields:
ResourceID:
is_primary_key: true
Expand Down
2 changes: 2 additions & 0 deletions generator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ resources:
code: rm.customSetLastModifiedTimeToCreationTime(ko)
sdk_update_post_set_output:
code: rm.customSetLastModifiedTimeToCurrentTime(ko)
sdk_read_many_post_build_request:
code: rm.customDescribeScalingPolicies(ctx, r, input)
fields:
ResourceID:
is_primary_key: true
Expand Down
20 changes: 19 additions & 1 deletion pkg/resource/scaling_policy/custom_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@
package scaling_policy

import (
"context"
"time"

svcapitypes "github.com/aws-controllers-k8s/applicationautoscaling-controller/apis/v1alpha1"
svcsdk "github.com/aws/aws-sdk-go/service/applicationautoscaling"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"time"
)

// customSetLastModifiedTimeToCreationTime sets the LastModifiedTime field to the creationTime
Expand All @@ -31,3 +34,18 @@ func (rm *resourceManager) customSetLastModifiedTimeToCurrentTime(ko *svcapitype
currentTime := metav1.Time{Time: time.Now().UTC()}
ko.Status.LastModifiedTime = &currentTime
}

// customDescribeScalingPolicies sets the policy name in DescribeScalingPoliciesInput
func (rm *resourceManager) customDescribeScalingPolicies(
ctx context.Context,
latest *resource,
input *svcsdk.DescribeScalingPoliciesInput,
) {
spec := latest.ko.Spec

var policyNames []*string
if spec.PolicyName != nil {
policyNames = append(policyNames, spec.PolicyName)
input.SetPolicyNames(policyNames)
}
}
1 change: 1 addition & 0 deletions pkg/resource/scaling_policy/sdk.go

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

32 changes: 23 additions & 9 deletions test/e2e/tests/test_scalingpolicy.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,34 @@ def _get_dynamodb_scaling_policy_exists(
return len(targets["ScalingPolicies"]) == 1

def test_smoke(self, applicationautoscaling_client):
(reference, policy) = self._generate_dynamodb_policy(get_bootstrap_resources())
resource = k8s.create_custom_resource(reference, policy)
resource = k8s.wait_resource_consumed_by_controller(reference)
assert k8s.get_resource_exists(reference)

policyName = policy["spec"].get("policyName")
assert policyName is not None
(reference_a, policy_a) = self._generate_dynamodb_policy(get_bootstrap_resources())
(reference_b, policy_b) = self._generate_dynamodb_policy(get_bootstrap_resources())

resource = k8s.create_custom_resource(reference_a, policy_a)
resource = k8s.wait_resource_consumed_by_controller(reference_a)
assert k8s.get_resource_exists(reference_a)

resource = k8s.create_custom_resource(reference_b, policy_b)
resource = k8s.wait_resource_consumed_by_controller(reference_b)
assert k8s.get_resource_exists(reference_b)

policyNameA = policy_a["spec"].get("policyName")
assert policyNameA is not None
policyNameB = policy_b["spec"].get("policyName")
assert policyNameB is not None

exists = self._get_dynamodb_scaling_policy_exists(
applicationautoscaling_client, policyName
applicationautoscaling_client, policyNameA,
)
assert exists
exists = self._get_dynamodb_scaling_policy_exists(
applicationautoscaling_client, policyNameB,
)
assert exists

_, deleted = k8s.delete_custom_resource(reference)
_, deleted = k8s.delete_custom_resource(reference_a)
assert deleted is True
_, deleted = k8s.delete_custom_resource(reference_b)
assert deleted is True

exists = self._get_dynamodb_scaling_policy_exists(
Expand Down