Skip to content

Update support for Runtime field #139

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions pkg/resource/function/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,14 @@ func (rm *resourceManager) updateFunctionConfiguration(
}
}

if delta.DifferentAt("Spec.Runtime") {
if dspec.Runtime != nil {
input.Runtime = aws.String(*dspec.Runtime)
} else {
input.Runtime = aws.String("")
}
}

if delta.DifferentAt(("Spec.SnapStart")) {
snapStart := &svcsdk.SnapStart{}
if dspec.SnapStart != nil {
Expand Down
62 changes: 62 additions & 0 deletions test/e2e/tests/test_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,68 @@ def test_function_features(self, lambda_client):
# Check Lambda function doesn't exist
assert not lambda_validator.function_exists(resource_name)

def test_function_runtime(self, lambda_client):
resource_name = random_suffix_name("function", 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.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()

# Load Lambda CR
resource_data = load_lambda_resource(
"function",
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"]["runtime"] = "java21"

#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"]["Runtime"] == "java21"

# 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_layers(self, lambda_client):
resource_name = random_suffix_name("functionlayers", 24)

Expand Down