Skip to content

Commit 488981c

Browse files
authored
Support passing Function reference in Version resource (#114)
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 862aee4 commit 488981c

11 files changed

+210
-11
lines changed
+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
ack_generate_info:
2-
build_date: "2024-01-10T21:05:33Z"
2+
build_date: "2024-01-11T18:38:51Z"
33
build_hash: 1563ceb2b15ff29ee692b4178d4de5f2cbe0b0f0
44
go_version: go1.19
55
version: v0.28.0-12-g1563ceb
6-
api_directory_checksum: 6d988b03425fad3e88d887c1cd4510a07e4be281
6+
api_directory_checksum: 72bea0d84787d3f6fcaf7bbbc7f576a6d78b4609
77
api_version: v1alpha1
88
aws_sdk_go_version: v1.44.181
99
generator_config_info:
10-
file_checksum: 5101c7f40235cfe24d7916bc0cbc95498e1d5e6c
10+
file_checksum: 0f86b7a7f2adfe243a9aa055853514f6b4c16645
1111
original_file_name: generator.yaml
1212
last_modification:
1313
reason: API generation

apis/v1alpha1/generator.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,9 @@ resources:
218218
FunctionName:
219219
is_required: true
220220
is_primary_key: true
221+
references:
222+
resource: Function
223+
path: Spec.Name
221224
Qualifier:
222225
is_read_only: true
223226
from:

apis/v1alpha1/version.go

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/v1alpha1/zz_generated.deepcopy.go

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/lambda.services.k8s.aws_versions.yaml

+13-2
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,25 @@ spec:
5252
constraint applies only to the full ARN. If you specify only the
5353
function name, it is limited to 64 characters in length."
5454
type: string
55+
functionRef:
56+
description: "AWSResourceReferenceWrapper provides a wrapper around
57+
*AWSResourceReference type to provide more user friendly syntax
58+
for references using 'from' field Ex: APIIDRef: \n from: name: my-api"
59+
properties:
60+
from:
61+
description: AWSResourceReference provides all the values necessary
62+
to reference another k8s resource for finding the identifier(Id/ARN/Name)
63+
properties:
64+
name:
65+
type: string
66+
type: object
67+
type: object
5568
revisionID:
5669
description: Only update the function if the revision ID matches the
5770
ID that's specified. Use this option to avoid publishing a version
5871
if the function configuration has changed since you last updated
5972
it.
6073
type: string
61-
required:
62-
- functionName
6374
type: object
6475
status:
6576
description: VersionStatus defines the observed state of Version

generator.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,9 @@ resources:
218218
FunctionName:
219219
is_required: true
220220
is_primary_key: true
221+
references:
222+
resource: Function
223+
path: Spec.Name
221224
Qualifier:
222225
is_read_only: true
223226
from:

helm/crds/lambda.services.k8s.aws_versions.yaml

+13-2
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,25 @@ spec:
5252
constraint applies only to the full ARN. If you specify only the
5353
function name, it is limited to 64 characters in length."
5454
type: string
55+
functionRef:
56+
description: "AWSResourceReferenceWrapper provides a wrapper around
57+
*AWSResourceReference type to provide more user friendly syntax
58+
for references using 'from' field Ex: APIIDRef: \n from: name: my-api"
59+
properties:
60+
from:
61+
description: AWSResourceReference provides all the values necessary
62+
to reference another k8s resource for finding the identifier(Id/ARN/Name)
63+
properties:
64+
name:
65+
type: string
66+
type: object
67+
type: object
5568
revisionID:
5669
description: Only update the function if the revision ID matches the
5770
ID that's specified. Use this option to avoid publishing a version
5871
if the function configuration has changed since you last updated
5972
it.
6073
type: string
61-
required:
62-
- functionName
6374
type: object
6475
status:
6576
description: VersionStatus defines the observed state of Version

pkg/resource/version/delta.go

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/resource/version/references.go

+106-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/e2e/resources/version_ref.yaml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: lambda.services.k8s.aws/v1alpha1
2+
kind: Version
3+
metadata:
4+
name: $VERSION_NAME
5+
annotations:
6+
services.k8s.aws/region: $AWS_REGION
7+
spec:
8+
functionRef:
9+
from:
10+
name: $FUNCTION_REF_NAME
11+
description: version created by ACK lambda-controller e2e tests

test/e2e/tests/test_version.py

+48-1
Original file line numberDiff line numberDiff line change
@@ -184,4 +184,51 @@ def test_version_with_revision_hash(self, lambda_client, lambda_function):
184184
time.sleep(DELETE_WAIT_AFTER_SECONDS)
185185

186186
# Check function version doesn't exist
187-
assert not lambda_validator.version_exists(lambda_function_name, version_number)
187+
assert not lambda_validator.version_exists(lambda_function_name, version_number)
188+
189+
def test_smoke_ref(self, lambda_client, lambda_function):
190+
(_, function_resource) = lambda_function
191+
function_resource_name = function_resource["metadata"]["name"]
192+
193+
resource_name = random_suffix_name("lambda-version", 24)
194+
replacements = REPLACEMENT_VALUES.copy()
195+
replacements["AWS_REGION"] = get_region()
196+
replacements["VERSION_NAME"] = resource_name
197+
replacements["FUNCTION_REF_NAME"] = function_resource_name
198+
199+
# Load alias CR
200+
resource_data = load_lambda_resource(
201+
"version_ref",
202+
additional_replacements=replacements,
203+
)
204+
logging.debug(resource_data)
205+
206+
# Create k8s resource
207+
ref = k8s.CustomResourceReference(
208+
CRD_GROUP, CRD_VERSION, RESOURCE_PLURAL,
209+
resource_name, namespace="default",
210+
)
211+
k8s.create_custom_resource(ref, resource_data)
212+
cr = k8s.wait_resource_consumed_by_controller(ref)
213+
214+
assert cr is not None
215+
assert k8s.get_resource_exists(ref)
216+
217+
time.sleep(CREATE_WAIT_AFTER_SECONDS)
218+
219+
cr = k8s.wait_resource_consumed_by_controller(ref)
220+
221+
lambda_validator = LambdaValidator(lambda_client)
222+
223+
# Check version exists
224+
version_number = cr['status']['version']
225+
assert lambda_validator.version_exists(function_resource_name, version_number)
226+
227+
# Delete k8s resource
228+
_, deleted = k8s.delete_custom_resource(ref)
229+
assert deleted is True
230+
231+
time.sleep(DELETE_WAIT_AFTER_SECONDS)
232+
233+
# Check alias doesn't exist
234+
assert not lambda_validator.version_exists(function_resource_name, version_number)

0 commit comments

Comments
 (0)