diff --git a/apis/v1alpha1/ack-generate-metadata.yaml b/apis/v1alpha1/ack-generate-metadata.yaml index ea732a1..723d903 100755 --- a/apis/v1alpha1/ack-generate-metadata.yaml +++ b/apis/v1alpha1/ack-generate-metadata.yaml @@ -1,9 +1,9 @@ ack_generate_info: - build_date: "2024-04-08T23:27:24Z" + build_date: "2024-04-09T20:12:55Z" build_hash: 37f4ba2b5a121a8786bc516e9ec4aa0b8b590c7d go_version: go1.21.6 version: v0.33.0-1-g37f4ba2 -api_directory_checksum: 33a9d13c7343aec5c9acdc6e18fd2494f2af2e88 +api_directory_checksum: 93229b2f11a89ef43fc0ef07ea1beb425e9aaf17 api_version: v1alpha1 aws_sdk_go_version: v1.44.181 generator_config_info: diff --git a/test/e2e/tests/test_function.py b/test/e2e/tests/test_function.py index 077cd77..d76f823 100644 --- a/test/e2e/tests/test_function.py +++ b/test/e2e/tests/test_function.py @@ -681,5 +681,87 @@ def test_function_event_invoke_config(self, lambda_client): time.sleep(DELETE_WAIT_AFTER_SECONDS) + # Check Lambda function doesn't exist + assert not lambda_validator.function_exists(resource_name) + + def test_function_code_s3(self, lambda_client): + resource_name = random_suffix_name("functioncodes3", 24) + + resources = get_bootstrap_resources() + logging.debug(resources) + + archive_1 = open(LAMBDA_FUNCTION_FILE_PATH_ZIP, 'rb') + readFile_1 = archive_1.read() + hash_1 = hashlib.sha256(readFile_1) + binary_hash_1 = hash_1.digest() + base64_hash_1 = base64.b64encode(binary_hash_1).decode('utf-8') + + archive_2 = open(LAMBDA_FUNCTION_UPDATED_FILE_PATH_ZIP, 'rb') + readFile_2 = archive_2.read() + hash_2 = hashlib.sha256(readFile_2) + binary_hash_2 = hash_2.digest() + base64_hash_2 = base64.b64encode(binary_hash_2).decode('utf-8') + + replacements = REPLACEMENT_VALUES.copy() + replacements["FUNCTION_NAME"] = resource_name + replacements["BUCKET_NAME"] = resources.FunctionsBucket.name + replacements["LAMBDA_ROLE"] = resources.BasicRole.arn + replacements["LAMBDA_FILE_NAME"] = LAMBDA_FUNCTION_FILE_ZIP + replacements["RESERVED_CONCURRENT_EXECUTIONS"] = "0" + replacements["CODE_SIGNING_CONFIG_ARN"] = "" + replacements["AWS_REGION"] = get_region() + replacements["HASH"] = base64_hash_1 + + # Load Lambda CR + resource_data = load_lambda_resource( + "function_code_s3", + 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) + + # Assert that the original code.s3Bucket and code.s3Key is still part of + # the function's CR + assert cr["spec"]["code"]["s3Bucket"] == resources.FunctionsBucket.name + assert cr["spec"]["code"]["s3Key"] == LAMBDA_FUNCTION_FILE_ZIP + + # Check Lambda function exists + assert lambda_validator.function_exists(resource_name) + + # Update cr + cr["spec"]["code"]["sha256"] = base64_hash_2 + cr["spec"]["code"]["s3Key"] = LAMBDA_FUNCTION_UPDATED_FILE_ZIP + + # Patch k8s resource + k8s.patch_custom_resource(ref, cr) + time.sleep(UPDATE_WAIT_AFTER_SECONDS) + + # Check function updated fields + function = lambda_validator.get_function(resource_name) + assert function is not None + assert function["Configuration"]["CodeSha256"] == base64_hash_2 + + # 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) \ No newline at end of file