Skip to content

Commit cff6684

Browse files
committed
Enable adopted resource and add an integration test
1 parent e21169d commit cff6684

File tree

11 files changed

+325
-12
lines changed

11 files changed

+325
-12
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
ack_generate_info:
2-
build_date: "2021-08-25T09:34:48Z"
2+
build_date: "2021-08-26T08:51:22Z"
33
build_hash: be9e3abf09e334d8585d14404a99d8adae0daec7
44
go_version: go1.14.14 darwin/amd64
55
version: v0.12.0
66
api_directory_checksum: 8697d12182de3cc93f7263c2a5d45e480b77bf05
77
api_version: v1alpha1
88
aws_sdk_go_version: v1.37.10
99
generator_config_info:
10-
file_checksum: c7e5f39c1278b0b0061103439a4075073bf19403
10+
file_checksum: 1a255ab098ba83f9aa791d130d2d8e4169d0b399
1111
original_file_name: generator.yaml
1212
last_modification:
1313
reason: API generation
14-
timestamp: 2021-08-25 09:34:57.503447 +0000 UTC
14+
timestamp: 2021-08-26 08:51:32.146215 +0000 UTC

apis/v1alpha1/generator.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ operations:
1414
primary_identifier_field_name: ResourceID
1515
resources:
1616
ScalableTarget:
17-
is_adoptable: false
1817
hooks:
1918
sdk_read_many_post_build_request:
2019
code: rm.customDescribeScalableTarget(ctx, r, input)
@@ -24,7 +23,6 @@ resources:
2423
ResourceID:
2524
is_name: true
2625
ScalingPolicy:
27-
is_adoptable: false
2826
fields:
2927
ResourceID:
3028
is_name: true

generator.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ operations:
1414
primary_identifier_field_name: ResourceID
1515
resources:
1616
ScalableTarget:
17-
is_adoptable: false
1817
hooks:
1918
sdk_read_many_post_build_request:
2019
code: rm.customDescribeScalableTarget(ctx, r, input)
@@ -24,7 +23,6 @@ resources:
2423
ResourceID:
2524
is_name: true
2625
ScalingPolicy:
27-
is_adoptable: false
2826
fields:
2927
ResourceID:
3028
is_name: true

helm/values.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
image:
66
repository: public.ecr.aws/aws-controllers-k8s/applicationautoscaling-controller
7-
tag: v0.0.1-master
7+
tag: v0.0.1
88
pullPolicy: IfNotPresent
99
pullSecrets: []
1010

@@ -41,8 +41,8 @@ aws:
4141

4242
# log level for the controller
4343
log:
44-
enable_development_logging: true
45-
level: debug
44+
enable_development_logging: false
45+
level: info
4646

4747
# Set to "namespace" to install the controller in a namespaced scope, will only
4848
# watch for object creation in the namespace. By default installScope is

pkg/resource/scalable_target/manager_factory.go

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

pkg/resource/scaling_policy/manager_factory.go

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

test/e2e/__init__.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
SERVICE_NAME = "applicationautoscaling"
2222
CRD_GROUP = "applicationautoscaling.services.k8s.aws"
23+
ADOPTED_RESOURCE_CRD_GROUP = "services.k8s.aws"
2324
CRD_VERSION = "v1alpha1"
2425

2526
# PyTest marker for the current service
@@ -61,3 +62,21 @@ def create_applicationautoscaling_resource(
6162
)
6263

6364
return reference, spec, resource
65+
66+
def create_adopted_resource(resource_name, spec_file, replacements, namespace="default"):
67+
"""
68+
Wrapper around k8s.load_and_create_resource to create a Adopoted resource
69+
"""
70+
71+
reference, spec, resource = k8s.load_and_create_resource(
72+
resource_directory,
73+
ADOPTED_RESOURCE_CRD_GROUP,
74+
CRD_VERSION,
75+
"adoptedresources",
76+
resource_name,
77+
spec_file,
78+
replacements,
79+
namespace,
80+
)
81+
82+
return reference, spec, resource
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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+
15+
import boto3
16+
17+
def application_autoscaling_client():
18+
return boto3.client("application-autoscaling")
19+
20+
def sagemaker_endpoint_register_scalable_target(resource_id):
21+
target_input = {
22+
"ServiceNamespace": "sagemaker",
23+
"ResourceId": resource_id,
24+
"ScalableDimension": "sagemaker:variant:DesiredInstanceCount",
25+
"MinCapacity": 1,
26+
"MaxCapacity": 2,
27+
}
28+
29+
target_response = application_autoscaling_client().register_scalable_target(**target_input)
30+
return target_response
31+
32+
def sagemaker_endpoint_put_scaling_policy(resource_id, policy_name):
33+
policy_input = {
34+
"PolicyName": policy_name,
35+
"ServiceNamespace": "sagemaker",
36+
"ResourceId": resource_id,
37+
"ScalableDimension": "sagemaker:variant:DesiredInstanceCount",
38+
"PolicyType": "TargetTrackingScaling",
39+
"TargetTrackingScalingPolicyConfiguration": {
40+
"TargetValue": 70.0,
41+
"ScaleInCooldown": 700,
42+
"ScaleOutCooldown": 300,
43+
"PredefinedMetricSpecification": {
44+
"PredefinedMetricType": "SageMakerVariantInvocationsPerInstance",
45+
},
46+
}
47+
}
48+
49+
policy_response = application_autoscaling_client().put_scaling_policy(**policy_input)
50+
return policy_response
51+
52+
def sagemaker_endpoint_deregister_scalable_target(resource_id):
53+
target_input = {
54+
"ServiceNamespace": "sagemaker",
55+
"ResourceId": resource_id,
56+
"ScalableDimension": "sagemaker:variant:DesiredInstanceCount",
57+
}
58+
59+
target_response = application_autoscaling_client().deregister_scalable_target(**target_input)
60+
return target_response
61+
62+
def sagemaker_endpoint_delete_scaling_policy(resource_id, policy_name):
63+
policy_input = {
64+
"ServiceNamespace": "sagemaker",
65+
"ResourceId": resource_id,
66+
"ScalableDimension": "sagemaker:variant:DesiredInstanceCount",
67+
"PolicyName": policy_name
68+
}
69+
70+
policy_response = application_autoscaling_client().delete_scaling_policy(**policy_input)
71+
return policy_response
72+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apiVersion: services.k8s.aws/v1alpha1
2+
kind: AdoptedResource
3+
metadata:
4+
name: $ADOPTED_POLICY_NAME
5+
spec:
6+
aws:
7+
nameOrID: $RESOURCE_ID
8+
additionalKeys:
9+
serviceNamespace: sagemaker
10+
kubernetes:
11+
group: applicationautoscaling.services.k8s.aws
12+
kind: ScalingPolicy
13+
metadata:
14+
name: $ADOPTED_POLICY_NAME
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apiVersion: services.k8s.aws/v1alpha1
2+
kind: AdoptedResource
3+
metadata:
4+
name: $ADOPTED_TARGET_NAME
5+
spec:
6+
aws:
7+
nameOrID: $RESOURCE_ID
8+
additionalKeys:
9+
serviceNamespace: sagemaker
10+
kubernetes:
11+
group: applicationautoscaling.services.k8s.aws
12+
kind: ScalableTarget
13+
metadata:
14+
name: $ADOPTED_TARGET_NAME

0 commit comments

Comments
 (0)