Skip to content

Commit e917f81

Browse files
authored
Keep the desired code.s3* fields part of the spec (#43)
Fixes aws-controllers-k8s/community#1402 The AWS Lambda API doesn't return the original submitted `s3Bucket`, `s3Key`, and `s3ObjectVersion` when a function is successfully created. Instead, it returns different values (In `Getfunction` call) in a different response field (`Code.Location`). This is causing the generated code in ACK to set the `spec.Code.s3*` fields to nil values. To keep the experience in ACK lambda-controller consistent in the Kubernetes-land, we must keep the original submitted `code.S3*` fields part of the function's spec. This patch removes the part that is setting the `spec.Code.s3*` to nil and allows the controllers to keep the original values part of the spec. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license. Signed-off-by: Amine Hilaly <[email protected]>
1 parent e6a6840 commit e917f81

File tree

6 files changed

+31
-11
lines changed

6 files changed

+31
-11
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
ack_generate_info:
2-
build_date: "2022-08-14T02:48:40Z"
2+
build_date: "2022-08-11T19:32:42Z"
33
build_hash: 87477ae8ca8ac6ddb8c565bbd910cc7e30f55ed0
44
go_version: go1.18.1
55
version: v0.19.3
66
api_directory_checksum: 3c3c74f14b359bf55495aabc720fddbe21254966
77
api_version: v1alpha1
88
aws_sdk_go_version: v1.44.60
99
generator_config_info:
10-
file_checksum: 9e2e36e894eb563184f2e40efe8198ec65c3c387
10+
file_checksum: 6eb0aca0b19db6cf5fcb510de34fc3a7f5a74cac
1111
original_file_name: generator.yaml
1212
last_modification:
1313
reason: API generation

apis/v1alpha1/generator.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ resources:
1818
Code:
1919
compare:
2020
is_ignored: true
21+
set:
22+
- ignore: true
23+
operation: ReadOne
2124
Layers:
2225
set:
2326
- method: Create

generator.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ resources:
1818
Code:
1919
compare:
2020
is_ignored: true
21+
set:
22+
- ignore: true
23+
operation: ReadOne
2124
Layers:
2225
set:
2326
- method: Create

pkg/resource/function/sdk.go

Lines changed: 10 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

templates/hooks/function/sdk_read_one_post_set_output.go.tpl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
if resp.Code != nil {
2+
// We need to keep the desired .Code s3Bucket s3Key and s3ObjectVersion
3+
// part of the function's spec. So instead of setting Spec.Code to nil
4+
// we only set ImageURI
5+
if resp.Code.ImageUri != nil {
6+
ko.Spec.Code.ImageURI = resp.Code.ImageUri
7+
}
8+
}
19
if resp.Configuration.CodeSha256 != nil {
210
ko.Status.CodeSHA256 = resp.Configuration.CodeSha256
311
} else {

test/e2e/tests/test_function.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ def test_smoke(self, lambda_client):
120120

121121
lambda_validator = LambdaValidator(lambda_client)
122122

123+
# Assert that the original code.s3Bucket and code.s3Key is still part of
124+
# the function's CR
125+
assert cr["spec"]["code"]["s3Bucket"] == resources.FunctionsBucket.name
126+
assert cr["spec"]["code"]["s3Key"] == LAMBDA_FUNCTION_FILE_ZIP
127+
123128
# Check Lambda function exists
124129
assert lambda_validator.function_exists(resource_name)
125130

0 commit comments

Comments
 (0)