Skip to content

fix: Update support for DeadLetterConfig #134

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
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
2 changes: 1 addition & 1 deletion apis/v1alpha1/ack-generate-metadata.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ack_generate_info:
build_date: "2024-04-16T16:52:09Z"
build_date: "2024-04-16T23:40:41Z"
build_hash: 37f4ba2b5a121a8786bc516e9ec4aa0b8b590c7d
go_version: go1.21.6
version: v0.33.0-1-g37f4ba2
Expand Down
9 changes: 9 additions & 0 deletions pkg/resource/function/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,15 @@ func (rm *resourceManager) updateFunctionConfiguration(
FunctionName: aws.String(*dspec.Name),
}

if delta.DifferentAt("Spec.DeadLetterConfig") {
deadLetterConfig := &svcsdk.DeadLetterConfig{}
if dspec.DeadLetterConfig != nil {
deadLetterConfigCopy := dspec.DeadLetterConfig.DeepCopy()
deadLetterConfig.TargetArn = deadLetterConfigCopy.TargetARN
}
input.DeadLetterConfig = deadLetterConfig
}

if delta.DifferentAt("Spec.Description") {
if dspec.Description != nil {
input.Description = aws.String(*dspec.Description)
Expand Down
17 changes: 17 additions & 0 deletions test/e2e/resources/function_features.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: lambda.services.k8s.aws/v1alpha1
kind: Function
metadata:
name: $FUNCTION_NAME
annotations:
services.k8s.aws/region: $AWS_REGION
spec:
name: $FUNCTION_NAME
code:
s3Bucket: $BUCKET_NAME
s3Key: $LAMBDA_FILE_NAME
role: $LAMBDA_ROLE
runtime: python3.9
handler: main
deadLetterConfig:
targetARN: $DEAD_LETTER_CONFIG_TARGET_ARN
description: function created by ACK lambda-controller e2e tests
61 changes: 61 additions & 0 deletions test/e2e/tests/test_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,67 @@ def test_function_architecture(self, lambda_client):
# Check Lambda function doesn't exist
assert not lambda_validator.function_exists(resource_name)

def test_function_features(self, lambda_client):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is failing with this error message:

 2024-04-01T22:47:58.673Z	DEBUG	ackrt	<< r.createResource	{"kind": "Function", "namespace": "default", "name": "functionfeatures-6ihswvx", "account": "566350749442", "role": "", "region": "us-west-2", "is_adopted": false, "generation": 1, "error": "InvalidParameterValueException: The provided execution role does not have permissions to call SendMessage on SQS\n{\n  RespMetadata: {\n    StatusCode: 400,\n    RequestID: \"ee5cd503-5f8a-4c66-a8e5-88473a1fb18a\"\n  },\n  Message_: \"The provided execution role does not have permissions to call SendMessage on SQS\",\n  Type: \"User\"\n}"} 

It looks like we need to add more permissions to Role we create during the bootstrap. Maybe we can introduce a new role for DLQ

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing out the error, I have used another Role now. This role will give permission to access SQS.

resource_name = random_suffix_name("functionfeatures", 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.EICRole.arn
replacements["LAMBDA_FILE_NAME"] = LAMBDA_FUNCTION_FILE_ZIP
replacements["AWS_REGION"] = get_region()
replacements["DEAD_LETTER_CONFIG_TARGET_ARN"] = resources.EICQueueOnSuccess.arn

# Load Lambda CR
resource_data = load_lambda_resource(
"function_features",
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"]["deadLetterConfig"]["targetARN"] = resources.EICQueueOnFailure.arn

#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"]["DeadLetterConfig"]["TargetArn"] == resources.EICQueueOnFailure.arn

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

Expand Down