Skip to content

Commit b3a09f9

Browse files
authored
mitigate runtime panic when adopting cluster (#130)
Description of Changes: This change makes null checks to avoid panics. Panic was noticed when trying to adopt a resource By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent a9fe5b9 commit b3a09f9

File tree

4 files changed

+8
-6
lines changed

4 files changed

+8
-6
lines changed

apis/v1alpha1/ack-generate-metadata.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
ack_generate_info:
2-
build_date: "2024-09-19T16:42:31Z"
2+
build_date: "2024-09-30T17:24:49Z"
33
build_hash: f8f98563404066ac3340db0a049d2e530e5c51cc
44
go_version: go1.23.0
55
version: v0.38.1

pkg/resource/cluster/hook.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,12 @@ func (rm *resourceManager) customUpdate(
192192
return updatedRes, requeueWaitUntilCanModify(latest)
193193
}
194194

195+
// Ensure ACKResourceMetadata and ARN are not nil before derefrencing
196+
// This can occur when adopting a resource
195197
if delta.DifferentAt("Spec.Tags") {
196198
if err := tags.SyncTags(
197199
ctx, rm.sdkapi, rm.metrics,
198-
string(*desired.ko.Status.ACKResourceMetadata.ARN),
200+
string(*latest.ko.Status.ACKResourceMetadata.ARN),
199201
desired.ko.Spec.Tags, latest.ko.Spec.Tags,
200202
); err != nil {
201203
return nil, err

pkg/resource/cluster/sdk.go

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

templates/hooks/cluster/sdk_read_one_post_set_output.go.tpl

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
if r.ko.Spec.ResourcesVPCConfig.SubnetRefs != nil {
1+
if r.ko.Spec.ResourcesVPCConfig != nil && r.ko.Spec.ResourcesVPCConfig.SubnetRefs != nil {
22
ko.Spec.ResourcesVPCConfig.SubnetRefs = r.ko.Spec.ResourcesVPCConfig.SubnetRefs
33
}
44

5-
if r.ko.Spec.ResourcesVPCConfig.SecurityGroupRefs != nil {
5+
if r.ko.Spec.ResourcesVPCConfig != nil && r.ko.Spec.ResourcesVPCConfig.SecurityGroupRefs != nil {
66
ko.Spec.ResourcesVPCConfig.SecurityGroupRefs = r.ko.Spec.ResourcesVPCConfig.SecurityGroupRefs
77
}
88

0 commit comments

Comments
 (0)