diff --git a/apis/v1alpha1/ack-generate-metadata.yaml b/apis/v1alpha1/ack-generate-metadata.yaml index b77478ef..6ad5b45f 100755 --- a/apis/v1alpha1/ack-generate-metadata.yaml +++ b/apis/v1alpha1/ack-generate-metadata.yaml @@ -1,5 +1,5 @@ ack_generate_info: - build_date: "2024-04-16T16:52:09Z" + build_date: "2024-04-16T23:40:41Z" build_hash: 37f4ba2b5a121a8786bc516e9ec4aa0b8b590c7d go_version: go1.21.6 version: v0.33.0-1-g37f4ba2 diff --git a/pkg/resource/function/hooks.go b/pkg/resource/function/hooks.go index a5dd5ead..5ce407fd 100644 --- a/pkg/resource/function/hooks.go +++ b/pkg/resource/function/hooks.go @@ -162,6 +162,15 @@ func (rm *resourceManager) updateFunctionConfiguration( FunctionName: aws.String(*dspec.Name), } + if delta.DifferentAt("Spec.DeadLetterConfig") { + deadLetterConfig := &svcsdk.DeadLetterConfig{} + if dspec.DeadLetterConfig != nil { + deadLetterConfigCopy := dspec.DeadLetterConfig.DeepCopy() + deadLetterConfig.TargetArn = deadLetterConfigCopy.TargetARN + } + input.DeadLetterConfig = deadLetterConfig + } + if delta.DifferentAt("Spec.Description") { if dspec.Description != nil { input.Description = aws.String(*dspec.Description) diff --git a/test/e2e/resources/function_features.yaml b/test/e2e/resources/function_features.yaml new file mode 100644 index 00000000..68f46e44 --- /dev/null +++ b/test/e2e/resources/function_features.yaml @@ -0,0 +1,17 @@ +apiVersion: lambda.services.k8s.aws/v1alpha1 +kind: Function +metadata: + name: $FUNCTION_NAME + annotations: + services.k8s.aws/region: $AWS_REGION +spec: + name: $FUNCTION_NAME + code: + s3Bucket: $BUCKET_NAME + s3Key: $LAMBDA_FILE_NAME + role: $LAMBDA_ROLE + runtime: python3.9 + handler: main + deadLetterConfig: + targetARN: $DEAD_LETTER_CONFIG_TARGET_ARN + description: function created by ACK lambda-controller e2e tests \ No newline at end of file diff --git a/test/e2e/tests/test_function.py b/test/e2e/tests/test_function.py index 58f4fc13..1e9aba7c 100644 --- a/test/e2e/tests/test_function.py +++ b/test/e2e/tests/test_function.py @@ -604,6 +604,67 @@ def test_function_architecture(self, lambda_client): # Check Lambda function doesn't exist assert not lambda_validator.function_exists(resource_name) + def test_function_features(self, lambda_client): + resource_name = random_suffix_name("functionfeatures", 24) + + resources = get_bootstrap_resources() + logging.debug(resources) + + replacements = REPLACEMENT_VALUES.copy() + replacements["FUNCTION_NAME"] = resource_name + replacements["BUCKET_NAME"] = resources.FunctionsBucket.name + replacements["LAMBDA_ROLE"] = resources.EICRole.arn + replacements["LAMBDA_FILE_NAME"] = LAMBDA_FUNCTION_FILE_ZIP + replacements["AWS_REGION"] = get_region() + replacements["DEAD_LETTER_CONFIG_TARGET_ARN"] = resources.EICQueueOnSuccess.arn + + # Load Lambda CR + resource_data = load_lambda_resource( + "function_features", + 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 Lambda function exists + assert lambda_validator.function_exists(resource_name) + + # Update cr + cr["spec"]["deadLetterConfig"]["targetARN"] = resources.EICQueueOnFailure.arn + + #Patch k8s resource + k8s.patch_custom_resource(ref, cr) + time.sleep(UPDATE_WAIT_AFTER_SECONDS) + + #Check function_snapstart update fields + function = lambda_validator.get_function(resource_name) + assert function["Configuration"]["DeadLetterConfig"]["TargetArn"] == resources.EICQueueOnFailure.arn + + # Delete k8s resource + _, deleted = k8s.delete_custom_resource(ref) + assert deleted is True + + time.sleep(DELETE_WAIT_AFTER_SECONDS) + + # Check Lambda function doesn't exist + assert not lambda_validator.function_exists(resource_name) + def test_function_event_invoke_config(self, lambda_client): resource_name = random_suffix_name("lambda-function", 24)