Skip to content

Commit 4cb0e48

Browse files
committed
Adding code and e2e tests for Code.S3 update feature
1 parent ffbfe9d commit 4cb0e48

12 files changed

+100
-49
lines changed

ada.log

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"_aws" : {"Timestamp":1679602549000,"CloudWatchMetrics":[{"Namespace":"toolbox-ada","Dimensions":[[],["Platform"],["Channel"],["Command"],["Version"],["Platform","Channel"],["Command","Channel"],["Version","Channel"],["ToolName","SubCommand"]],"Metrics":[{"Name":"Success","Unit":"Count"}]}]},"Success" : 1,"Channel" : "bh","Command" : "ada","Version" : "1.0.200834.0","ToolName" : "","SubCommand" : "update","Platform" : "macOS-arm64","Os" : "osx","Platform" : "macOS-arm64","Command" : "ada","Arch" : "arm64","InvocationId" : "1-641cb375-6bb70feea00eddd91d20ee29","User" : "vanditap","Channel" : "bh","Hostname" : "b0f1d82295be.ant.amazon.com","Version" : "1.0.200834.0"}
+5-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
ack_generate_info:
2-
build_date: "2023-01-31T23:16:05Z"
3-
build_hash: c3fefc1cc5cb030c5e893027ba1195d747889aca
2+
build_date: "2023-03-23T21:33:23Z"
3+
build_hash: 0888419ec6825035cae1fdee2ceffd7c1ac73ca8
44
go_version: go1.19
5-
version: v0.23.0
6-
api_directory_checksum: a9fcef68210dd72b4b2e37052f2c1a9e971326c6
5+
version: v0.20.1-65-g0888419
6+
api_directory_checksum: c76f3eae97fba6266f0598168b20c6565f20cac0
77
api_version: v1alpha1
88
aws_sdk_go_version: v1.44.181
99
generator_config_info:
10-
file_checksum: e007d88ecf6ad1c45cb6451f5fda9401af9d7305
10+
file_checksum: 8dd1f312a8698d733fe429a7968be2d688cab75d
1111
original_file_name: generator.yaml
1212
last_modification:
1313
reason: API generation

apis/v1alpha1/function.go

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/v1alpha1/generator.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ resources:
1919
- path: Status.State
2020
in: [ "Active" ]
2121
fields:
22+
CodeS3SHA256:
23+
type: String
24+
is_required: true
2225
Code.S3Bucket:
2326
references:
2427
resource: Bucket

apis/v1alpha1/zz_generated.deepcopy.go

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/lambda.services.k8s.aws_functions.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ spec:
6969
format: byte
7070
type: string
7171
type: object
72+
codeS3SHA256:
73+
type: string
7274
codeSigningConfigARN:
7375
description: To enable code signing for this function, specify the
7476
ARN of a code-signing configuration. A code-signing configuration
@@ -279,6 +281,7 @@ spec:
279281
type: object
280282
required:
281283
- code
284+
- codeS3SHA256
282285
- name
283286
- role
284287
type: object

generator.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ resources:
1919
- path: Status.State
2020
in: [ "Active" ]
2121
fields:
22+
CodeS3SHA256:
23+
type: String
24+
is_required: true
2225
Code.S3Bucket:
2326
references:
2427
resource: Bucket

helm/crds/lambda.services.k8s.aws_functions.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ spec:
6969
format: byte
7070
type: string
7171
type: object
72+
codeS3SHA256:
73+
type: string
7274
codeSigningConfigARN:
7375
description: To enable code signing for this function, specify the
7476
ARN of a code-signing configuration. A code-signing configuration
@@ -279,6 +281,7 @@ spec:
279281
type: object
280282
required:
281283
- code
284+
- codeS3SHA256
282285
- name
283286
- role
284287
type: object

pkg/resource/function/delta.go

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/resource/function/hooks.go

+54-34
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ package function
1515

1616
import (
1717
"context"
18+
"encoding/json"
1819
"errors"
20+
"fmt"
1921
"time"
2022

2123
ackcompare "github.com/aws-controllers-k8s/runtime/pkg/compare"
@@ -95,8 +97,14 @@ func (rm *resourceManager) customUpdateFunction(
9597
// not correct to sequentially call UpdateFunctionConfiguration and
9698
// UpdateFunctionCode because both of them can put the function in a
9799
// Pending state.
100+
bytes, _ := json.Marshal(desired.ko.Spec.CodeS3SHA256)
101+
fmt.Println("Desired is:", string(bytes))
102+
103+
bytes1, _ := json.Marshal(latest.ko.Spec.CodeS3SHA256)
104+
fmt.Println("Latest is:", string(bytes1))
105+
98106
switch {
99-
case delta.DifferentAt("Spec.Code"):
107+
case delta.DifferentAt("Spec.Code") || delta.DifferentAt("Spec.CodeS3SHA256"):
100108
err = rm.updateFunctionCode(ctx, desired, delta)
101109
if err != nil {
102110
return nil, err
@@ -335,30 +343,22 @@ func (rm *resourceManager) updateFunctionCode(
335343
exit := rlog.Trace("rm.updateFunctionCode")
336344
defer exit(err)
337345

338-
if delta.DifferentAt("Spec.Code.S3Key") &&
339-
!delta.DifferentAt("Spec.Code.S3Bucket") &&
340-
!delta.DifferentAt("Spec.Code.S3ObjectVersion") &&
341-
!delta.DifferentAt("Spec.Code.ImageURI") {
342-
log := ackrtlog.FromContext(ctx)
343-
log.Info("updating code.s3Key field is not currently supported.")
344-
return nil
345-
}
346-
347346
dspec := desired.ko.Spec
348347
input := &svcsdk.UpdateFunctionCodeInput{
349348
FunctionName: aws.String(*dspec.Name),
350349
}
351350

352-
if dspec.Code != nil {
353-
switch {
354-
case dspec.Code.ImageURI != nil:
355-
input.ImageUri = dspec.Code.ImageURI
356-
case dspec.Code.S3Bucket != nil,
357-
dspec.Code.S3Key != nil,
358-
dspec.Code.S3ObjectVersion != nil:
359-
input.S3Bucket = dspec.Code.S3Bucket
360-
input.S3Key = dspec.Code.S3Key
361-
input.S3ObjectVersion = dspec.Code.S3ObjectVersion
351+
if delta.DifferentAt("Spec.ImageURI") {
352+
input.ImageUri = dspec.Code.ImageURI
353+
} else if delta.DifferentAt("Spec.CodeS3SHA256") {
354+
if dspec.Code.S3Key != nil {
355+
input.S3Key = aws.String(*dspec.Code.S3Key)
356+
}
357+
if dspec.Code.S3Bucket != nil {
358+
input.S3Bucket = aws.String(*dspec.Code.S3Bucket)
359+
}
360+
if dspec.Code.S3ObjectVersion != nil {
361+
input.S3ObjectVersion = aws.String(*dspec.Code.S3ObjectVersion)
362362
}
363363
}
364364

@@ -416,6 +416,26 @@ func customPreCompare(
416416
delta.Add("Spec.Code.ImageURI", a.ko.Spec.Code.ImageURI, b.ko.Spec.Code.ImageURI)
417417
}
418418
}
419+
420+
expected, _ := json.Marshal(a.ko.Spec.CodeS3SHA256)
421+
fmt.Println("expected:", string(expected))
422+
423+
actual, _ := json.Marshal(b.ko.Status.CodeSHA256)
424+
fmt.Println("actual:", string(actual))
425+
426+
if *b.ko.Status.CodeSHA256 != "" || *a.ko.Spec.CodeS3SHA256 != "" {
427+
if *b.ko.Status.CodeSHA256 != *a.ko.Spec.CodeS3SHA256 {
428+
delta.Add("Spec.CodeS3SHA256", a.ko.Spec.CodeS3SHA256, b.ko.Status.CodeSHA256)
429+
}
430+
}
431+
432+
// if ackcompare.HasNilDifference(a.ko.Spec.CodeS3SHA256, b.ko.Spec.CodeS3SHA256) {
433+
// delta.Add("Spec.CodeS3SHA256", a.ko.Spec.CodeS3SHA256, b.ko.Spec.CodeS3SHA256)
434+
// } else if a.ko.Spec.CodeS3SHA256 != nil && b.ko.Spec.CodeS3SHA256 != nil {
435+
// if *a.ko.Spec.CodeS3SHA256 != *b.ko.Spec.CodeS3SHA256 {
436+
// delta.Add("Spec.CodeS3SHA256", a.ko.Spec.CodeS3SHA256, b.ko.Spec.CodeS3SHA256)
437+
// }
438+
// }
419439
//TODO(hialylmh) handle Spec.Code.S3bucket changes
420440
// if ackcompare.HasNilDifference(a.ko.Spec.Code.S3Bucket, b.ko.Spec.Code.S3Bucket) {
421441
// delta.Add("Spec.Code.S3Bucket", a.ko.Spec.Code.S3Bucket, b.ko.Spec.Code.S3Bucket)
@@ -424,20 +444,20 @@ func customPreCompare(
424444
// delta.Add("Spec.Code.S3Bucket", a.ko.Spec.Code.S3Bucket, b.ko.Spec.Code.S3Bucket)
425445
// }
426446
// }
427-
if ackcompare.HasNilDifference(a.ko.Spec.Code.S3Key, b.ko.Spec.Code.S3Key) {
428-
delta.Add("Spec.Code.S3Key", a.ko.Spec.Code.S3Key, b.ko.Spec.Code.S3Key)
429-
} else if a.ko.Spec.Code.S3Key != nil && b.ko.Spec.Code.S3Key != nil {
430-
if *a.ko.Spec.Code.S3Key != *b.ko.Spec.Code.S3Key {
431-
delta.Add("Spec.Code.S3Key", a.ko.Spec.Code.S3Key, b.ko.Spec.Code.S3Key)
432-
}
433-
}
434-
if ackcompare.HasNilDifference(a.ko.Spec.Code.S3ObjectVersion, b.ko.Spec.Code.S3ObjectVersion) {
435-
delta.Add("Spec.Code.S3ObjectVersion", a.ko.Spec.Code.S3ObjectVersion, b.ko.Spec.Code.S3ObjectVersion)
436-
} else if a.ko.Spec.Code.S3ObjectVersion != nil && b.ko.Spec.Code.S3ObjectVersion != nil {
437-
if *a.ko.Spec.Code.S3ObjectVersion != *b.ko.Spec.Code.S3ObjectVersion {
438-
delta.Add("Spec.Code.S3ObjectVersion", a.ko.Spec.Code.S3ObjectVersion, b.ko.Spec.Code.S3ObjectVersion)
439-
}
440-
}
447+
// if ackcompare.HasNilDifference(a.ko.Spec.Code.S3Key, b.ko.Spec.Code.S3Key) {
448+
// delta.Add("Spec.Code.S3Key", a.ko.Spec.Code.S3Key, b.ko.Spec.Code.S3Key)
449+
// } else if a.ko.Spec.Code.S3Key != nil && b.ko.Spec.Code.S3Key != nil {
450+
// if *a.ko.Spec.Code.S3Key != *b.ko.Spec.Code.S3Key {
451+
// delta.Add("Spec.Code.S3Key", a.ko.Spec.Code.S3Key, b.ko.Spec.Code.S3Key)
452+
// }
453+
// }
454+
// if ackcompare.HasNilDifference(a.ko.Spec.Code.S3ObjectVersion, b.ko.Spec.Code.S3ObjectVersion) {
455+
// delta.Add("Spec.Code.S3ObjectVersion", a.ko.Spec.Code.S3ObjectVersion, b.ko.Spec.Code.S3ObjectVersion)
456+
// } else if a.ko.Spec.Code.S3ObjectVersion != nil && b.ko.Spec.Code.S3ObjectVersion != nil {
457+
// if *a.ko.Spec.Code.S3ObjectVersion != *b.ko.Spec.Code.S3ObjectVersion {
458+
// delta.Add("Spec.Code.S3ObjectVersion", a.ko.Spec.Code.S3ObjectVersion, b.ko.Spec.Code.S3ObjectVersion)
459+
// }
460+
// }
441461
}
442462
}
443463

test/e2e/resources/function.yaml

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
apiVersion: lambda.services.k8s.aws/v1alpha1
22
kind: Function
33
metadata:
4-
name: $FUNCTION_NAME
4+
name: testfunction
55
annotations:
6-
services.k8s.aws/region: $AWS_REGION
6+
services.k8s.aws/region: us-west-2
77
spec:
8-
name: $FUNCTION_NAME
8+
name: testfunction
99
code:
10-
s3Bucket: $BUCKET_NAME
11-
s3Key: $LAMBDA_FILE_NAME
12-
role: $LAMBDA_ROLE
10+
s3Bucket: 322962841005-lambda-test
11+
s3Key: my-deployment-package.zip
12+
role: arn:aws:iam::322962841005:role/lambda_basic_execution
13+
codeS3SHA256: LPjdyPLMyt/xeNHWE1ekPopFwTV2bWmxRCDBdTZr+fo=
1314
runtime: python3.9
1415
handler: main
1516
description: function created by ACK lambda-controller e2e tests
16-
reservedConcurrentExecutions: $RESERVED_CONCURRENT_EXECUTIONS
17-
codeSigningConfigARN: "$CODE_SIGNING_CONFIG_ARN"
17+
# reservedConcurrentExecutions: $RESERVED_CONCURRENT_EXECUTIONS
18+
# codeSigningConfigARN: "$CODE_SIGNING_CONFIG_ARN"

test/e2e/tests/test_function.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def test_smoke(self, lambda_client):
9595
replacements["RESERVED_CONCURRENT_EXECUTIONS"] = "0"
9696
replacements["CODE_SIGNING_CONFIG_ARN"] = ""
9797
replacements["AWS_REGION"] = get_region()
98-
98+
9999
# Load Lambda CR
100100
resource_data = load_lambda_resource(
101101
"function",
@@ -137,7 +137,9 @@ def test_smoke(self, lambda_client):
137137
cr["spec"]["description"] = "Updated description"
138138
cr["spec"]["timeout"] = 10
139139
cr["spec"]["tags"] = update_tags
140-
140+
cr["spec"]["codeS3SHA256"] = "xyzx/6d9vfoneW+qg1io3FwJOQDxEATifUL/oPeNoSI="
141+
cr["spec"]["code"]["s3Key"] = "updated-my-deployment-package.zip"
142+
141143
# Patch k8s resource
142144
k8s.patch_custom_resource(ref, cr)
143145
time.sleep(UPDATE_WAIT_AFTER_SECONDS)
@@ -147,6 +149,7 @@ def test_smoke(self, lambda_client):
147149
assert function is not None
148150
assert function["Configuration"]["Description"] == "Updated description"
149151
assert function["Configuration"]["Timeout"] == 10
152+
assert function["Configuration"]["CodeSha256"] == "xyzx/6d9vfoneW+qg1io3FwJOQDxEATifUL/oPeNoSI="
150153

151154
function_tags = function["Tags"]
152155
tags.assert_ack_system_tags(

0 commit comments

Comments
 (0)