|
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,112 @@ 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 |
| 369 | + |
| 370 | + def test_function_package_type_image_with_signing_config(self, lambda_client, code_signing_config): |
| 371 | + resource_name = random_suffix_name("lambda-function", 24) |
| 372 | + |
| 373 | + resources = get_bootstrap_resources() |
| 374 | + |
| 375 | + replacements = REPLACEMENT_VALUES.copy() |
| 376 | + replacements["FUNCTION_NAME"] = resource_name |
| 377 | + replacements["LAMBDA_ROLE"] = resources.LambdaBasicRoleARN |
| 378 | + replacements["AWS_REGION"] = get_region() |
| 379 | + replacements["IMAGE_URL"] = get_testing_image_url() |
| 380 | + |
| 381 | + # Load Lambda CR |
| 382 | + resource_data = load_lambda_resource( |
| 383 | + "function_package_type_image", |
| 384 | + additional_replacements=replacements, |
| 385 | + ) |
| 386 | + logging.debug(resource_data) |
| 387 | + |
| 388 | + # Create k8s resource |
| 389 | + ref = k8s.CustomResourceReference( |
| 390 | + CRD_GROUP, CRD_VERSION, RESOURCE_PLURAL, |
| 391 | + resource_name, namespace="default", |
| 392 | + ) |
| 393 | + k8s.create_custom_resource(ref, resource_data) |
| 394 | + cr = k8s.wait_resource_consumed_by_controller(ref) |
| 395 | + |
| 396 | + assert cr is not None |
| 397 | + assert k8s.get_resource_exists(ref) |
| 398 | + |
| 399 | + time.sleep(CREATE_WAIT_AFTER_SECONDS) |
| 400 | + |
| 401 | + cr = k8s.wait_resource_consumed_by_controller(ref) |
| 402 | + |
| 403 | + # Check Lambda function exists |
| 404 | + exists = self.function_exists(lambda_client, resource_name) |
| 405 | + assert exists |
| 406 | + |
| 407 | + # Add signing configuration |
| 408 | + cr["spec"]["codeSigningConfigARN"] = "random-csc" |
| 409 | + k8s.patch_custom_resource(ref, cr) |
| 410 | + |
| 411 | + time.sleep(UPDATE_WAIT_AFTER_SECONDS) |
| 412 | + |
| 413 | + cr = k8s.wait_resource_consumed_by_controller(ref) |
| 414 | + # assert condition |
| 415 | + assert k8s.assert_condition_state_message( |
| 416 | + ref, |
| 417 | + "ACK.Terminal", |
| 418 | + "True", |
| 419 | + "Cannot set function code signing config when package type is Image", |
| 420 | + ) |
| 421 | + |
| 422 | + # Delete k8s resource |
| 423 | + _, deleted = k8s.delete_custom_resource(ref) |
| 424 | + assert deleted is True |
| 425 | + |
| 426 | + time.sleep(DELETE_WAIT_AFTER_SECONDS) |
| 427 | + |
| 428 | + # Check Lambda function doesn't exist |
| 429 | + exists = self.function_exists(lambda_client, resource_name) |
| 430 | + assert not exists |
0 commit comments