Skip to content

Commit c37cd3b

Browse files
authored
fix(networkacl): Correct update order and entries/associations handlers (#202)
The custom update logic for `NetworkACL` resources was syncing the `Entries` before the `Tags`. This could lead to issues if the `Entries` sync failed as the Tags would not be updated.. This change also updates the order to sync `Tags` before `Entries`. It also uses `DeepCopy` when passing the resource to `createAssociation` and `createEntries to avoid modifying the original desired state. Additionally, the exit functions in `hooks.go` were fixed to properly handle the error return value. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent fd8e540 commit c37cd3b

File tree

4 files changed

+18
-13
lines changed

4 files changed

+18
-13
lines changed

apis/v1alpha1/ack-generate-metadata.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
ack_generate_info:
2-
build_date: "2024-06-19T06:55:08Z"
2+
build_date: "2024-06-19T08:11:53Z"
33
build_hash: 14cef51778d471698018b6c38b604181a6948248
44
go_version: go1.22.4
55
version: v0.34.0

pkg/resource/network_acl/hooks.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func (rm *resourceManager) customUpdateNetworkAcl(
3939
) (updated *resource, err error) {
4040
rlog := ackrtlog.FromContext(ctx)
4141
exit := rlog.Trace("rm.customUpdateNetworkAcl")
42-
defer exit(err)
42+
defer func(err error) { exit(err) }(err)
4343

4444
// Default `updated` to `desired` because it is likely
4545
// EC2 `modify` APIs do NOT return output, only errors.
@@ -48,12 +48,6 @@ func (rm *resourceManager) customUpdateNetworkAcl(
4848
// (now updated.Spec) reflects the latest resource state.
4949
updated = rm.concreteResource(desired.DeepCopy())
5050

51-
if delta.DifferentAt("Spec.Entries") {
52-
if err := rm.syncEntries(ctx, desired, latest); err != nil {
53-
return nil, err
54-
}
55-
}
56-
5751
if delta.DifferentAt("Spec.Tags") {
5852
if err := tags.Sync(
5953
ctx, rm.sdkapi, rm.metrics, *latest.ko.Status.ID,
@@ -63,6 +57,12 @@ func (rm *resourceManager) customUpdateNetworkAcl(
6357
}
6458
}
6559

60+
if delta.DifferentAt("Spec.Entries") {
61+
if err := rm.syncEntries(ctx, desired, latest); err != nil {
62+
return nil, err
63+
}
64+
}
65+
6666
if delta.DifferentAt("Spec.Associations") {
6767
if err := rm.syncAssociation(ctx, desired, latest); err != nil {
6868
return nil, err
@@ -297,7 +297,8 @@ func (rm *resourceManager) syncEntries(
297297
) (err error) {
298298
rlog := ackrtlog.FromContext(ctx)
299299
exit := rlog.Trace("rm.syncEntries")
300-
defer exit(err)
300+
defer func(err error) { exit(err) }(err)
301+
301302
toAdd := []*svcapitypes.NetworkACLEntry{}
302303
toDelete := []*svcapitypes.NetworkACLEntry{}
303304
toUpdate := []*svcapitypes.NetworkACLEntry{}

pkg/resource/network_acl/sdk.go

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

templates/hooks/network_acl/sdk_create_post_set_output.go.tpl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@
44

55
if len(desired.ko.Spec.Associations) > 0 {
66
ko.Spec.Associations = desired.ko.Spec.Associations
7-
if err := rm.createAssociation(ctx, &resource{ko}); err != nil {
7+
copy := ko.DeepCopy()
8+
if err := rm.createAssociation(ctx, &resource{copy}); err != nil {
89
rlog.Debug("Error while syncing Association", err)
910
}
1011
}
1112

1213
if len(desired.ko.Spec.Entries) > 0 {
1314
//desired rules are overwritten by NetworkACL's default rules
1415
ko.Spec.Entries = append(ko.Spec.Entries, desired.ko.Spec.Entries...)
15-
if err := rm.createEntries(ctx, &resource{ko}); err != nil {
16+
copy := ko.DeepCopy()
17+
if err := rm.createEntries(ctx, &resource{copy}); err != nil {
1618
rlog.Debug("Error while syncing routes", err)
1719
}
1820
}

0 commit comments

Comments
 (0)