Skip to content

Commit 5c15463

Browse files
ack-botVandita2020
authored andcommitted
Update to ACK runtime v0.25.0, code-generator v0.25.0 (aws-controllers-k8s#87)
---------- * ACK code-generator `v0.25.0` [release notes](https://github.com/aws-controllers-k8s/code-generator/releases/tag/v0.25.0) * ACK runtime `v0.25.0` [release notes](https://github.com/aws-controllers-k8s/runtime/releases/tag/v0.25.0) ---------- NOTE: This PR increments the release version of service controller from `v0.1.6` to `v0.1.7` Once this PR is merged, release `v0.1.7` will be automatically created for `lambda-controller` **Please close this PR, if you do not want the new patch release for `lambda-controller`** ---------- ``` building ack-generate ... ok. ==== building lambda-controller ==== Copying common custom resource definitions into lambda Building Kubernetes API objects for lambda Generating deepcopy code for lambda Generating custom resource definitions for lambda Building service controller for lambda Generating RBAC manifests for lambda Running gofmt against generated code for lambda Updating additional GitHub repository maintenance files ==== building lambda-controller release artifacts ==== Building release artifacts for lambda-v0.1.7 Generating common custom resource definitions Generating custom resource definitions for lambda Generating RBAC manifests for lambda ``` ---------- By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 39f35a1 commit 5c15463

File tree

12 files changed

+149
-20
lines changed

12 files changed

+149
-20
lines changed

apis/v1alpha1/ack-generate-metadata.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ api_directory_checksum: a9fcef68210dd72b4b2e37052f2c1a9e971326c6
77
api_version: v1alpha1
88
aws_sdk_go_version: v1.44.181
99
generator_config_info:
10-
file_checksum: 095af1082df5c34cdc12296dc085bc6b2b7eadb9
10+
file_checksum: e495db568ae64db031fcfa40b8a53f9866f22302
1111
original_file_name: generator.yaml
1212
last_modification:
1313
reason: API generation

apis/v1alpha1/function.go

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/v1alpha1/generator.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ resources:
1919
- path: Status.State
2020
in: [ "Active" ]
2121
fields:
22+
CodeS3SHA256:
23+
type: String
24+
compare:
25+
is_ignored: true
2226
Code.S3Bucket:
2327
references:
2428
resource: Bucket

apis/v1alpha1/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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

generator.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ resources:
1919
- path: Status.State
2020
in: [ "Active" ]
2121
fields:
22+
CodeS3SHA256:
23+
type: String
24+
compare:
25+
is_ignored: true
2226
Code.S3Bucket:
2327
references:
2428
resource: Bucket

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

Lines changed: 2 additions & 0 deletions
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

pkg/resource/function/hooks.go

Lines changed: 27 additions & 18 deletions
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"
@@ -96,7 +98,7 @@ func (rm *resourceManager) customUpdateFunction(
9698
// UpdateFunctionCode because both of them can put the function in a
9799
// Pending state.
98100
switch {
99-
case delta.DifferentAt("Spec.Code"):
101+
case delta.DifferentAt("Spec.Code") || delta.DifferentAt("Spec.CodeS3SHA256"):
100102
err = rm.updateFunctionCode(ctx, desired, delta)
101103
if err != nil {
102104
return nil, err
@@ -335,30 +337,24 @@ func (rm *resourceManager) updateFunctionCode(
335337
exit := rlog.Trace("rm.updateFunctionCode")
336338
defer exit(err)
337339

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-
347340
dspec := desired.ko.Spec
348341
input := &svcsdk.UpdateFunctionCodeInput{
349342
FunctionName: aws.String(*dspec.Name),
350343
}
351344

352345
if dspec.Code != nil {
353-
switch {
354-
case dspec.Code.ImageURI != nil:
346+
if delta.DifferentAt("Spec.Code.ImageURI") {
355347
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
348+
} else if delta.DifferentAt("Spec.CodeS3SHA256") {
349+
if dspec.Code.S3Key != nil {
350+
input.S3Key = aws.String(*dspec.Code.S3Key)
351+
}
352+
if dspec.Code.S3Bucket != nil {
353+
input.S3Bucket = aws.String(*dspec.Code.S3Bucket)
354+
}
355+
if dspec.Code.S3ObjectVersion != nil {
356+
input.S3ObjectVersion = aws.String(*dspec.Code.S3ObjectVersion)
357+
}
362358
}
363359
}
364360

@@ -416,6 +412,19 @@ func customPreCompare(
416412
delta.Add("Spec.Code.ImageURI", a.ko.Spec.Code.ImageURI, b.ko.Spec.Code.ImageURI)
417413
}
418414
}
415+
expected, _ := json.Marshal(a.ko.Spec.CodeS3SHA256)
416+
fmt.Println("expected:", string(expected))
417+
418+
actual, _ := json.Marshal(b.ko.Status.CodeSHA256)
419+
fmt.Println("actual:", string(actual))
420+
421+
if ackcompare.HasNilDifference(a.ko.Spec.CodeS3SHA256, b.ko.Status.CodeSHA256) {
422+
delta.Add("Spec.CodeS3SHA256", a.ko.Spec.CodeS3SHA256, b.ko.Status.CodeSHA256)
423+
} else if a.ko.Spec.CodeS3SHA256 != nil && b.ko.Status.CodeSHA256 != nil {
424+
if *a.ko.Spec.CodeS3SHA256 != *b.ko.Status.CodeSHA256 {
425+
delta.Add("Spec.CodeS3SHA256", a.ko.Spec.CodeS3SHA256, b.ko.Status.CodeSHA256)
426+
}
427+
}
419428
//TODO(hialylmh) handle Spec.Code.S3bucket changes
420429
// if ackcompare.HasNilDifference(a.ko.Spec.Code.S3Bucket, b.ko.Spec.Code.S3Bucket) {
421430
// delta.Add("Spec.Code.S3Bucket", a.ko.Spec.Code.S3Bucket, b.ko.Spec.Code.S3Bucket)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
apiVersion: lambda.services.k8s.aws/v1alpha1
2+
kind: Function
3+
metadata:
4+
name: $FUNCTION_NAME
5+
annotations:
6+
services.k8s.aws/region: $AWS_REGION
7+
spec:
8+
name: $FUNCTION_NAME
9+
code:
10+
s3Bucket: $BUCKET_NAME
11+
s3Key: $LAMBDA_FILE_NAME
12+
role: $LAMBDA_ROLE
13+
codeS3SHA256: $HASH
14+
runtime: python3.9
15+
handler: main
16+
description: function created by ACK lambda-controller e2e tests
17+
reservedConcurrentExecutions: $RESERVED_CONCURRENT_EXECUTIONS
18+
codeSigningConfigARN: "$CODE_SIGNING_CONFIG_ARN"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
if __name__ == "__main__":
2+
print("Updated Hello ACK!")

test/e2e/service_bootstrap.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@
4343
LAMBDA_FUNCTION_FILE_PATH = f"./resources/lambda_function/{LAMBDA_FUNCTION_FILE}"
4444
LAMBDA_FUNCTION_FILE_PATH_ZIP = f"./resources/lambda_function/{LAMBDA_FUNCTION_FILE_ZIP}"
4545

46+
LAMBDA_FUNCTION_UPDATED_FILE = "updated_main.py"
47+
LAMBDA_FUNCTION_UPDATED_FILE_ZIP = "updated_main.zip"
48+
LAMBDA_FUNCTION_UPDATED_FILE_PATH = f"./resources/lambda_function/{LAMBDA_FUNCTION_UPDATED_FILE}"
49+
LAMBDA_FUNCTION_UPDATED_FILE_PATH_ZIP = f"./resources/lambda_function/{LAMBDA_FUNCTION_UPDATED_FILE_ZIP}"
50+
4651
AWS_SIGNING_PLATFORM_ID = "AWSLambda-SHA384-ECDSA"
4752

4853
def zip_function_file(src: str, dst: str):
@@ -127,6 +132,12 @@ def service_bootstrap() -> Resources:
127132
LAMBDA_FUNCTION_FILE_PATH_ZIP,
128133
resources.FunctionsBucket.name,
129134
)
135+
136+
zip_function_file(LAMBDA_FUNCTION_UPDATED_FILE_PATH, LAMBDA_FUNCTION_UPDATED_FILE_PATH_ZIP)
137+
upload_function_to_bucket(
138+
LAMBDA_FUNCTION_UPDATED_FILE_PATH_ZIP,
139+
resources.FunctionsBucket.name,
140+
)
130141
except BootstrapFailureException as ex:
131142
exit(254)
132143
return resources

test/e2e/tests/test_function.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from e2e.replacement_values import REPLACEMENT_VALUES
2828
from e2e.bootstrap_resources import get_bootstrap_resources
2929
from e2e.service_bootstrap import LAMBDA_FUNCTION_FILE_ZIP
30+
from e2e.service_bootstrap import LAMBDA_FUNCTION_UPDATED_FILE_ZIP
3031
from e2e.tests.helper import LambdaValidator
3132

3233
RESOURCE_PLURAL = "functions"
@@ -536,5 +537,75 @@ def test_function_snapstart(self, lambda_client):
536537

537538
time.sleep(DELETE_WAIT_AFTER_SECONDS)
538539

540+
# Check Lambda function doesn't exist
541+
assert not lambda_validator.function_exists(resource_name)
542+
543+
def test_function_code_s3(self, lambda_client):
544+
resource_name = random_suffix_name("functioncodeS3", 24)
545+
546+
resources = get_bootstrap_resources()
547+
logging.debug(resources)
548+
549+
replacements = REPLACEMENT_VALUES.copy()
550+
replacements["FUNCTION_NAME"] = resource_name
551+
replacements["BUCKET_NAME"] = resources.FunctionsBucket.name
552+
replacements["LAMBDA_ROLE"] = resources.BasicRole.arn
553+
replacements["LAMBDA_FILE_NAME"] = LAMBDA_FUNCTION_FILE_ZIP
554+
replacements["RESERVED_CONCURRENT_EXECUTIONS"] = "0"
555+
replacements["CODE_SIGNING_CONFIG_ARN"] = ""
556+
replacements["AWS_REGION"] = get_region()
557+
replacements["HASH"] = "/tHBXaeeZCkMO6W7N6tpEhMC21Mf/lUK/WavHWmgBwU="
558+
559+
# Load Lambda CR
560+
resource_data = load_lambda_resource(
561+
"function_code_s3",
562+
additional_replacements=replacements,
563+
)
564+
logging.debug(resource_data)
565+
566+
# Create k8s resource
567+
ref = k8s.CustomResourceReference(
568+
CRD_GROUP, CRD_VERSION, RESOURCE_PLURAL,
569+
resource_name, namespace="default",
570+
)
571+
k8s.create_custom_resource(ref, resource_data)
572+
cr = k8s.wait_resource_consumed_by_controller(ref)
573+
574+
assert cr is not None
575+
assert k8s.get_resource_exists(ref)
576+
577+
time.sleep(CREATE_WAIT_AFTER_SECONDS)
578+
579+
cr = k8s.wait_resource_consumed_by_controller(ref)
580+
581+
lambda_validator = LambdaValidator(lambda_client)
582+
583+
# Assert that the original code.s3Bucket and code.s3Key is still part of
584+
# the function's CR
585+
assert cr["spec"]["code"]["s3Bucket"] == resources.FunctionsBucket.name
586+
assert cr["spec"]["code"]["s3Key"] == LAMBDA_FUNCTION_FILE_ZIP
587+
588+
# Check Lambda function exists
589+
assert lambda_validator.function_exists(resource_name)
590+
591+
# Update cr
592+
cr["spec"]["codeS3SHA256"] = "WOraA9i0RRICzj+4asi24Kx1PnumV2McYTMXLfizAhE="
593+
cr["spec"]["code"]["s3Key"] = LAMBDA_FUNCTION_UPDATED_FILE_ZIP
594+
595+
# Patch k8s resource
596+
k8s.patch_custom_resource(ref, cr)
597+
time.sleep(UPDATE_WAIT_AFTER_SECONDS)
598+
599+
# Check function updated fields
600+
function = lambda_validator.get_function(resource_name)
601+
assert function is not None
602+
assert function["Configuration"]["CodeSha256"] == "WOraA9i0RRICzj+4asi24Kx1PnumV2McYTMXLfizAhE="
603+
604+
# Delete k8s resource
605+
_, deleted = k8s.delete_custom_resource(ref)
606+
assert deleted is True
607+
608+
time.sleep(DELETE_WAIT_AFTER_SECONDS)
609+
539610
# Check Lambda function doesn't exist
540611
assert not lambda_validator.function_exists(resource_name)

0 commit comments

Comments
 (0)