Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ toolchain go1.22.4

require (
github.com/aws-controllers-k8s/pkg v0.0.15
github.com/aws-controllers-k8s/runtime v0.42.0
github.com/aws-controllers-k8s/runtime v0.43.0
github.com/aws/aws-sdk-go v1.49.0
github.com/aws/aws-sdk-go-v2 v1.32.7
github.com/dlclark/regexp2 v1.10.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf/go.mod h1:l
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
github.com/aws-controllers-k8s/pkg v0.0.15 h1:C1pnD/aDqJsU9oYf5upHkpSc+Hv4JQVtkdCpfZQIPig=
github.com/aws-controllers-k8s/pkg v0.0.15/go.mod h1:VvdjLWmR6IJ3KU8KByKiq/lJE8M+ur2piXysXKTGUS0=
github.com/aws-controllers-k8s/runtime v0.42.0 h1:fVb3cOwUtn0ZwTSedapES+Rspb97S8BTxMqXJt6R5uM=
github.com/aws-controllers-k8s/runtime v0.42.0/go.mod h1:Oy0JKvDxZMZ+SVupm4NZVqP00KLIIAMfk93KnOwlt5c=
github.com/aws-controllers-k8s/runtime v0.43.0 h1:mCtMHO0rew84VbqotquvBirnKysbao+y2G3QI8bKZxM=
github.com/aws-controllers-k8s/runtime v0.43.0/go.mod h1:Oy0JKvDxZMZ+SVupm4NZVqP00KLIIAMfk93KnOwlt5c=
github.com/aws/aws-sdk-go v1.49.0 h1:g9BkW1fo9GqKfwg2+zCD+TW/D36Ux+vtfJ8guF4AYmY=
github.com/aws/aws-sdk-go v1.49.0/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk=
github.com/aws/aws-sdk-go-v2 v1.32.7 h1:ky5o35oENWi0JYWUZkB7WYvVPP+bcRF5/Iq7JWSb5Rw=
Expand Down
2 changes: 2 additions & 0 deletions pkg/generate/ack/runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ func (frm *fakeRM) EnsureTags(
return nil
}

func (frm *fakeRM) FilterSystemTags(acktypes.AWSResource) {}

// This test is mostly just a hack to introduce a Go module dependency between
// the ACK runtime library and the code generator. The code generator doesn't
// actually depend on Go code in the ACK runtime, but it *produces* templated
Expand Down
6 changes: 3 additions & 3 deletions templates/pkg/resource/manager.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -342,14 +342,14 @@ func (rm *resourceManager) FilterSystemTags(res acktypes.AWSResource) {
{{ end -}}
existingTags = r.ko.Spec.{{ $tagField.Path }}
resourceTags := ToACKTags(existingTags)
IgnoreAWSTags(resourceTags)
ignoreSystemTags(resourceTags)
{{ GoCodeInitializeNestedStructField .CRD "r.ko" $tagField "svcapitypes" 1 -}}
r.ko.Spec.{{ $tagField.Path }} = FromACKTags(resourceTags)
{{- end }}
{{- end }}
}

// MirrorAWSTags ensures that AWS tags are included in the desired resource
// mirrorAWSTags ensures that AWS tags are included in the desired resource
// if they are present in the latest resource. This will ensure that the
// aws tags are not present in a diff. The logic of the controller will
// ensure these tags aren't patched to the resource in the cluster, and
Expand Down Expand Up @@ -395,7 +395,7 @@ func mirrorAWSTags(a *resource, b *resource) {
existingLatestTags = b.ko.Spec.{{ $tagField.Path }}
desiredTags := ToACKTags(existingDesiredTags)
latestTags := ToACKTags(existingLatestTags)
SyncAWSTags(desiredTags, latestTags)
syncAWSTags(desiredTags, latestTags)
{{ GoCodeInitializeNestedStructField .CRD "a.ko" $tagField "svcapitypes" 1 -}}
a.ko.Spec.{{ $tagField.Path }} = FromACKTags(desiredTags)
{{- end }}
Expand Down
14 changes: 7 additions & 7 deletions templates/pkg/resource/tags.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import(
var (
_ = svcapitypes.{{ .CRD.Kind }}{}
_ = acktags.NewTags()
ACKSystemTags = []string{"services.k8s.aws/namespace", "services.k8s.aws/controller-version"}
)

{{- if $hookCode := Hook .CRD "convert_tags" }}
Expand Down Expand Up @@ -87,21 +88,20 @@ func FromACKTags(tags acktags.Tags) {{ $tagFieldGoType }} {
}
{{ end }}

// IgnoreAWSTags ignores tags that have keys that start with "aws:"
// is needed to ensure the controller does not attempt to remove
// tags set by AWS
// ignoreSystemTags ignores tags that have keys that start with "aws:"
// and ACKSystemTags, to avoid patching them to the resourceSpec.
// Eg. resources created with cloudformation have tags that cannot be
// removed by an ACK controller
func IgnoreAWSTags(tags acktags.Tags) {
func ignoreSystemTags(tags acktags.Tags) {
for k := range tags {
if strings.HasPrefix(k, "aws:") ||
strings.HasPrefix(k, "services.k8s.aws/") {
slices.Contains(ACKSystemTags, k) {
delete(tags, k)
}
}
}

// SyncAWSTags ensures AWS-managed tags (prefixed with "aws:") from the latest resource state
// syncAWSTags ensures AWS-managed tags (prefixed with "aws:") from the latest resource state
// are preserved in the desired state. This prevents the controller from attempting to
// modify AWS-managed tags, which would result in an error.
//
Expand All @@ -120,7 +120,7 @@ func IgnoreAWSTags(tags acktags.Tags) {
// desired := Tags{"environment": "dev"}
// SyncAWSTags(desired, latest)
// desired now contains {"aws:cloudformation:stack-name": "my-stack", "environment": "dev"}
func SyncAWSTags(a acktags.Tags, b acktags.Tags) {
func syncAWSTags(a acktags.Tags, b acktags.Tags) {
for k := range b {
if strings.HasPrefix(k, "aws:") {
a[k] = b[k]
Expand Down