-
Notifications
You must be signed in to change notification settings - Fork 23
fix: Update support for Layers
#136
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,4 @@ | ||
if resp.Code != nil { | ||
// We need to keep the desired .Code s3Bucket s3Key and s3ObjectVersion | ||
// part of the function's spec. So instead of setting Spec.Code to nil | ||
// we only set ImageURI | ||
// | ||
// When adopting a Function resource, Spec.Code field should be manually | ||
// initialised before injecting ImageURI. | ||
if ko.Spec.Code == nil { | ||
ko.Spec.Code = &svcapitypes.FunctionCode{} | ||
} | ||
|
@@ -13,7 +7,8 @@ | |
} | ||
} | ||
if resp.Configuration.Layers != nil { | ||
f16 := []*svcapitypes.Layer{} | ||
f17 := []*svcapitypes.Layer{} | ||
layer := []*string{} | ||
for _, f16iter := range resp.Configuration.Layers { | ||
f16elem := &svcapitypes.Layer{} | ||
if f16iter.Arn != nil { | ||
|
@@ -29,7 +24,9 @@ | |
f16elem.SigningProfileVersionARN = f16iter.SigningProfileVersionArn | ||
} | ||
f16 = append(f16, f16elem) | ||
layer = append(layer, f16iter.Arn) | ||
} | ||
ko.Spec.Layers = layer | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we have some smoke tests around layers updates? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
ko.Status.LayerStatuses = f16 | ||
} else { | ||
ko.Status.LayerStatuses = nil | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
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 | ||
layers: [$LAYERS] | ||
description: function created by ACK lambda-controller e2e tests |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -664,6 +664,69 @@ def test_function_features(self, lambda_client): | |
|
||
# 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) | ||
|
||
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["LAYERS"] = "arn:aws:lambda:us-west-2:336392948345:layer:AWSSDKPandas-Python310:14" | ||
|
||
# Load Lambda CR | ||
resource_data = load_lambda_resource( | ||
"function_layers", | ||
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 | ||
layers_list = ["arn:aws:lambda:us-west-2:017000801446:layer:AWSLambdaPowertoolsPythonV2:68", "arn:aws:lambda:us-west-2:580247275435:layer:LambdaInsightsExtension:52"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. qq: I guess those are official layers that anybody can reference? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, those are from the list of layers provided by AWS. |
||
cr["spec"]["layers"] = layers_list | ||
|
||
#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) | ||
for i in range(len(function["Configuration"]["Layers"])) : | ||
assert function["Configuration"]["Layers"][i]["Arn"] == layers_list[i] | ||
|
||
# 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) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @Vandita2020 ! How are environement/ephemeralStorage/FileSystemConfigs/Timeouts affecting to layers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, I have just rearranged them according to the order in the API. Please ignore them, no changes for them.