|
21 | 21 | from typing import Dict, Tuple
|
22 | 22 |
|
23 | 23 | from acktest.resources import random_suffix_name
|
24 |
| -from acktest.aws.identity import get_region |
| 24 | +from acktest.aws.identity import get_region, get_account_id |
25 | 25 | from acktest.k8s import resource as k8s
|
26 | 26 | from e2e import service_marker, CRD_GROUP, CRD_VERSION, load_lambda_resource
|
27 | 27 | from e2e.replacement_values import REPLACEMENT_VALUES
|
|
33 | 33 | UPDATE_WAIT_AFTER_SECONDS = 25
|
34 | 34 | DELETE_WAIT_AFTER_SECONDS = 25
|
35 | 35 |
|
| 36 | + |
| 37 | +def get_testing_image_url(): |
| 38 | + aws_region = get_region() |
| 39 | + account_id = get_account_id() |
| 40 | + return f"{account_id}.dkr.ecr.{aws_region}.amazonaws.com/ack-e2e-testing-lambda-controller:v1" |
| 41 | + |
36 | 42 | @pytest.fixture(scope="module")
|
37 | 43 | def lambda_client():
|
38 | 44 | return boto3.client("lambda")
|
@@ -313,3 +319,50 @@ def test_function_code_signing_config(self, lambda_client, code_signing_config):
|
313 | 319 | # Check Lambda function doesn't exist
|
314 | 320 | exists = self.function_exists(lambda_client, resource_name)
|
315 | 321 | assert not exists
|
| 322 | + |
| 323 | + def test_function_package_type_image(self, lambda_client, code_signing_config): |
| 324 | + resource_name = random_suffix_name("lambda-function", 24) |
| 325 | + |
| 326 | + resources = get_bootstrap_resources() |
| 327 | + |
| 328 | + replacements = REPLACEMENT_VALUES.copy() |
| 329 | + replacements["FUNCTION_NAME"] = resource_name |
| 330 | + replacements["LAMBDA_ROLE"] = resources.LambdaBasicRoleARN |
| 331 | + replacements["AWS_REGION"] = get_region() |
| 332 | + replacements["IMAGE_URL"] = get_testing_image_url() |
| 333 | + |
| 334 | + # Load Lambda CR |
| 335 | + resource_data = load_lambda_resource( |
| 336 | + "function_package_type_image", |
| 337 | + additional_replacements=replacements, |
| 338 | + ) |
| 339 | + logging.debug(resource_data) |
| 340 | + |
| 341 | + # Create k8s resource |
| 342 | + ref = k8s.CustomResourceReference( |
| 343 | + CRD_GROUP, CRD_VERSION, RESOURCE_PLURAL, |
| 344 | + resource_name, namespace="default", |
| 345 | + ) |
| 346 | + k8s.create_custom_resource(ref, resource_data) |
| 347 | + cr = k8s.wait_resource_consumed_by_controller(ref) |
| 348 | + |
| 349 | + assert cr is not None |
| 350 | + assert k8s.get_resource_exists(ref) |
| 351 | + |
| 352 | + time.sleep(CREATE_WAIT_AFTER_SECONDS) |
| 353 | + |
| 354 | + cr = k8s.wait_resource_consumed_by_controller(ref) |
| 355 | + |
| 356 | + # Check Lambda function exists |
| 357 | + exists = self.function_exists(lambda_client, resource_name) |
| 358 | + assert exists |
| 359 | + |
| 360 | + # Delete k8s resource |
| 361 | + _, deleted = k8s.delete_custom_resource(ref) |
| 362 | + assert deleted is True |
| 363 | + |
| 364 | + time.sleep(DELETE_WAIT_AFTER_SECONDS) |
| 365 | + |
| 366 | + # Check Lambda function doesn't exist |
| 367 | + exists = self.function_exists(lambda_client, resource_name) |
| 368 | + assert not exists |
0 commit comments