Skip to content
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,14 +1,14 @@
ack_generate_info:
build_date: "2021-09-10T21:06:37Z"
build_date: "2021-09-13T17:26:12Z"
build_hash: a988bddaea3800999e8a548e0e7a4fd44cc00b19
go_version: go1.14.14 darwin/amd64
version: v0.13.2
api_directory_checksum: a13caf20935ebb6193efdee1ab377cae33311ad7
api_version: v1alpha1
aws_sdk_go_version: v1.37.10
generator_config_info:
file_checksum: 968c7d8481a61c0299fc373cc6d1692a52b55868
file_checksum: 56e7824ca9325632a94126f3c1489f45d31e6be6
original_file_name: generator.yaml
last_modification:
reason: API generation
timestamp: 2021-09-10 21:06:47.280077 +0000 UTC
timestamp: 2021-09-13 17:26:20.032123 +0000 UTC
5 changes: 3 additions & 2 deletions apis/v1alpha1/generator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ operations:
resource_name: ScalableTarget
DescribeScalableTargets:
primary_identifier_field_name: ResourceId
custom_check_required_fields_missing_method: customCheckRequiredFieldsMissingMethod
DescribeScalingPolicies:
primary_identifier_field_name: ResourceId
resources:
ScalableTarget:
is_adoptable: false
hooks:
sdk_create_post_set_output:
code: rm.customSetLastModifiedTime(ko)
Expand All @@ -29,6 +29,8 @@ resources:
code: customSetDefaults(a, b)
sdk_update_post_set_output:
code: rm.customSetLastModifiedTime(ko)
set_identifiers_pre_read_one:
code: r.customSetPrimaryIdentifier(identifier)
fields:
ResourceID:
is_name: true
Expand All @@ -43,7 +45,6 @@ resources:
operation: DescribeScalableTargets
path: ScalableTargets..CreationTime
ScalingPolicy:
is_adoptable: false
hooks:
sdk_create_post_set_output:
code: rm.customSetLastModifiedTime(ko)
Expand Down
5 changes: 3 additions & 2 deletions generator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ operations:
resource_name: ScalableTarget
DescribeScalableTargets:
primary_identifier_field_name: ResourceId
custom_check_required_fields_missing_method: customCheckRequiredFieldsMissingMethod
DescribeScalingPolicies:
primary_identifier_field_name: ResourceId
resources:
ScalableTarget:
is_adoptable: false
hooks:
sdk_create_post_set_output:
code: rm.customSetLastModifiedTime(ko)
Expand All @@ -29,6 +29,8 @@ resources:
code: customSetDefaults(a, b)
sdk_update_post_set_output:
code: rm.customSetLastModifiedTime(ko)
set_identifiers_pre_read_one:
code: r.customSetPrimaryIdentifier(identifier)
fields:
ResourceID:
is_name: true
Expand All @@ -43,7 +45,6 @@ resources:
operation: DescribeScalableTargets
path: ScalableTargets..CreationTime
ScalingPolicy:
is_adoptable: false
hooks:
sdk_create_post_set_output:
code: rm.customSetLastModifiedTime(ko)
Expand Down
19 changes: 19 additions & 0 deletions pkg/resource/scalable_target/custom_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package scalable_target
import (
"context"
svcapitypes "github.com/aws-controllers-k8s/applicationautoscaling-controller/apis/v1alpha1"
ackv1alpha1 "github.com/aws-controllers-k8s/runtime/apis/core/v1alpha1"
svcsdk "github.com/aws/aws-sdk-go/service/applicationautoscaling"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"time"
Expand All @@ -40,3 +41,21 @@ func (rm *resourceManager) customSetLastModifiedTime(ko *svcapitypes.ScalableTar
currentTime := metav1.Time{Time: time.Now().UTC()}
ko.Status.LastModifiedTime = &currentTime
}

// customSetPrimaryIdentifier sets the ResourceId as the primary Identifier since there is
// a mismatch in the describe output and inputShape for this resource
func (r *resource) customSetPrimaryIdentifier(
identifier *ackv1alpha1.AWSIdentifiers,
) {
r.ko.Spec.ResourceID = &identifier.NameOrID
}

// customCheckRequiredFieldsMissingMethod returns true if there are any fields
// for the ReadOne Input shape that are required but not present in the
// resource's Spec or Status
func (rm *resourceManager) customCheckRequiredFieldsMissingMethod(
r *resource,
) bool {
return r.ko.Spec.ResourceID == nil

}
2 changes: 1 addition & 1 deletion pkg/resource/scalable_target/manager_factory.go

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

1 change: 1 addition & 0 deletions pkg/resource/scalable_target/resource.go

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

2 changes: 1 addition & 1 deletion pkg/resource/scalable_target/sdk.go

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

2 changes: 1 addition & 1 deletion pkg/resource/scaling_policy/manager_factory.go

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

19 changes: 19 additions & 0 deletions test/e2e/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

SERVICE_NAME = "applicationautoscaling"
CRD_GROUP = "applicationautoscaling.services.k8s.aws"
ADOPTED_RESOURCE_CRD_GROUP = "services.k8s.aws"
CRD_VERSION = "v1alpha1"

# PyTest marker for the current service
Expand Down Expand Up @@ -61,3 +62,21 @@ def create_applicationautoscaling_resource(
)

return reference, spec, resource

def create_adopted_resource(resource_name, spec_file, replacements, namespace="default"):
"""
Wrapper around k8s.load_and_create_resource to create a Adopoted resource
"""

reference, spec, resource = k8s.load_and_create_resource(
resource_directory,
ADOPTED_RESOURCE_CRD_GROUP,
CRD_VERSION,
"adoptedresources",
resource_name,
spec_file,
replacements,
namespace,
)

return reference, spec, resource
71 changes: 71 additions & 0 deletions test/e2e/common/application_autoscaling_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can rename file to utils.py?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this name is more appropriate since this bootstraps AA resources using boto3 for the tests ?

#
# Licensed under the Apache License, Version 2.0 (the "License"). You may
# not use this file except in compliance with the License. A copy of the
# License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is distributed
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied. See the License for the specific language governing
# permissions and limitations under the License.


import boto3

def application_autoscaling_client():
return boto3.client("application-autoscaling")

def sagemaker_endpoint_register_scalable_target(resource_id):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

arent these methods specific to the test? why in utills

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can call it something other than utils but this file does for applicationAutoscaling what sagemaker_utils does for sagemaker. These are pre-setup steps for the test and not really related to what we want to test and thus IMO cleaner in a separate module.

target_input = {
"ServiceNamespace": "sagemaker",
"ResourceId": resource_id,
"ScalableDimension": "sagemaker:variant:DesiredInstanceCount",
"MinCapacity": 1,
"MaxCapacity": 2,
}

target_response = application_autoscaling_client().register_scalable_target(**target_input)
return target_response

def sagemaker_endpoint_put_scaling_policy(resource_id, policy_name):
policy_input = {
"PolicyName": policy_name,
"ServiceNamespace": "sagemaker",
"ResourceId": resource_id,
"ScalableDimension": "sagemaker:variant:DesiredInstanceCount",
"PolicyType": "TargetTrackingScaling",
"TargetTrackingScalingPolicyConfiguration": {
"TargetValue": 70.0,
"ScaleInCooldown": 700,
"ScaleOutCooldown": 300,
"PredefinedMetricSpecification": {
"PredefinedMetricType": "SageMakerVariantInvocationsPerInstance",
},
}
}

policy_response = application_autoscaling_client().put_scaling_policy(**policy_input)
return policy_response

def sagemaker_endpoint_deregister_scalable_target(resource_id):
target_input = {
"ServiceNamespace": "sagemaker",
"ResourceId": resource_id,
"ScalableDimension": "sagemaker:variant:DesiredInstanceCount",
}

target_response = application_autoscaling_client().deregister_scalable_target(**target_input)
return target_response

def sagemaker_endpoint_delete_scaling_policy(resource_id, policy_name):
policy_input = {
"ServiceNamespace": "sagemaker",
"ResourceId": resource_id,
"ScalableDimension": "sagemaker:variant:DesiredInstanceCount",
"PolicyName": policy_name
}

policy_response = application_autoscaling_client().delete_scaling_policy(**policy_input)
return policy_response
14 changes: 14 additions & 0 deletions test/e2e/resources/sagemaker_endpoint_adopted_policy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: services.k8s.aws/v1alpha1
kind: AdoptedResource
metadata:
name: $ADOPTED_POLICY_NAME
spec:
aws:
nameOrID: $RESOURCE_ID
additionalKeys:
serviceNamespace: sagemaker
kubernetes:
group: applicationautoscaling.services.k8s.aws
kind: ScalingPolicy
metadata:
name: $ADOPTED_POLICY_NAME
15 changes: 15 additions & 0 deletions test/e2e/resources/sagemaker_endpoint_adopted_target.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: services.k8s.aws/v1alpha1
kind: AdoptedResource
metadata:
name: $ADOPTED_TARGET_NAME
spec:
aws:
nameOrID: $RESOURCE_ID
additionalKeys:
serviceNamespace: "sagemaker"
scalableDimension: "sagemaker:variant:DesiredInstanceCount"
kubernetes:
group: applicationautoscaling.services.k8s.aws
kind: ScalableTarget
metadata:
name: $ADOPTED_TARGET_NAME
Loading