Skip to content

Commit cf95d82

Browse files
authored
Initialise spec.Code before setting the imageURI (#55)
Fixes aws-controllers-k8s/community#1480 The runtime panics observed in issue 1480 were mainly caused by the `sdk_read_one` hook we use for `Function` resource. The hook didn't correctly initialise `spec.Code`. This patch fixes the initialization to avoid nil pointer panics when adopting function resources By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 753891a commit cf95d82

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

pkg/resource/function/sdk.go

Lines changed: 6 additions & 0 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: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
if resp.Code != nil {
2-
// We need to keep the desired .Code s3Bucket s3Key and s3ObjectVersion
2+
// We need to keep the desired .Code s3Bucket s3Key and s3ObjectVersion
33
// part of the function's spec. So instead of setting Spec.Code to nil
44
// we only set ImageURI
5+
//
6+
// When adopting a Function resource, Spec.Code field should be manually
7+
// initialised before injecting ImageURI.
8+
if ko.Spec.Code == nil {
9+
ko.Spec.Code = &svcapitypes.FunctionCode{}
10+
}
511
if resp.Code.ImageUri != nil {
612
ko.Spec.Code.ImageURI = resp.Code.ImageUri
713
}

0 commit comments

Comments
 (0)