Skip to content

Commit

Permalink
Ensure Ref is not overwritten in Spec
Browse files Browse the repository at this point in the history
Similarly as the ec2-controller, the ref stored in a struct
is being overwritten during create/update. With this fix
we ensure the ref would not be discarded.

Currently there isn't a way to test this fix, as we can't
run two controllers simultaneously and reference subnet names
in cluster directly.
Instead I will document an example with the fix working in
this PR
  • Loading branch information
michaelhtm committed Sep 18, 2024
1 parent 5256d32 commit d5c868d
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 2 deletions.
4 changes: 2 additions & 2 deletions apis/v1alpha1/ack-generate-metadata.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ack_generate_info:
build_date: "2024-08-29T17:14:13Z"
build_date: "2024-09-18T21:03:40Z"
build_hash: f8f98563404066ac3340db0a049d2e530e5c51cc
go_version: go1.22.5
go_version: go1.23.0
version: v0.38.1
api_directory_checksum: 626700f8799840e0470b1ff7ef3dbb32665b9f9d
api_version: v1alpha1
Expand Down
7 changes: 7 additions & 0 deletions pkg/resource/cluster/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,13 @@ func (rm *resourceManager) customUpdate(
}

rm.setStatusDefaults(updatedRes.ko)
if desired.ko.Spec.ResourcesVPCConfig.SubnetRefs != nil {
updated.ko.Spec.ResourcesVPCConfig.SubnetRefs = desired.ko.Spec.ResourcesVPCConfig.SubnetRefs
}

if desired.ko.Spec.ResourcesVPCConfig.SecurityGroupRefs != nil {
updated.ko.Spec.ResourcesVPCConfig.SecurityGroupRefs = desired.ko.Spec.ResourcesVPCConfig.SecurityGroupRefs
}
return updatedRes, nil
}

Expand Down
14 changes: 14 additions & 0 deletions pkg/resource/cluster/sdk.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions templates/hooks/cluster/sdk_create_post_set_output.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,11 @@
ackcondition.SetSynced(&resource{ko}, corev1.ConditionFalse, nil, nil)
return &resource{ko}, nil
}

if desired.ko.Spec.ResourcesVPCConfig.SubnetRefs != nil {
ko.Spec.ResourcesVPCConfig.SubnetRefs = desired.ko.Spec.ResourcesVPCConfig.SubnetRefs
}

if desired.ko.Spec.ResourcesVPCConfig.SecurityGroupRefs != nil {
ko.Spec.ResourcesVPCConfig.SecurityGroupRefs = desired.ko.Spec.ResourcesVPCConfig.SecurityGroupRefs
}
7 changes: 7 additions & 0 deletions templates/hooks/cluster/sdk_read_one_post_set_output.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,10 @@
ackcondition.SetSynced(&resource{ko}, corev1.ConditionTrue, nil, nil)
}

if r.ko.Spec.ResourcesVPCConfig.SubnetRefs != nil {
ko.Spec.ResourcesVPCConfig.SubnetRefs = r.ko.Spec.ResourcesVPCConfig.SubnetRefs
}

if r.ko.Spec.ResourcesVPCConfig.SecurityGroupRefs != nil {
ko.Spec.ResourcesVPCConfig.SecurityGroupRefs = r.ko.Spec.ResourcesVPCConfig.SecurityGroupRefs
}

0 comments on commit d5c868d

Please sign in to comment.