Skip to content

Commit 5b918f9

Browse files
authored
feat(tags): filter AWS tags and ACK tags during reconciliation (#170)
* feat(tags): add SyncAWSTags for AWS-managed tag preservation Add utility to automatically preserve immutable AWS-managed tags (aws:*) when modifying resources. Prevents tag operation errors with CloudFormation and Service Catalog managed resources. * Add FilterAWSTags as a method in AWSResourceManager interface. This funtion will filter out tags injected by AWS and ACK.
1 parent e48dd7b commit 5b918f9

File tree

3 files changed

+13
-16
lines changed

3 files changed

+13
-16
lines changed

mocks/pkg/types/aws_resource_manager.go

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

pkg/runtime/reconciler.go

+2-16
Original file line numberDiff line numberDiff line change
@@ -330,14 +330,10 @@ func (r *resourceReconciler) handleAdoption(
330330
return nil, err
331331
}
332332

333-
rlog.Enter("rm.EnsureTags")
334-
err = rm.EnsureTags(ctx, resolved, r.sc.GetMetadata())
335-
rlog.Exit("rm.EnsureTags", err)
336-
if err != nil {
337-
return resolved, err
338-
}
339333
rlog.Enter("rm.ReadOne")
340334
latest, err := rm.ReadOne(ctx, resolved)
335+
rlog.Exit("rm.ReadOne", err)
336+
rm.FilterSystemTags(latest)
341337
if err != nil {
342338
return latest, err
343339
}
@@ -346,16 +342,6 @@ func (r *resourceReconciler) handleAdoption(
346342
return latest, err
347343
}
348344

349-
// Ensure tags again after adding the finalizer and patching the
350-
// resource. Patching desired resource omits the controller tags
351-
// because they are not persisted in etcd. So we again ensure
352-
// that tags are present before performing the create operation.
353-
rlog.Enter("rm.EnsureTags")
354-
err = rm.EnsureTags(ctx, latest, r.sc.GetMetadata())
355-
rlog.Exit("rm.EnsureTags", err)
356-
if err != nil {
357-
return latest, err
358-
}
359345
r.rd.MarkAdopted(latest)
360346
rlog.WithValues("is_adopted", "true")
361347
latest, err = r.patchResourceMetadataAndSpec(ctx, rm, desired, latest)

pkg/types/aws_resource_manager.go

+6
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ type AWSResourceManager interface {
8585
// If the AWSResource does not support tags, only then the controller tags
8686
// will not be added to the AWSResource.
8787
EnsureTags(context.Context, AWSResource, ServiceControllerMetadata) error
88+
// FilterSystemTags ignores tags that are either injected by the controller
89+
// or by AWS. These tags have keys that start with "aws:" or "services.k8s.aws/"
90+
// and this function will remove them before adoption.
91+
// Eg. resources created with cloudformation have tags that cannot be
92+
//removed by an ACK controller
93+
FilterSystemTags(AWSResource)
8894
}
8995

9096
// AWSResourceManagerFactory returns an AWSResourceManager that can be used to

0 commit comments

Comments
 (0)