Skip to content

Commit

Permalink
feat(tags): filter AWS tags and ACK tags during reconciliation (#170)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
michaelhtm authored Feb 17, 2025
1 parent e48dd7b commit 5b918f9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
5 changes: 5 additions & 0 deletions mocks/pkg/types/aws_resource_manager.go

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

18 changes: 2 additions & 16 deletions pkg/runtime/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,14 +330,10 @@ func (r *resourceReconciler) handleAdoption(
return nil, err
}

rlog.Enter("rm.EnsureTags")
err = rm.EnsureTags(ctx, resolved, r.sc.GetMetadata())
rlog.Exit("rm.EnsureTags", err)
if err != nil {
return resolved, err
}
rlog.Enter("rm.ReadOne")
latest, err := rm.ReadOne(ctx, resolved)
rlog.Exit("rm.ReadOne", err)
rm.FilterSystemTags(latest)
if err != nil {
return latest, err
}
Expand All @@ -346,16 +342,6 @@ func (r *resourceReconciler) handleAdoption(
return latest, err
}

// Ensure tags again after adding the finalizer and patching the
// resource. Patching desired resource omits the controller tags
// because they are not persisted in etcd. So we again ensure
// that tags are present before performing the create operation.
rlog.Enter("rm.EnsureTags")
err = rm.EnsureTags(ctx, latest, r.sc.GetMetadata())
rlog.Exit("rm.EnsureTags", err)
if err != nil {
return latest, err
}
r.rd.MarkAdopted(latest)
rlog.WithValues("is_adopted", "true")
latest, err = r.patchResourceMetadataAndSpec(ctx, rm, desired, latest)
Expand Down
6 changes: 6 additions & 0 deletions pkg/types/aws_resource_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ type AWSResourceManager interface {
// If the AWSResource does not support tags, only then the controller tags
// will not be added to the AWSResource.
EnsureTags(context.Context, AWSResource, ServiceControllerMetadata) error
// FilterSystemTags ignores tags that are either injected by the controller
// or by AWS. These tags have keys that start with "aws:" or "services.k8s.aws/"
// and this function will remove them before adoption.
// Eg. resources created with cloudformation have tags that cannot be
//removed by an ACK controller
FilterSystemTags(AWSResource)
}

// AWSResourceManagerFactory returns an AWSResourceManager that can be used to
Expand Down

0 comments on commit 5b918f9

Please sign in to comment.