Skip to content

Support passing Function reference in Version resource #114

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

Merged
merged 1 commit into from
Jan 11, 2024
Merged
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: "2024-01-10T21:05:33Z"
build_date: "2024-01-11T18:38:51Z"
build_hash: 1563ceb2b15ff29ee692b4178d4de5f2cbe0b0f0
go_version: go1.19
version: v0.28.0-12-g1563ceb
api_directory_checksum: 6d988b03425fad3e88d887c1cd4510a07e4be281
api_directory_checksum: 72bea0d84787d3f6fcaf7bbbc7f576a6d78b4609
api_version: v1alpha1
aws_sdk_go_version: v1.44.181
generator_config_info:
file_checksum: 5101c7f40235cfe24d7916bc0cbc95498e1d5e6c
file_checksum: 0f86b7a7f2adfe243a9aa055853514f6b4c16645
original_file_name: generator.yaml
last_modification:
reason: API generation
3 changes: 3 additions & 0 deletions apis/v1alpha1/generator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ resources:
FunctionName:
is_required: true
is_primary_key: true
references:
resource: Function
path: Spec.Name
Qualifier:
is_read_only: true
from:
Expand Down
4 changes: 2 additions & 2 deletions apis/v1alpha1/version.go

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

5 changes: 5 additions & 0 deletions apis/v1alpha1/zz_generated.deepcopy.go

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

15 changes: 13 additions & 2 deletions config/crd/bases/lambda.services.k8s.aws_versions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,25 @@ spec:
constraint applies only to the full ARN. If you specify only the
function name, it is limited to 64 characters in length."
type: string
functionRef:
description: "AWSResourceReferenceWrapper provides a wrapper around
*AWSResourceReference type to provide more user friendly syntax
for references using 'from' field Ex: APIIDRef: \n from: name: my-api"
properties:
from:
description: AWSResourceReference provides all the values necessary
to reference another k8s resource for finding the identifier(Id/ARN/Name)
properties:
name:
type: string
type: object
type: object
revisionID:
description: Only update the function if the revision ID matches the
ID that's specified. Use this option to avoid publishing a version
if the function configuration has changed since you last updated
it.
type: string
required:
- functionName
type: object
status:
description: VersionStatus defines the observed state of Version
Expand Down
3 changes: 3 additions & 0 deletions generator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ resources:
FunctionName:
is_required: true
is_primary_key: true
references:
resource: Function
path: Spec.Name
Qualifier:
is_read_only: true
from:
Expand Down
15 changes: 13 additions & 2 deletions helm/crds/lambda.services.k8s.aws_versions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,25 @@ spec:
constraint applies only to the full ARN. If you specify only the
function name, it is limited to 64 characters in length."
type: string
functionRef:
description: "AWSResourceReferenceWrapper provides a wrapper around
*AWSResourceReference type to provide more user friendly syntax
for references using 'from' field Ex: APIIDRef: \n from: name: my-api"
properties:
from:
description: AWSResourceReference provides all the values necessary
to reference another k8s resource for finding the identifier(Id/ARN/Name)
properties:
name:
type: string
type: object
type: object
revisionID:
description: Only update the function if the revision ID matches the
ID that's specified. Use this option to avoid publishing a version
if the function configuration has changed since you last updated
it.
type: string
required:
- functionName
type: object
status:
description: VersionStatus defines the observed state of Version
Expand Down
3 changes: 3 additions & 0 deletions pkg/resource/version/delta.go

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

107 changes: 106 additions & 1 deletion pkg/resource/version/references.go

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

11 changes: 11 additions & 0 deletions test/e2e/resources/version_ref.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: lambda.services.k8s.aws/v1alpha1
kind: Version
metadata:
name: $VERSION_NAME
annotations:
services.k8s.aws/region: $AWS_REGION
spec:
functionRef:
from:
name: $FUNCTION_REF_NAME
description: version created by ACK lambda-controller e2e tests
49 changes: 48 additions & 1 deletion test/e2e/tests/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,51 @@ def test_version_with_revision_hash(self, lambda_client, lambda_function):
time.sleep(DELETE_WAIT_AFTER_SECONDS)

# Check function version doesn't exist
assert not lambda_validator.version_exists(lambda_function_name, version_number)
assert not lambda_validator.version_exists(lambda_function_name, version_number)

def test_smoke_ref(self, lambda_client, lambda_function):
(_, function_resource) = lambda_function
function_resource_name = function_resource["metadata"]["name"]

resource_name = random_suffix_name("lambda-version", 24)
replacements = REPLACEMENT_VALUES.copy()
replacements["AWS_REGION"] = get_region()
replacements["VERSION_NAME"] = resource_name
replacements["FUNCTION_REF_NAME"] = function_resource_name

# Load alias CR
resource_data = load_lambda_resource(
"version_ref",
additional_replacements=replacements,
)
logging.debug(resource_data)

# Create k8s resource
ref = k8s.CustomResourceReference(
CRD_GROUP, CRD_VERSION, RESOURCE_PLURAL,
resource_name, namespace="default",
)
k8s.create_custom_resource(ref, resource_data)
cr = k8s.wait_resource_consumed_by_controller(ref)

assert cr is not None
assert k8s.get_resource_exists(ref)

time.sleep(CREATE_WAIT_AFTER_SECONDS)

cr = k8s.wait_resource_consumed_by_controller(ref)

lambda_validator = LambdaValidator(lambda_client)

# Check version exists
version_number = cr['status']['version']
assert lambda_validator.version_exists(function_resource_name, version_number)

# Delete k8s resource
_, deleted = k8s.delete_custom_resource(ref)
assert deleted is True

time.sleep(DELETE_WAIT_AFTER_SECONDS)

# Check alias doesn't exist
assert not lambda_validator.version_exists(function_resource_name, version_number)