Skip to content

Commit 7582c00

Browse files
committed
Make mirrowAwsTags a method in the AWSResourceMAnager interface
1 parent bced95a commit 7582c00

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

templates/pkg/resource/manager.go.tpl

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ func (rm *resourceManager) ReadOne(
8989
panic("resource manager's ReadOne() method received resource with nil CR object")
9090
}
9191
observed, err := rm.sdkFind(ctx, r)
92+
rm.MirrorAWSTags(r, observed)
9293
if err != nil {
9394
if observed != nil {
9495
return rm.onError(observed, err)
@@ -140,7 +141,6 @@ func (rm *resourceManager) Update(
140141
// Should never happen... if it does, it's buggy code.
141142
panic("resource manager's Update() method received resource with nil CR object")
142143
}
143-
syncAWSTags(desired, latest)
144144
updated, err := rm.sdkUpdate(ctx, desired, latest, delta)
145145
if err != nil {
146146
if updated != nil {
@@ -312,7 +312,7 @@ func (rm *resourceManager) EnsureTags(
312312
{{- end }}
313313
}
314314
315-
// filterAWSTags ignores tags that have keys that start with "aws:"
315+
// FilterAWSTags ignores tags that have keys that start with "aws:"
316316
// is needed to ensure the controller does not attempt to remove
317317
// tags set by AWS. This function needs to be called after each Read
318318
// operation.
@@ -349,14 +349,18 @@ func (rm *resourceManager) FilterAWSTags(res acktypes.AWSResource) {
349349
{{- end }}
350350
}
351351
352-
353-
// syncAWSTags ignores tags that have keys that start with "aws:"
354-
// is needed to ensure the controller does not attempt to remove
355-
// tags set by AWS. This function needs to be called after each Read
356-
// operation.
357-
// Eg. resources created with cloudformation have tags that cannot be
358-
//removed by an ACK controller
359-
func syncAWSTags(a *resource, b *resource) {
352+
// MirrorAWSTags ensures that AWS tags are included in the desired resource
353+
// if they are present in the latest resource. This will ensure that the
354+
// aws tags are not present in a diff. The logic of the controller will
355+
// ensure these tags aren't patched to the resource in the cluster, and
356+
// will only be present to make sure we don't try to remove these tags.
357+
//
358+
// Although there are a lot of similarities between this function and
359+
// EnsureTags, they are very much different.
360+
// While EnsureTags tries to make sure the resource contains the controller
361+
// tags, mirrowAWSTags tries to make sure tags injected by AWS are mirrored
362+
// from the latest resoruce to the desired resource.
363+
func (rm *resourceManager) MirrorAWSTags(resA acktypes.AWSResource, resB acktypes.AWSResource) {
360364
{{- if $hookCode := Hook .CRD "sync_tags" }}
361365
{{ $hookCode }}
362366
{{ else }}
@@ -367,6 +371,8 @@ func syncAWSTags(a *resource, b *resource) {
367371
{{ if eq "list" $tagFieldShapeType -}}
368372
{{ $tagFieldGoType = (print "[]*svcapitypes." $tagField.GoTypeElem) -}}
369373
{{ end -}}
374+
a := rm.concreteResource(resA)
375+
b := rm.concreteResource(resB)
370376
if a == nil || a.ko == nil || b == nil || b.ko == nil {
371377
return
372378
}

0 commit comments

Comments
 (0)