Skip to content

Commit 2653248

Browse files
authored
Update support for Runtime field (#139)
**Description:** This PR adds the missing update feature for `Runtime` field in Function resource. **Acknowledgement:** By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent cfbd77b commit 2653248

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

pkg/resource/function/hooks.go

+8
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,14 @@ func (rm *resourceManager) updateFunctionConfiguration(
267267
}
268268
}
269269

270+
if delta.DifferentAt("Spec.Runtime") {
271+
if dspec.Runtime != nil {
272+
input.Runtime = aws.String(*dspec.Runtime)
273+
} else {
274+
input.Runtime = aws.String("")
275+
}
276+
}
277+
270278
if delta.DifferentAt(("Spec.SnapStart")) {
271279
snapStart := &svcsdk.SnapStart{}
272280
if dspec.SnapStart != nil {

test/e2e/tests/test_function.py

+62
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,68 @@ def test_function_features(self, lambda_client):
665665
# Check Lambda function doesn't exist
666666
assert not lambda_validator.function_exists(resource_name)
667667

668+
def test_function_runtime(self, lambda_client):
669+
resource_name = random_suffix_name("function", 24)
670+
671+
resources = get_bootstrap_resources()
672+
logging.debug(resources)
673+
674+
replacements = REPLACEMENT_VALUES.copy()
675+
replacements["FUNCTION_NAME"] = resource_name
676+
replacements["BUCKET_NAME"] = resources.FunctionsBucket.name
677+
replacements["LAMBDA_ROLE"] = resources.BasicRole.arn
678+
replacements["LAMBDA_FILE_NAME"] = LAMBDA_FUNCTION_FILE_ZIP
679+
replacements["RESERVED_CONCURRENT_EXECUTIONS"] = "0"
680+
replacements["CODE_SIGNING_CONFIG_ARN"] = ""
681+
replacements["AWS_REGION"] = get_region()
682+
683+
# Load Lambda CR
684+
resource_data = load_lambda_resource(
685+
"function",
686+
additional_replacements=replacements,
687+
)
688+
logging.debug(resource_data)
689+
690+
# Create k8s resource
691+
ref = k8s.CustomResourceReference(
692+
CRD_GROUP, CRD_VERSION, RESOURCE_PLURAL,
693+
resource_name, namespace="default",
694+
)
695+
k8s.create_custom_resource(ref, resource_data)
696+
cr = k8s.wait_resource_consumed_by_controller(ref)
697+
698+
assert cr is not None
699+
assert k8s.get_resource_exists(ref)
700+
701+
time.sleep(CREATE_WAIT_AFTER_SECONDS)
702+
703+
cr = k8s.wait_resource_consumed_by_controller(ref)
704+
705+
lambda_validator = LambdaValidator(lambda_client)
706+
707+
# Check Lambda function exists
708+
assert lambda_validator.function_exists(resource_name)
709+
710+
# Update cr
711+
cr["spec"]["runtime"] = "java21"
712+
713+
#Patch k8s resource
714+
k8s.patch_custom_resource(ref, cr)
715+
time.sleep(UPDATE_WAIT_AFTER_SECONDS)
716+
717+
#Check function_snapstart update fields
718+
function = lambda_validator.get_function(resource_name)
719+
assert function["Configuration"]["Runtime"] == "java21"
720+
721+
# Delete k8s resource
722+
_, deleted = k8s.delete_custom_resource(ref)
723+
assert deleted is True
724+
725+
time.sleep(DELETE_WAIT_AFTER_SECONDS)
726+
727+
# Check Lambda function doesn't exist
728+
assert not lambda_validator.function_exists(resource_name)
729+
668730
def test_function_layers(self, lambda_client):
669731
resource_name = random_suffix_name("functionlayers", 24)
670732

0 commit comments

Comments
 (0)