Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
8 changes: 4 additions & 4 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: "2021-09-13T20:41:14Z"
build_hash: c6e8ce29423336f827d2ca5c737595561c84539c
build_date: "2021-09-14T01:33:26Z"
build_hash: 5a4809a4882a9beb39c737529907a3ebaff3910c
go_version: go1.14.14
version: v0.13.2
version: v0.14.0
api_directory_checksum: a13caf20935ebb6193efdee1ab377cae33311ad7
api_version: v1alpha1
aws_sdk_go_version: v1.37.10
generator_config_info:
file_checksum: 968c7d8481a61c0299fc373cc6d1692a52b55868
file_checksum: f8ed39c2c7a95648bd194f7db3e2e2d8afdbe724
original_file_name: generator.yaml
last_modification:
reason: API generation
10 changes: 3 additions & 7 deletions apis/v1alpha1/generator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,9 @@ operations:
- Delete
resource_name: ScalableTarget
DescribeScalableTargets:
primary_identifier_field_name: ResourceId
DescribeScalingPolicies:
primary_identifier_field_name: ResourceId
custom_check_required_fields_missing_method: customCheckRequiredFieldsMissingMethod
resources:
ScalableTarget:
is_adoptable: false
hooks:
sdk_create_post_set_output:
code: rm.customSetLastModifiedTime(ko)
Expand All @@ -31,7 +28,7 @@ resources:
code: rm.customSetLastModifiedTime(ko)
fields:
ResourceID:
is_name: true
is_primary_key: true
CreationTime:
is_read_only: true
from:
Expand All @@ -43,15 +40,14 @@ resources:
operation: DescribeScalableTargets
path: ScalableTargets..CreationTime
ScalingPolicy:
is_adoptable: false
hooks:
sdk_create_post_set_output:
code: rm.customSetLastModifiedTime(ko)
sdk_update_post_set_output:
code: rm.customSetLastModifiedTime(ko)
fields:
ResourceID:
is_name: true
is_primary_key: true
PolicyARN:
is_arn: true
CreationTime:
Expand Down
10 changes: 3 additions & 7 deletions generator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,9 @@ operations:
- Delete
resource_name: ScalableTarget
DescribeScalableTargets:
primary_identifier_field_name: ResourceId
DescribeScalingPolicies:
primary_identifier_field_name: ResourceId
custom_check_required_fields_missing_method: customCheckRequiredFieldsMissingMethod
resources:
ScalableTarget:
is_adoptable: false
hooks:
sdk_create_post_set_output:
code: rm.customSetLastModifiedTime(ko)
Expand All @@ -31,7 +28,7 @@ resources:
code: rm.customSetLastModifiedTime(ko)
fields:
ResourceID:
is_name: true
is_primary_key: true
CreationTime:
is_read_only: true
from:
Expand All @@ -43,15 +40,14 @@ resources:
operation: DescribeScalableTargets
path: ScalableTargets..CreationTime
ScalingPolicy:
is_adoptable: false
hooks:
sdk_create_post_set_output:
code: rm.customSetLastModifiedTime(ko)
sdk_update_post_set_output:
code: rm.customSetLastModifiedTime(ko)
fields:
ResourceID:
is_name: true
is_primary_key: true
PolicyARN:
is_arn: true
CreationTime:
Expand Down
10 changes: 10 additions & 0 deletions pkg/resource/scalable_target/custom_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,13 @@ func (rm *resourceManager) customSetLastModifiedTime(ko *svcapitypes.ScalableTar
currentTime := metav1.Time{Time: time.Now().UTC()}
ko.Status.LastModifiedTime = &currentTime
}

// 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.
#
# 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):
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