From d7535f4d23fbdf084c35e2617b53255dd27d059a Mon Sep 17 00:00:00 2001 From: ci-robot Date: Thu, 27 Mar 2025 16:30:27 +0000 Subject: [PATCH] Update to ACK runtime `v0.44.0`, code-generator `v0.44.0` --- apis/v1alpha1/ack-generate-metadata.yaml | 8 +- cmd/controller/main.go | 13 +- config/controller/kustomization.yaml | 2 +- go.mod | 53 +++++---- go.sum | 112 +++++++++--------- helm/Chart.yaml | 4 +- helm/templates/NOTES.txt | 2 +- helm/templates/deployment.yaml | 4 + helm/values.schema.json | 5 +- helm/values.yaml | 6 +- pkg/resource/app/manager.go | 14 +-- pkg/resource/app/tags.go | 61 +++------- .../data_quality_job_definition/manager.go | 14 +-- .../data_quality_job_definition/tags.go | 61 +++------- pkg/resource/domain/manager.go | 14 +-- pkg/resource/domain/tags.go | 61 +++------- pkg/resource/endpoint/manager.go | 14 +-- pkg/resource/endpoint/tags.go | 61 +++------- pkg/resource/endpoint_config/manager.go | 14 +-- pkg/resource/endpoint_config/tags.go | 61 +++------- pkg/resource/feature_group/manager.go | 14 +-- pkg/resource/feature_group/tags.go | 61 +++------- .../hyper_parameter_tuning_job/manager.go | 14 +-- .../hyper_parameter_tuning_job/tags.go | 61 +++------- pkg/resource/inference_component/manager.go | 14 +-- pkg/resource/inference_component/tags.go | 61 +++------- pkg/resource/model/manager.go | 14 +-- pkg/resource/model/tags.go | 61 +++------- .../model_bias_job_definition/manager.go | 14 +-- .../model_bias_job_definition/tags.go | 61 +++------- .../manager.go | 14 +-- .../tags.go | 61 +++------- pkg/resource/model_package_group/manager.go | 14 +-- pkg/resource/model_package_group/tags.go | 61 +++------- .../model_quality_job_definition/manager.go | 14 +-- .../model_quality_job_definition/tags.go | 61 +++------- pkg/resource/monitoring_schedule/manager.go | 14 +-- pkg/resource/monitoring_schedule/tags.go | 61 +++------- pkg/resource/notebook_instance/manager.go | 14 +-- pkg/resource/notebook_instance/tags.go | 61 +++------- pkg/resource/pipeline/manager.go | 14 +-- pkg/resource/pipeline/tags.go | 61 +++------- pkg/resource/processing_job/manager.go | 14 +-- pkg/resource/processing_job/tags.go | 61 +++------- pkg/resource/training_job/manager.go | 14 +-- pkg/resource/training_job/tags.go | 61 +++------- pkg/resource/transform_job/manager.go | 14 +-- pkg/resource/transform_job/tags.go | 61 +++------- pkg/resource/user_profile/manager.go | 14 +-- pkg/resource/user_profile/tags.go | 61 +++------- 50 files changed, 595 insertions(+), 1114 deletions(-) diff --git a/apis/v1alpha1/ack-generate-metadata.yaml b/apis/v1alpha1/ack-generate-metadata.yaml index fd3a89ed..03d5c537 100755 --- a/apis/v1alpha1/ack-generate-metadata.yaml +++ b/apis/v1alpha1/ack-generate-metadata.yaml @@ -1,8 +1,8 @@ ack_generate_info: - build_date: "2025-03-10T20:12:55Z" - build_hash: cfbd9fc8a32a564e2f05252b60248053ff09e744 - go_version: go1.24.0 - version: v0.43.2-4-gcfbd9fc + build_date: "2025-03-27T16:29:41Z" + build_hash: 980cb1e4734f673d16101cf55206b84ca639ec01 + go_version: go1.24.1 + version: v0.44.0 api_directory_checksum: a0804e163a24b96c9fa36be8d0277bebfe1d5c77 api_version: v1alpha1 aws_sdk_go_version: v1.32.6 diff --git a/cmd/controller/main.go b/cmd/controller/main.go index 4a42e82a..bdfbb5f9 100644 --- a/cmd/controller/main.go +++ b/cmd/controller/main.go @@ -123,11 +123,20 @@ func main() { for _, namespace := range namespaces { watchNamespaces[namespace] = ctrlrtcache.Config{} } + watchSelectors, err := ackCfg.ParseWatchSelectors() + if err != nil { + setupLog.Error( + err, "Unable to parse watch selectors.", + "aws.service", awsServiceAlias, + ) + os.Exit(1) + } mgr, err := ctrlrt.NewManager(ctrlrt.GetConfigOrDie(), ctrlrt.Options{ Scheme: scheme, Cache: ctrlrtcache.Options{ - Scheme: scheme, - DefaultNamespaces: watchNamespaces, + Scheme: scheme, + DefaultNamespaces: watchNamespaces, + DefaultLabelSelector: watchSelectors, }, WebhookServer: &ctrlrtwebhook.DefaultServer{ Options: ctrlrtwebhook.Options{ diff --git a/config/controller/kustomization.yaml b/config/controller/kustomization.yaml index 08b63b9c..f45bc396 100644 --- a/config/controller/kustomization.yaml +++ b/config/controller/kustomization.yaml @@ -6,4 +6,4 @@ kind: Kustomization images: - name: controller newName: public.ecr.aws/aws-controllers-k8s/sagemaker-controller - newTag: 1.2.15 + newTag: 1.2.16 diff --git a/go.mod b/go.mod index ef023edd..75b81e6d 100644 --- a/go.mod +++ b/go.mod @@ -1,11 +1,11 @@ module github.com/aws-controllers-k8s/sagemaker-controller -go 1.22.0 +go 1.24.0 -toolchain go1.22.5 +toolchain go1.24.1 require ( - github.com/aws-controllers-k8s/runtime v0.42.0 + github.com/aws-controllers-k8s/runtime v0.44.0 github.com/aws/aws-sdk-go v1.55.6 github.com/aws/aws-sdk-go-v2 v1.34.0 github.com/aws/aws-sdk-go-v2/service/sagemaker v1.173.2 @@ -13,10 +13,10 @@ require ( github.com/ghodss/yaml v1.0.0 github.com/go-logr/logr v1.4.2 github.com/spf13/pflag v1.0.5 - k8s.io/api v0.31.0 - k8s.io/apimachinery v0.31.0 - k8s.io/client-go v0.31.0 - sigs.k8s.io/controller-runtime v0.19.0 + k8s.io/api v0.32.1 + k8s.io/apimachinery v0.32.1 + k8s.io/client-go v0.32.1 + sigs.k8s.io/controller-runtime v0.20.4 ) require ( @@ -36,21 +36,20 @@ require ( github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect github.com/emicklei/go-restful/v3 v3.11.0 // indirect - github.com/evanphx/json-patch/v5 v5.9.0 // indirect + github.com/evanphx/json-patch/v5 v5.9.11 // indirect github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/fxamacker/cbor/v2 v2.7.0 // indirect github.com/go-logr/zapr v1.3.0 // indirect - github.com/go-openapi/jsonpointer v0.19.6 // indirect + github.com/go-openapi/jsonpointer v0.21.0 // indirect github.com/go-openapi/jsonreference v0.20.2 // indirect - github.com/go-openapi/swag v0.22.4 // indirect + github.com/go-openapi/swag v0.23.0 // indirect github.com/gogo/protobuf v1.3.2 // indirect - github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/protobuf v1.5.4 // indirect + github.com/google/btree v1.1.3 // indirect github.com/google/gnostic-models v0.6.8 // indirect github.com/google/go-cmp v0.6.0 // indirect github.com/google/gofuzz v1.2.0 // indirect github.com/google/uuid v1.6.0 // indirect - github.com/imdario/mergo v0.3.12 // indirect github.com/itchyny/gojq v0.12.6 // indirect github.com/itchyny/timefmt-go v0.1.3 // indirect github.com/jaypipes/envutil v1.0.0 // indirect @@ -69,24 +68,26 @@ require ( github.com/samber/lo v1.37.0 // indirect github.com/x448/float16 v0.8.4 // indirect go.uber.org/multierr v1.11.0 // indirect - go.uber.org/zap v1.26.0 // indirect - golang.org/x/exp v0.0.0-20230515195305-f3d0a9c9a5cc // indirect - golang.org/x/net v0.33.0 // indirect - golang.org/x/oauth2 v0.21.0 // indirect - golang.org/x/sys v0.28.0 // indirect - golang.org/x/term v0.27.0 // indirect - golang.org/x/text v0.21.0 // indirect - golang.org/x/time v0.3.0 // indirect + go.uber.org/zap v1.27.0 // indirect + golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect + golang.org/x/net v0.37.0 // indirect + golang.org/x/oauth2 v0.23.0 // indirect + golang.org/x/sync v0.12.0 // indirect + golang.org/x/sys v0.31.0 // indirect + golang.org/x/term v0.30.0 // indirect + golang.org/x/text v0.23.0 // indirect + golang.org/x/time v0.7.0 // indirect gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect - google.golang.org/protobuf v1.34.2 // indirect + google.golang.org/protobuf v1.35.1 // indirect + gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect - k8s.io/apiextensions-apiserver v0.31.0 // indirect + k8s.io/apiextensions-apiserver v0.32.1 // indirect k8s.io/klog/v2 v2.130.1 // indirect - k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 // indirect - k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 // indirect - sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect - sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect + k8s.io/kube-openapi v0.0.0-20241105132330-32ad38e42d3f // indirect + k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738 // indirect + sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 // indirect + sigs.k8s.io/structured-merge-diff/v4 v4.4.2 // indirect sigs.k8s.io/yaml v1.4.0 // indirect ) diff --git a/go.sum b/go.sum index a97e660d..a83eb292 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -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.44.0 h1:Et0Gikkxx4tJ6+dyK6w88DZqYRbpUTpBHCEny0X7gLQ= +github.com/aws-controllers-k8s/runtime v0.44.0/go.mod h1:G2UMBKA7qgXG4JV16NTIUp715uqvUEvWaa7TG1I527U= github.com/aws/aws-sdk-go v1.55.6 h1:cSg4pvZ3m8dgYcgqB97MrcdjUmZ1BeMYKUxMMB89IPk= github.com/aws/aws-sdk-go v1.55.6/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU= github.com/aws/aws-sdk-go-v2 v1.34.0 h1:9iyL+cjifckRGEVpRKZP3eIxVlL06Qk1Tk13vreaVQU= @@ -45,8 +45,8 @@ github.com/emicklei/go-restful/v3 v3.11.0 h1:rAQeMHw1c7zTmncogyy8VvRZwtkmkZ4FxER github.com/emicklei/go-restful/v3 v3.11.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= github.com/evanphx/json-patch v5.6.0+incompatible h1:jBYDEEiFBPxA0v50tFdvOzQQTCvpL6mnFh5mB2/l16U= github.com/evanphx/json-patch v5.6.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= -github.com/evanphx/json-patch/v5 v5.9.0 h1:kcBlZQbplgElYIlo/n1hJbls2z/1awpXxpRi0/FOJfg= -github.com/evanphx/json-patch/v5 v5.9.0/go.mod h1:VNkHZ/282BpEyt/tObQO8s5CMPmYYq14uClGH4abBuQ= +github.com/evanphx/json-patch/v5 v5.9.11 h1:/8HVnzMq13/3x9TPvjG08wUGqBTmZBsCWzjTM0wiaDU= +github.com/evanphx/json-patch/v5 v5.9.11/go.mod h1:3j+LviiESTElxA4p3EMKAB9HXj3/XEtnUf6OZxqIQTM= github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= github.com/fxamacker/cbor/v2 v2.7.0 h1:iM5WgngdRBanHcxugY4JySA0nk1wZorNOpTgCMedv5E= @@ -57,21 +57,22 @@ github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-logr/zapr v1.3.0 h1:XGdV8XW8zdwFiwOA2Dryh1gj2KRQyOOoNmBy4EplIcQ= github.com/go-logr/zapr v1.3.0/go.mod h1:YKepepNBd1u/oyhd/yQmtjVXmm9uML4IXUgMOwR8/Gg= -github.com/go-openapi/jsonpointer v0.19.6 h1:eCs3fxoIi3Wh6vtgmLTOjdhSpiqphQ+DaPn38N2ZdrE= github.com/go-openapi/jsonpointer v0.19.6/go.mod h1:osyAmYz/mB/C3I+WsTTSgw1ONzaLJoLCyoi6/zppojs= +github.com/go-openapi/jsonpointer v0.21.0 h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1rr/O9oNQ= +github.com/go-openapi/jsonpointer v0.21.0/go.mod h1:IUyH9l/+uyhIYQ/PXVA41Rexl+kOkAPDdXEYns6fzUY= github.com/go-openapi/jsonreference v0.20.2 h1:3sVjiK66+uXK/6oQ8xgcRKcFgQ5KXa2KvnJRumpMGbE= github.com/go-openapi/jsonreference v0.20.2/go.mod h1:Bl1zwGIM8/wsvqjsOQLJ/SH+En5Ap4rVB5KVcIDZG2k= github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14= -github.com/go-openapi/swag v0.22.4 h1:QLMzNJnMGPRNDCbySlcj1x01tzU8/9LTTL9hZZZogBU= -github.com/go-openapi/swag v0.22.4/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14= +github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+GrE= +github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ577vPjgQ= github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI= github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= -github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= -github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= +github.com/google/btree v1.1.3 h1:CVpQJjYgC4VbzxeGVHfvZrv1ctoYCAI8vbl07Fcxlyg= +github.com/google/btree v1.1.3/go.mod h1:qOPhT0dTNdNzV6Z/lhRX0YXUafgPLFUh+gZMl761Gm4= github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I= github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U= github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= @@ -81,12 +82,10 @@ github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeN github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0= github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= -github.com/google/pprof v0.0.0-20240525223248-4bfdf5a9a2af h1:kmjWCqn2qkEml422C2Rrd27c3VGxi6a/6HNq8QmHRKM= -github.com/google/pprof v0.0.0-20240525223248-4bfdf5a9a2af/go.mod h1:K1liHPHnj73Fdn/EKuT8nrFqBihUSKXoLYU0BuatOYo= +github.com/google/pprof v0.0.0-20241029153458-d1b30febd7db h1:097atOisP2aRj7vFgYQBbFN4U4JNXUNYpxael3UzMyo= +github.com/google/pprof v0.0.0-20241029153458-d1b30febd7db/go.mod h1:vavhavw2zAxS5dIdcRluK6cSGGPlZynqzFM8NdvU144= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU= -github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= github.com/itchyny/gojq v0.12.6 h1:VjaFn59Em2wTxDNGcrRkDK9ZHMNa8IksOgL13sLL4d0= github.com/itchyny/gojq v0.12.6/go.mod h1:ZHrkfu7A+RbZLy5J1/JKpS4poEqrzItSTGDItqsfP0A= github.com/itchyny/timefmt-go v0.1.3 h1:7M3LGVDsqcd0VZH2U+x393obrzZisp7C0uEe921iRkU= @@ -121,10 +120,10 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= -github.com/onsi/ginkgo/v2 v2.19.0 h1:9Cnnf7UHo57Hy3k6/m5k3dRfGTMXGvxhHFvkDTCTpvA= -github.com/onsi/ginkgo/v2 v2.19.0/go.mod h1:rlwLi9PilAFJ8jCg9UE1QP6VBpd6/xj3SRC0d6TU0To= -github.com/onsi/gomega v1.33.1 h1:dsYjIxxSR755MDmKVsaFQTE22ChNBcuuTWgkUDSubOk= -github.com/onsi/gomega v1.33.1/go.mod h1:U4R44UsT+9eLIaYRB2a5qajjtQYn0hauxvRm16AVYg0= +github.com/onsi/ginkgo/v2 v2.22.0 h1:Yed107/8DjTr0lKCNt7Dn8yQ6ybuDRQoMGrNFKzMfHg= +github.com/onsi/ginkgo/v2 v2.22.0/go.mod h1:7Du3c42kxCUegi0IImZ1wUQzMBVecgIHjR1C+NkhLQo= +github.com/onsi/gomega v1.36.1 h1:bJDPBO7ibjxcbHMgSCoo4Yj18UWbKDlLwX1x9sybDcw= +github.com/onsi/gomega v1.36.1/go.mod h1:PvZbdDc8J6XJEpDK4HCuRBm8a6Fzp9/DmhC9C7yFlog= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= @@ -163,55 +162,57 @@ go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= -go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo= -go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so= +go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= +go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/exp v0.0.0-20230515195305-f3d0a9c9a5cc h1:mCRnTeVUjcrhlRmO0VK8a6k6Rrf6TF9htwo2pJVSjIU= -golang.org/x/exp v0.0.0-20230515195305-f3d0a9c9a5cc/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w= +golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 h1:2dVuKD2vS7b0QIHQbpyTISPd0LeHDbnYEryqj5Q1ug8= +golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I= -golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4= -golang.org/x/oauth2 v0.21.0 h1:tsimM75w1tF/uws5rbeHzIWxEqElMehnc+iW793zsZs= -golang.org/x/oauth2 v0.21.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= +golang.org/x/net v0.37.0 h1:1zLorHbz+LYj7MQlSf1+2tPIIgibq2eL5xkrGk6f+2c= +golang.org/x/net v0.37.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8= +golang.org/x/oauth2 v0.23.0 h1:PbgcYx2W7i4LvjJWEbf0ngHV6qJYr86PkAV3bXdLEbs= +golang.org/x/oauth2 v0.23.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.12.0 h1:MHc5BpPuC30uJk597Ri8TV3CNZcTLu6B6z4lJy+g6Jw= +golang.org/x/sync v0.12.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211124211545-fe61309f8881/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA= -golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/term v0.27.0 h1:WP60Sv1nlK1T6SupCHbXzSaN0b9wUmsPoRS9b61A23Q= -golang.org/x/term v0.27.0/go.mod h1:iMsnZpn0cago0GOrHO2+Y7u7JPn5AylBrcoWkElMTSM= +golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik= +golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= +golang.org/x/term v0.30.0 h1:PQ39fJZ+mfadBm0y5WlL4vlM7Sx1Hgf13sMIY2+QS9Y= +golang.org/x/term v0.30.0/go.mod h1:NYYFdzHoI5wRh/h5tDMdMqCqPJZEuNqVR5xJLd/n67g= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo= -golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= -golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4= -golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY= +golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4= +golang.org/x/time v0.7.0 h1:ntUhktv3OPE6TgYxXWv9vKvUSJyIFJlyohwbkEwPrKQ= +golang.org/x/time v0.7.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg= -golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= +golang.org/x/tools v0.31.0 h1:0EedkvKDbh+qistFTd0Bcwe/YLh4vHwWEkiI0toFIBU= +golang.org/x/tools v0.31.0/go.mod h1:naFTU+Cev749tSJRXJlna0T3WxKvb1kWEx15xA4SdmQ= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gomodules.xyz/jsonpatch/v2 v2.4.0 h1:Ci3iUJyx9UeRx7CeFN8ARgGbkESwJK+KB9lLcWxY/Zw= gomodules.xyz/jsonpatch/v2 v2.4.0/go.mod h1:AH3dM2RI6uoBZxn3LVrfvJ3E0/9dG4cSrbuBJT4moAY= -google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= -google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= +google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA= +google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= @@ -220,32 +221,31 @@ gopkg.in/evanphx/json-patch.v4 v4.12.0/go.mod h1:p8EYWUEYMpynmqDbY58zCKCFZw8pRWM gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc= gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -k8s.io/api v0.31.0 h1:b9LiSjR2ym/SzTOlfMHm1tr7/21aD7fSkqgD/CVJBCo= -k8s.io/api v0.31.0/go.mod h1:0YiFF+JfFxMM6+1hQei8FY8M7s1Mth+z/q7eF1aJkTE= -k8s.io/apiextensions-apiserver v0.31.0 h1:fZgCVhGwsclj3qCw1buVXCV6khjRzKC5eCFt24kyLSk= -k8s.io/apiextensions-apiserver v0.31.0/go.mod h1:b9aMDEYaEe5sdK+1T0KU78ApR/5ZVp4i56VacZYEHxk= -k8s.io/apimachinery v0.31.0 h1:m9jOiSr3FoSSL5WO9bjm1n6B9KROYYgNZOb4tyZ1lBc= -k8s.io/apimachinery v0.31.0/go.mod h1:rsPdaZJfTfLsNJSQzNHQvYoTmxhoOEofxtOsF3rtsMo= -k8s.io/client-go v0.31.0 h1:QqEJzNjbN2Yv1H79SsS+SWnXkBgVu4Pj3CJQgbx0gI8= -k8s.io/client-go v0.31.0/go.mod h1:Y9wvC76g4fLjmU0BA+rV+h2cncoadjvjjkkIGoTLcGU= +k8s.io/api v0.32.1 h1:f562zw9cy+GvXzXf0CKlVQ7yHJVYzLfL6JAS4kOAaOc= +k8s.io/api v0.32.1/go.mod h1:/Yi/BqkuueW1BgpoePYBRdDYfjPF5sgTr5+YqDZra5k= +k8s.io/apiextensions-apiserver v0.32.1 h1:hjkALhRUeCariC8DiVmb5jj0VjIc1N0DREP32+6UXZw= +k8s.io/apiextensions-apiserver v0.32.1/go.mod h1:sxWIGuGiYov7Io1fAS2X06NjMIk5CbRHc2StSmbaQto= +k8s.io/apimachinery v0.32.1 h1:683ENpaCBjma4CYqsmZyhEzrGz6cjn1MY/X2jB2hkZs= +k8s.io/apimachinery v0.32.1/go.mod h1:GpHVgxoKlTxClKcteaeuF1Ul/lDVb74KpZcxcmLDElE= +k8s.io/client-go v0.32.1 h1:otM0AxdhdBIaQh7l1Q0jQpmo7WOFIk5FFa4bg6YMdUU= +k8s.io/client-go v0.32.1/go.mod h1:aTTKZY7MdxUaJ/KiUs8D+GssR9zJZi77ZqtzcGXIiDg= k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk= k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE= -k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 h1:BZqlfIlq5YbRMFko6/PM7FjZpUb45WallggurYhKGag= -k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340/go.mod h1:yD4MZYeKMBwQKVht279WycxKyM84kkAx2DPrTXaeb98= -k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 h1:pUdcCO1Lk/tbT5ztQWOBi5HBgbBP1J8+AsQnQCKsi8A= -k8s.io/utils v0.0.0-20240711033017-18e509b52bc8/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= -sigs.k8s.io/controller-runtime v0.19.0 h1:nWVM7aq+Il2ABxwiCizrVDSlmDcshi9llbaFbC0ji/Q= -sigs.k8s.io/controller-runtime v0.19.0/go.mod h1:iRmWllt8IlaLjvTTDLhRBXIEtkCK6hwVBJJsYS9Ajf4= -sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo= -sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0= -sigs.k8s.io/structured-merge-diff/v4 v4.4.1 h1:150L+0vs/8DA78h1u02ooW1/fFq/Lwr+sGiqlzvrtq4= -sigs.k8s.io/structured-merge-diff/v4 v4.4.1/go.mod h1:N8hJocpFajUSSeSJ9bOZ77VzejKZaXsTtZo4/u7Io08= +k8s.io/kube-openapi v0.0.0-20241105132330-32ad38e42d3f h1:GA7//TjRY9yWGy1poLzYYJJ4JRdzg3+O6e8I+e+8T5Y= +k8s.io/kube-openapi v0.0.0-20241105132330-32ad38e42d3f/go.mod h1:R/HEjbvWI0qdfb8viZUeVZm0X6IZnxAydC7YU42CMw4= +k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738 h1:M3sRQVHv7vB20Xc2ybTt7ODCeFj6JSWYFzOFnYeS6Ro= +k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= +sigs.k8s.io/controller-runtime v0.20.4 h1:X3c+Odnxz+iPTRobG4tp092+CvBU9UK0t/bRf+n0DGU= +sigs.k8s.io/controller-runtime v0.20.4/go.mod h1:xg2XB0K5ShQzAgsoujxuKN4LNXR2LfwwHsPj7Iaw+XY= +sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 h1:/Rv+M11QRah1itp8VhT6HoVx1Ray9eB4DBr+K+/sCJ8= +sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3/go.mod h1:18nIHnGi6636UCz6m8i4DhaJ65T6EruyzmoQqI2BVDo= +sigs.k8s.io/structured-merge-diff/v4 v4.4.2 h1:MdmvkGuXi/8io6ixD5wud3vOLwc1rj0aNqRlpuvjmwA= +sigs.k8s.io/structured-merge-diff/v4 v4.4.2/go.mod h1:N8f93tFZh9U6vpxwRArLiikrE5/2tiu1w1AGfACIGE4= sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E= sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY= diff --git a/helm/Chart.yaml b/helm/Chart.yaml index 436ae193..e36df597 100644 --- a/helm/Chart.yaml +++ b/helm/Chart.yaml @@ -1,8 +1,8 @@ apiVersion: v1 name: sagemaker-chart description: A Helm chart for the ACK service controller for Amazon SageMaker (SageMaker) -version: 1.2.15 -appVersion: 1.2.15 +version: 1.2.16 +appVersion: 1.2.16 home: https://github.com/aws-controllers-k8s/sagemaker-controller icon: https://raw.githubusercontent.com/aws/eks-charts/master/docs/logo/aws.png sources: diff --git a/helm/templates/NOTES.txt b/helm/templates/NOTES.txt index 22205114..b0f3e21a 100644 --- a/helm/templates/NOTES.txt +++ b/helm/templates/NOTES.txt @@ -1,5 +1,5 @@ {{ .Chart.Name }} has been installed. -This chart deploys "public.ecr.aws/aws-controllers-k8s/sagemaker-controller:1.2.15". +This chart deploys "public.ecr.aws/aws-controllers-k8s/sagemaker-controller:1.2.16". Check its status by running: kubectl --namespace {{ .Release.Namespace }} get pods -l "app.kubernetes.io/instance={{ .Release.Name }}" diff --git a/helm/templates/deployment.yaml b/helm/templates/deployment.yaml index b718bcb3..510c10d8 100644 --- a/helm/templates/deployment.yaml +++ b/helm/templates/deployment.yaml @@ -57,6 +57,8 @@ spec: - "$(ACK_RESOURCE_TAGS)" - --watch-namespace - "$(ACK_WATCH_NAMESPACE)" + - --watch-selectors + - "$(ACK_WATCH_SELECTORS)" - --deletion-policy - "$(DELETION_POLICY)" {{- if .Values.leaderElection.enabled }} @@ -103,6 +105,8 @@ spec: value: {{ .Values.aws.endpoint_url | quote }} - name: ACK_WATCH_NAMESPACE value: {{ include "ack-sagemaker-controller.watch-namespace" . }} + - name: ACK_WATCH_SELECTORS + value: {{ .Values.watchSelectors }} - name: DELETION_POLICY value: {{ .Values.deletionPolicy }} - name: LEADER_ELECTION_NAMESPACE diff --git a/helm/values.schema.json b/helm/values.schema.json index 7ccb485d..37f2ca01 100644 --- a/helm/values.schema.json +++ b/helm/values.schema.json @@ -210,7 +210,10 @@ }, "watchNamespace": { "type": "string" - }, + }, + "watchSelectors": { + "type": "string" + }, "resourceTags": { "type": "array", "items": { diff --git a/helm/values.yaml b/helm/values.yaml index 117aaa28..384dca05 100644 --- a/helm/values.yaml +++ b/helm/values.yaml @@ -4,7 +4,7 @@ image: repository: public.ecr.aws/aws-controllers-k8s/sagemaker-controller - tag: 1.2.15 + tag: 1.2.16 pullPolicy: IfNotPresent pullSecrets: [] @@ -110,6 +110,10 @@ installScope: cluster # You can set multiple namespaces by providing a comma separated list of namespaces. e.g "namespace1,namespace2" watchNamespace: "" +# Set the value of labelsSelectors to be used by the controller to filter the resources to watch. +# You can set multiple labelsSelectors by providing a comma separated list of a=b arguments. e.g "label1=value1,label2=value2" +watchSelectors: "" + resourceTags: # Configures the ACK service controller to always set key/value pairs tags on # resources that it manages. diff --git a/pkg/resource/app/manager.go b/pkg/resource/app/manager.go index e52f67d0..bbe8ebff 100644 --- a/pkg/resource/app/manager.go +++ b/pkg/resource/app/manager.go @@ -300,9 +300,9 @@ func (rm *resourceManager) EnsureTags( defaultTags := ackrt.GetDefaultTags(&rm.cfg, r.ko, md) var existingTags []*svcapitypes.Tag existingTags = r.ko.Spec.Tags - resourceTags := ToACKTags(existingTags) + resourceTags, keyOrder := convertToOrderedACKTags(existingTags) tags := acktags.Merge(resourceTags, defaultTags) - r.ko.Spec.Tags = FromACKTags(tags) + r.ko.Spec.Tags = fromACKTags(tags, keyOrder) return nil } @@ -319,9 +319,9 @@ func (rm *resourceManager) FilterSystemTags(res acktypes.AWSResource) { } var existingTags []*svcapitypes.Tag existingTags = r.ko.Spec.Tags - resourceTags, tagKeyOrder := toACKTagsWithKeyOrder(existingTags) + resourceTags, tagKeyOrder := convertToOrderedACKTags(existingTags) ignoreSystemTags(resourceTags) - r.ko.Spec.Tags = fromACKTagsWithKeyOrder(resourceTags, tagKeyOrder) + r.ko.Spec.Tags = fromACKTags(resourceTags, tagKeyOrder) } // mirrorAWSTags ensures that AWS tags are included in the desired resource @@ -343,10 +343,10 @@ func mirrorAWSTags(a *resource, b *resource) { var existingDesiredTags []*svcapitypes.Tag existingDesiredTags = a.ko.Spec.Tags existingLatestTags = b.ko.Spec.Tags - desiredTags, desiredTagKeyOrder := toACKTagsWithKeyOrder(existingDesiredTags) - latestTags, _ := toACKTagsWithKeyOrder(existingLatestTags) + desiredTags, desiredTagKeyOrder := convertToOrderedACKTags(existingDesiredTags) + latestTags, _ := convertToOrderedACKTags(existingLatestTags) syncAWSTags(desiredTags, latestTags) - a.ko.Spec.Tags = fromACKTagsWithKeyOrder(desiredTags, desiredTagKeyOrder) + a.ko.Spec.Tags = fromACKTags(desiredTags, desiredTagKeyOrder) } // newResourceManager returns a new struct implementing diff --git a/pkg/resource/app/tags.go b/pkg/resource/app/tags.go index 8e0c81b8..e04c4536 100644 --- a/pkg/resource/app/tags.go +++ b/pkg/resource/app/tags.go @@ -30,69 +30,38 @@ var ( ACKSystemTags = []string{"services.k8s.aws/namespace", "services.k8s.aws/controller-version"} ) -// ToACKTags converts the tags parameter into 'acktags.Tags' shape. -// This method helps in creating the hub(acktags.Tags) for merging -// default controller tags with existing resource tags. -func ToACKTags(tags []*svcapitypes.Tag) acktags.Tags { - result := acktags.NewTags() - if tags == nil || len(tags) == 0 { - return result - } - - for _, t := range tags { - if t.Key != nil { - if t.Value == nil { - result[*t.Key] = "" - } else { - result[*t.Key] = *t.Value - } - } - } - - return result -} - -// toACKTagsWithKeyOrder converts the tags parameter into 'acktags.Tags' shape. +// convertToOrderedACKTags converts the tags parameter into 'acktags.Tags' shape. // This method helps in creating the hub(acktags.Tags) for merging // default controller tags with existing resource tags. It also returns a slice // of keys maintaining the original key Order when the tags are a list -func toACKTagsWithKeyOrder(tags []*svcapitypes.Tag) (acktags.Tags, []string) { +func convertToOrderedACKTags(tags []*svcapitypes.Tag) (acktags.Tags, []string) { result := acktags.NewTags() keyOrder := []string{} - if tags == nil || len(tags) == 0 { + + if len(tags) == 0 { return result, keyOrder } - for _, t := range tags { if t.Key != nil { keyOrder = append(keyOrder, *t.Key) + if t.Value != nil { + result[*t.Key] = *t.Value + } else { + result[*t.Key] = "" + } } } - result = ToACKTags(tags) return result, keyOrder } -// FromACKTags converts the tags parameter into []*svcapitypes.Tag shape. -// This method helps in setting the tags back inside AWSResource after merging -// default controller tags with existing resource tags. -func FromACKTags(tags acktags.Tags) []*svcapitypes.Tag { - result := []*svcapitypes.Tag{} - for k, v := range tags { - kCopy := k - vCopy := v - tag := svcapitypes.Tag{Key: &kCopy, Value: &vCopy} - result = append(result, &tag) - } - return result -} - -// fromACKTagsWithTagKeys converts the tags parameter into []*svcapitypes.Tag shape. +// fromACKTags converts the tags parameter into []*svcapitypes.Tag shape. // This method helps in setting the tags back inside AWSResource after merging // default controller tags with existing resource tags. When a list, // it maintains the order from original -func fromACKTagsWithKeyOrder(tags acktags.Tags, keyOrder []string) []*svcapitypes.Tag { +func fromACKTags(tags acktags.Tags, keyOrder []string) []*svcapitypes.Tag { result := []*svcapitypes.Tag{} + for _, k := range keyOrder { v, ok := tags[k] if ok { @@ -101,7 +70,11 @@ func fromACKTagsWithKeyOrder(tags acktags.Tags, keyOrder []string) []*svcapitype delete(tags, k) } } - result = append(result, FromACKTags(tags)...) + for k, v := range tags { + tag := svcapitypes.Tag{Key: &k, Value: &v} + result = append(result, &tag) + } + return result } diff --git a/pkg/resource/data_quality_job_definition/manager.go b/pkg/resource/data_quality_job_definition/manager.go index 000b64eb..ccb8f60d 100644 --- a/pkg/resource/data_quality_job_definition/manager.go +++ b/pkg/resource/data_quality_job_definition/manager.go @@ -291,9 +291,9 @@ func (rm *resourceManager) EnsureTags( defaultTags := ackrt.GetDefaultTags(&rm.cfg, r.ko, md) var existingTags []*svcapitypes.Tag existingTags = r.ko.Spec.Tags - resourceTags := ToACKTags(existingTags) + resourceTags, keyOrder := convertToOrderedACKTags(existingTags) tags := acktags.Merge(resourceTags, defaultTags) - r.ko.Spec.Tags = FromACKTags(tags) + r.ko.Spec.Tags = fromACKTags(tags, keyOrder) return nil } @@ -310,9 +310,9 @@ func (rm *resourceManager) FilterSystemTags(res acktypes.AWSResource) { } var existingTags []*svcapitypes.Tag existingTags = r.ko.Spec.Tags - resourceTags, tagKeyOrder := toACKTagsWithKeyOrder(existingTags) + resourceTags, tagKeyOrder := convertToOrderedACKTags(existingTags) ignoreSystemTags(resourceTags) - r.ko.Spec.Tags = fromACKTagsWithKeyOrder(resourceTags, tagKeyOrder) + r.ko.Spec.Tags = fromACKTags(resourceTags, tagKeyOrder) } // mirrorAWSTags ensures that AWS tags are included in the desired resource @@ -334,10 +334,10 @@ func mirrorAWSTags(a *resource, b *resource) { var existingDesiredTags []*svcapitypes.Tag existingDesiredTags = a.ko.Spec.Tags existingLatestTags = b.ko.Spec.Tags - desiredTags, desiredTagKeyOrder := toACKTagsWithKeyOrder(existingDesiredTags) - latestTags, _ := toACKTagsWithKeyOrder(existingLatestTags) + desiredTags, desiredTagKeyOrder := convertToOrderedACKTags(existingDesiredTags) + latestTags, _ := convertToOrderedACKTags(existingLatestTags) syncAWSTags(desiredTags, latestTags) - a.ko.Spec.Tags = fromACKTagsWithKeyOrder(desiredTags, desiredTagKeyOrder) + a.ko.Spec.Tags = fromACKTags(desiredTags, desiredTagKeyOrder) } // newResourceManager returns a new struct implementing diff --git a/pkg/resource/data_quality_job_definition/tags.go b/pkg/resource/data_quality_job_definition/tags.go index 2fca0d67..9cbdcf5f 100644 --- a/pkg/resource/data_quality_job_definition/tags.go +++ b/pkg/resource/data_quality_job_definition/tags.go @@ -30,69 +30,38 @@ var ( ACKSystemTags = []string{"services.k8s.aws/namespace", "services.k8s.aws/controller-version"} ) -// ToACKTags converts the tags parameter into 'acktags.Tags' shape. -// This method helps in creating the hub(acktags.Tags) for merging -// default controller tags with existing resource tags. -func ToACKTags(tags []*svcapitypes.Tag) acktags.Tags { - result := acktags.NewTags() - if tags == nil || len(tags) == 0 { - return result - } - - for _, t := range tags { - if t.Key != nil { - if t.Value == nil { - result[*t.Key] = "" - } else { - result[*t.Key] = *t.Value - } - } - } - - return result -} - -// toACKTagsWithKeyOrder converts the tags parameter into 'acktags.Tags' shape. +// convertToOrderedACKTags converts the tags parameter into 'acktags.Tags' shape. // This method helps in creating the hub(acktags.Tags) for merging // default controller tags with existing resource tags. It also returns a slice // of keys maintaining the original key Order when the tags are a list -func toACKTagsWithKeyOrder(tags []*svcapitypes.Tag) (acktags.Tags, []string) { +func convertToOrderedACKTags(tags []*svcapitypes.Tag) (acktags.Tags, []string) { result := acktags.NewTags() keyOrder := []string{} - if tags == nil || len(tags) == 0 { + + if len(tags) == 0 { return result, keyOrder } - for _, t := range tags { if t.Key != nil { keyOrder = append(keyOrder, *t.Key) + if t.Value != nil { + result[*t.Key] = *t.Value + } else { + result[*t.Key] = "" + } } } - result = ToACKTags(tags) return result, keyOrder } -// FromACKTags converts the tags parameter into []*svcapitypes.Tag shape. -// This method helps in setting the tags back inside AWSResource after merging -// default controller tags with existing resource tags. -func FromACKTags(tags acktags.Tags) []*svcapitypes.Tag { - result := []*svcapitypes.Tag{} - for k, v := range tags { - kCopy := k - vCopy := v - tag := svcapitypes.Tag{Key: &kCopy, Value: &vCopy} - result = append(result, &tag) - } - return result -} - -// fromACKTagsWithTagKeys converts the tags parameter into []*svcapitypes.Tag shape. +// fromACKTags converts the tags parameter into []*svcapitypes.Tag shape. // This method helps in setting the tags back inside AWSResource after merging // default controller tags with existing resource tags. When a list, // it maintains the order from original -func fromACKTagsWithKeyOrder(tags acktags.Tags, keyOrder []string) []*svcapitypes.Tag { +func fromACKTags(tags acktags.Tags, keyOrder []string) []*svcapitypes.Tag { result := []*svcapitypes.Tag{} + for _, k := range keyOrder { v, ok := tags[k] if ok { @@ -101,7 +70,11 @@ func fromACKTagsWithKeyOrder(tags acktags.Tags, keyOrder []string) []*svcapitype delete(tags, k) } } - result = append(result, FromACKTags(tags)...) + for k, v := range tags { + tag := svcapitypes.Tag{Key: &k, Value: &v} + result = append(result, &tag) + } + return result } diff --git a/pkg/resource/domain/manager.go b/pkg/resource/domain/manager.go index 1d854c8e..1ed2389c 100644 --- a/pkg/resource/domain/manager.go +++ b/pkg/resource/domain/manager.go @@ -330,9 +330,9 @@ func (rm *resourceManager) EnsureTags( defaultTags := ackrt.GetDefaultTags(&rm.cfg, r.ko, md) var existingTags []*svcapitypes.Tag existingTags = r.ko.Spec.Tags - resourceTags := ToACKTags(existingTags) + resourceTags, keyOrder := convertToOrderedACKTags(existingTags) tags := acktags.Merge(resourceTags, defaultTags) - r.ko.Spec.Tags = FromACKTags(tags) + r.ko.Spec.Tags = fromACKTags(tags, keyOrder) return nil } @@ -349,9 +349,9 @@ func (rm *resourceManager) FilterSystemTags(res acktypes.AWSResource) { } var existingTags []*svcapitypes.Tag existingTags = r.ko.Spec.Tags - resourceTags, tagKeyOrder := toACKTagsWithKeyOrder(existingTags) + resourceTags, tagKeyOrder := convertToOrderedACKTags(existingTags) ignoreSystemTags(resourceTags) - r.ko.Spec.Tags = fromACKTagsWithKeyOrder(resourceTags, tagKeyOrder) + r.ko.Spec.Tags = fromACKTags(resourceTags, tagKeyOrder) } // mirrorAWSTags ensures that AWS tags are included in the desired resource @@ -373,10 +373,10 @@ func mirrorAWSTags(a *resource, b *resource) { var existingDesiredTags []*svcapitypes.Tag existingDesiredTags = a.ko.Spec.Tags existingLatestTags = b.ko.Spec.Tags - desiredTags, desiredTagKeyOrder := toACKTagsWithKeyOrder(existingDesiredTags) - latestTags, _ := toACKTagsWithKeyOrder(existingLatestTags) + desiredTags, desiredTagKeyOrder := convertToOrderedACKTags(existingDesiredTags) + latestTags, _ := convertToOrderedACKTags(existingLatestTags) syncAWSTags(desiredTags, latestTags) - a.ko.Spec.Tags = fromACKTagsWithKeyOrder(desiredTags, desiredTagKeyOrder) + a.ko.Spec.Tags = fromACKTags(desiredTags, desiredTagKeyOrder) } // newResourceManager returns a new struct implementing diff --git a/pkg/resource/domain/tags.go b/pkg/resource/domain/tags.go index 2eb1f1cc..911cf254 100644 --- a/pkg/resource/domain/tags.go +++ b/pkg/resource/domain/tags.go @@ -30,69 +30,38 @@ var ( ACKSystemTags = []string{"services.k8s.aws/namespace", "services.k8s.aws/controller-version"} ) -// ToACKTags converts the tags parameter into 'acktags.Tags' shape. -// This method helps in creating the hub(acktags.Tags) for merging -// default controller tags with existing resource tags. -func ToACKTags(tags []*svcapitypes.Tag) acktags.Tags { - result := acktags.NewTags() - if tags == nil || len(tags) == 0 { - return result - } - - for _, t := range tags { - if t.Key != nil { - if t.Value == nil { - result[*t.Key] = "" - } else { - result[*t.Key] = *t.Value - } - } - } - - return result -} - -// toACKTagsWithKeyOrder converts the tags parameter into 'acktags.Tags' shape. +// convertToOrderedACKTags converts the tags parameter into 'acktags.Tags' shape. // This method helps in creating the hub(acktags.Tags) for merging // default controller tags with existing resource tags. It also returns a slice // of keys maintaining the original key Order when the tags are a list -func toACKTagsWithKeyOrder(tags []*svcapitypes.Tag) (acktags.Tags, []string) { +func convertToOrderedACKTags(tags []*svcapitypes.Tag) (acktags.Tags, []string) { result := acktags.NewTags() keyOrder := []string{} - if tags == nil || len(tags) == 0 { + + if len(tags) == 0 { return result, keyOrder } - for _, t := range tags { if t.Key != nil { keyOrder = append(keyOrder, *t.Key) + if t.Value != nil { + result[*t.Key] = *t.Value + } else { + result[*t.Key] = "" + } } } - result = ToACKTags(tags) return result, keyOrder } -// FromACKTags converts the tags parameter into []*svcapitypes.Tag shape. -// This method helps in setting the tags back inside AWSResource after merging -// default controller tags with existing resource tags. -func FromACKTags(tags acktags.Tags) []*svcapitypes.Tag { - result := []*svcapitypes.Tag{} - for k, v := range tags { - kCopy := k - vCopy := v - tag := svcapitypes.Tag{Key: &kCopy, Value: &vCopy} - result = append(result, &tag) - } - return result -} - -// fromACKTagsWithTagKeys converts the tags parameter into []*svcapitypes.Tag shape. +// fromACKTags converts the tags parameter into []*svcapitypes.Tag shape. // This method helps in setting the tags back inside AWSResource after merging // default controller tags with existing resource tags. When a list, // it maintains the order from original -func fromACKTagsWithKeyOrder(tags acktags.Tags, keyOrder []string) []*svcapitypes.Tag { +func fromACKTags(tags acktags.Tags, keyOrder []string) []*svcapitypes.Tag { result := []*svcapitypes.Tag{} + for _, k := range keyOrder { v, ok := tags[k] if ok { @@ -101,7 +70,11 @@ func fromACKTagsWithKeyOrder(tags acktags.Tags, keyOrder []string) []*svcapitype delete(tags, k) } } - result = append(result, FromACKTags(tags)...) + for k, v := range tags { + tag := svcapitypes.Tag{Key: &k, Value: &v} + result = append(result, &tag) + } + return result } diff --git a/pkg/resource/endpoint/manager.go b/pkg/resource/endpoint/manager.go index 4707106b..7100f655 100644 --- a/pkg/resource/endpoint/manager.go +++ b/pkg/resource/endpoint/manager.go @@ -291,9 +291,9 @@ func (rm *resourceManager) EnsureTags( defaultTags := ackrt.GetDefaultTags(&rm.cfg, r.ko, md) var existingTags []*svcapitypes.Tag existingTags = r.ko.Spec.Tags - resourceTags := ToACKTags(existingTags) + resourceTags, keyOrder := convertToOrderedACKTags(existingTags) tags := acktags.Merge(resourceTags, defaultTags) - r.ko.Spec.Tags = FromACKTags(tags) + r.ko.Spec.Tags = fromACKTags(tags, keyOrder) return nil } @@ -310,9 +310,9 @@ func (rm *resourceManager) FilterSystemTags(res acktypes.AWSResource) { } var existingTags []*svcapitypes.Tag existingTags = r.ko.Spec.Tags - resourceTags, tagKeyOrder := toACKTagsWithKeyOrder(existingTags) + resourceTags, tagKeyOrder := convertToOrderedACKTags(existingTags) ignoreSystemTags(resourceTags) - r.ko.Spec.Tags = fromACKTagsWithKeyOrder(resourceTags, tagKeyOrder) + r.ko.Spec.Tags = fromACKTags(resourceTags, tagKeyOrder) } // mirrorAWSTags ensures that AWS tags are included in the desired resource @@ -334,10 +334,10 @@ func mirrorAWSTags(a *resource, b *resource) { var existingDesiredTags []*svcapitypes.Tag existingDesiredTags = a.ko.Spec.Tags existingLatestTags = b.ko.Spec.Tags - desiredTags, desiredTagKeyOrder := toACKTagsWithKeyOrder(existingDesiredTags) - latestTags, _ := toACKTagsWithKeyOrder(existingLatestTags) + desiredTags, desiredTagKeyOrder := convertToOrderedACKTags(existingDesiredTags) + latestTags, _ := convertToOrderedACKTags(existingLatestTags) syncAWSTags(desiredTags, latestTags) - a.ko.Spec.Tags = fromACKTagsWithKeyOrder(desiredTags, desiredTagKeyOrder) + a.ko.Spec.Tags = fromACKTags(desiredTags, desiredTagKeyOrder) } // newResourceManager returns a new struct implementing diff --git a/pkg/resource/endpoint/tags.go b/pkg/resource/endpoint/tags.go index 8dbcb737..23b05dda 100644 --- a/pkg/resource/endpoint/tags.go +++ b/pkg/resource/endpoint/tags.go @@ -30,69 +30,38 @@ var ( ACKSystemTags = []string{"services.k8s.aws/namespace", "services.k8s.aws/controller-version"} ) -// ToACKTags converts the tags parameter into 'acktags.Tags' shape. -// This method helps in creating the hub(acktags.Tags) for merging -// default controller tags with existing resource tags. -func ToACKTags(tags []*svcapitypes.Tag) acktags.Tags { - result := acktags.NewTags() - if tags == nil || len(tags) == 0 { - return result - } - - for _, t := range tags { - if t.Key != nil { - if t.Value == nil { - result[*t.Key] = "" - } else { - result[*t.Key] = *t.Value - } - } - } - - return result -} - -// toACKTagsWithKeyOrder converts the tags parameter into 'acktags.Tags' shape. +// convertToOrderedACKTags converts the tags parameter into 'acktags.Tags' shape. // This method helps in creating the hub(acktags.Tags) for merging // default controller tags with existing resource tags. It also returns a slice // of keys maintaining the original key Order when the tags are a list -func toACKTagsWithKeyOrder(tags []*svcapitypes.Tag) (acktags.Tags, []string) { +func convertToOrderedACKTags(tags []*svcapitypes.Tag) (acktags.Tags, []string) { result := acktags.NewTags() keyOrder := []string{} - if tags == nil || len(tags) == 0 { + + if len(tags) == 0 { return result, keyOrder } - for _, t := range tags { if t.Key != nil { keyOrder = append(keyOrder, *t.Key) + if t.Value != nil { + result[*t.Key] = *t.Value + } else { + result[*t.Key] = "" + } } } - result = ToACKTags(tags) return result, keyOrder } -// FromACKTags converts the tags parameter into []*svcapitypes.Tag shape. -// This method helps in setting the tags back inside AWSResource after merging -// default controller tags with existing resource tags. -func FromACKTags(tags acktags.Tags) []*svcapitypes.Tag { - result := []*svcapitypes.Tag{} - for k, v := range tags { - kCopy := k - vCopy := v - tag := svcapitypes.Tag{Key: &kCopy, Value: &vCopy} - result = append(result, &tag) - } - return result -} - -// fromACKTagsWithTagKeys converts the tags parameter into []*svcapitypes.Tag shape. +// fromACKTags converts the tags parameter into []*svcapitypes.Tag shape. // This method helps in setting the tags back inside AWSResource after merging // default controller tags with existing resource tags. When a list, // it maintains the order from original -func fromACKTagsWithKeyOrder(tags acktags.Tags, keyOrder []string) []*svcapitypes.Tag { +func fromACKTags(tags acktags.Tags, keyOrder []string) []*svcapitypes.Tag { result := []*svcapitypes.Tag{} + for _, k := range keyOrder { v, ok := tags[k] if ok { @@ -101,7 +70,11 @@ func fromACKTagsWithKeyOrder(tags acktags.Tags, keyOrder []string) []*svcapitype delete(tags, k) } } - result = append(result, FromACKTags(tags)...) + for k, v := range tags { + tag := svcapitypes.Tag{Key: &k, Value: &v} + result = append(result, &tag) + } + return result } diff --git a/pkg/resource/endpoint_config/manager.go b/pkg/resource/endpoint_config/manager.go index d2498c4a..4214cba8 100644 --- a/pkg/resource/endpoint_config/manager.go +++ b/pkg/resource/endpoint_config/manager.go @@ -300,9 +300,9 @@ func (rm *resourceManager) EnsureTags( defaultTags := ackrt.GetDefaultTags(&rm.cfg, r.ko, md) var existingTags []*svcapitypes.Tag existingTags = r.ko.Spec.Tags - resourceTags := ToACKTags(existingTags) + resourceTags, keyOrder := convertToOrderedACKTags(existingTags) tags := acktags.Merge(resourceTags, defaultTags) - r.ko.Spec.Tags = FromACKTags(tags) + r.ko.Spec.Tags = fromACKTags(tags, keyOrder) return nil } @@ -319,9 +319,9 @@ func (rm *resourceManager) FilterSystemTags(res acktypes.AWSResource) { } var existingTags []*svcapitypes.Tag existingTags = r.ko.Spec.Tags - resourceTags, tagKeyOrder := toACKTagsWithKeyOrder(existingTags) + resourceTags, tagKeyOrder := convertToOrderedACKTags(existingTags) ignoreSystemTags(resourceTags) - r.ko.Spec.Tags = fromACKTagsWithKeyOrder(resourceTags, tagKeyOrder) + r.ko.Spec.Tags = fromACKTags(resourceTags, tagKeyOrder) } // mirrorAWSTags ensures that AWS tags are included in the desired resource @@ -343,10 +343,10 @@ func mirrorAWSTags(a *resource, b *resource) { var existingDesiredTags []*svcapitypes.Tag existingDesiredTags = a.ko.Spec.Tags existingLatestTags = b.ko.Spec.Tags - desiredTags, desiredTagKeyOrder := toACKTagsWithKeyOrder(existingDesiredTags) - latestTags, _ := toACKTagsWithKeyOrder(existingLatestTags) + desiredTags, desiredTagKeyOrder := convertToOrderedACKTags(existingDesiredTags) + latestTags, _ := convertToOrderedACKTags(existingLatestTags) syncAWSTags(desiredTags, latestTags) - a.ko.Spec.Tags = fromACKTagsWithKeyOrder(desiredTags, desiredTagKeyOrder) + a.ko.Spec.Tags = fromACKTags(desiredTags, desiredTagKeyOrder) } // newResourceManager returns a new struct implementing diff --git a/pkg/resource/endpoint_config/tags.go b/pkg/resource/endpoint_config/tags.go index b14d9b52..ea8560ce 100644 --- a/pkg/resource/endpoint_config/tags.go +++ b/pkg/resource/endpoint_config/tags.go @@ -30,69 +30,38 @@ var ( ACKSystemTags = []string{"services.k8s.aws/namespace", "services.k8s.aws/controller-version"} ) -// ToACKTags converts the tags parameter into 'acktags.Tags' shape. -// This method helps in creating the hub(acktags.Tags) for merging -// default controller tags with existing resource tags. -func ToACKTags(tags []*svcapitypes.Tag) acktags.Tags { - result := acktags.NewTags() - if tags == nil || len(tags) == 0 { - return result - } - - for _, t := range tags { - if t.Key != nil { - if t.Value == nil { - result[*t.Key] = "" - } else { - result[*t.Key] = *t.Value - } - } - } - - return result -} - -// toACKTagsWithKeyOrder converts the tags parameter into 'acktags.Tags' shape. +// convertToOrderedACKTags converts the tags parameter into 'acktags.Tags' shape. // This method helps in creating the hub(acktags.Tags) for merging // default controller tags with existing resource tags. It also returns a slice // of keys maintaining the original key Order when the tags are a list -func toACKTagsWithKeyOrder(tags []*svcapitypes.Tag) (acktags.Tags, []string) { +func convertToOrderedACKTags(tags []*svcapitypes.Tag) (acktags.Tags, []string) { result := acktags.NewTags() keyOrder := []string{} - if tags == nil || len(tags) == 0 { + + if len(tags) == 0 { return result, keyOrder } - for _, t := range tags { if t.Key != nil { keyOrder = append(keyOrder, *t.Key) + if t.Value != nil { + result[*t.Key] = *t.Value + } else { + result[*t.Key] = "" + } } } - result = ToACKTags(tags) return result, keyOrder } -// FromACKTags converts the tags parameter into []*svcapitypes.Tag shape. -// This method helps in setting the tags back inside AWSResource after merging -// default controller tags with existing resource tags. -func FromACKTags(tags acktags.Tags) []*svcapitypes.Tag { - result := []*svcapitypes.Tag{} - for k, v := range tags { - kCopy := k - vCopy := v - tag := svcapitypes.Tag{Key: &kCopy, Value: &vCopy} - result = append(result, &tag) - } - return result -} - -// fromACKTagsWithTagKeys converts the tags parameter into []*svcapitypes.Tag shape. +// fromACKTags converts the tags parameter into []*svcapitypes.Tag shape. // This method helps in setting the tags back inside AWSResource after merging // default controller tags with existing resource tags. When a list, // it maintains the order from original -func fromACKTagsWithKeyOrder(tags acktags.Tags, keyOrder []string) []*svcapitypes.Tag { +func fromACKTags(tags acktags.Tags, keyOrder []string) []*svcapitypes.Tag { result := []*svcapitypes.Tag{} + for _, k := range keyOrder { v, ok := tags[k] if ok { @@ -101,7 +70,11 @@ func fromACKTagsWithKeyOrder(tags acktags.Tags, keyOrder []string) []*svcapitype delete(tags, k) } } - result = append(result, FromACKTags(tags)...) + for k, v := range tags { + tag := svcapitypes.Tag{Key: &k, Value: &v} + result = append(result, &tag) + } + return result } diff --git a/pkg/resource/feature_group/manager.go b/pkg/resource/feature_group/manager.go index 622cb547..a0500ec7 100644 --- a/pkg/resource/feature_group/manager.go +++ b/pkg/resource/feature_group/manager.go @@ -318,9 +318,9 @@ func (rm *resourceManager) EnsureTags( defaultTags := ackrt.GetDefaultTags(&rm.cfg, r.ko, md) var existingTags []*svcapitypes.Tag existingTags = r.ko.Spec.Tags - resourceTags := ToACKTags(existingTags) + resourceTags, keyOrder := convertToOrderedACKTags(existingTags) tags := acktags.Merge(resourceTags, defaultTags) - r.ko.Spec.Tags = FromACKTags(tags) + r.ko.Spec.Tags = fromACKTags(tags, keyOrder) return nil } @@ -337,9 +337,9 @@ func (rm *resourceManager) FilterSystemTags(res acktypes.AWSResource) { } var existingTags []*svcapitypes.Tag existingTags = r.ko.Spec.Tags - resourceTags, tagKeyOrder := toACKTagsWithKeyOrder(existingTags) + resourceTags, tagKeyOrder := convertToOrderedACKTags(existingTags) ignoreSystemTags(resourceTags) - r.ko.Spec.Tags = fromACKTagsWithKeyOrder(resourceTags, tagKeyOrder) + r.ko.Spec.Tags = fromACKTags(resourceTags, tagKeyOrder) } // mirrorAWSTags ensures that AWS tags are included in the desired resource @@ -361,10 +361,10 @@ func mirrorAWSTags(a *resource, b *resource) { var existingDesiredTags []*svcapitypes.Tag existingDesiredTags = a.ko.Spec.Tags existingLatestTags = b.ko.Spec.Tags - desiredTags, desiredTagKeyOrder := toACKTagsWithKeyOrder(existingDesiredTags) - latestTags, _ := toACKTagsWithKeyOrder(existingLatestTags) + desiredTags, desiredTagKeyOrder := convertToOrderedACKTags(existingDesiredTags) + latestTags, _ := convertToOrderedACKTags(existingLatestTags) syncAWSTags(desiredTags, latestTags) - a.ko.Spec.Tags = fromACKTagsWithKeyOrder(desiredTags, desiredTagKeyOrder) + a.ko.Spec.Tags = fromACKTags(desiredTags, desiredTagKeyOrder) } // newResourceManager returns a new struct implementing diff --git a/pkg/resource/feature_group/tags.go b/pkg/resource/feature_group/tags.go index 6b7abf62..de456ad5 100644 --- a/pkg/resource/feature_group/tags.go +++ b/pkg/resource/feature_group/tags.go @@ -30,69 +30,38 @@ var ( ACKSystemTags = []string{"services.k8s.aws/namespace", "services.k8s.aws/controller-version"} ) -// ToACKTags converts the tags parameter into 'acktags.Tags' shape. -// This method helps in creating the hub(acktags.Tags) for merging -// default controller tags with existing resource tags. -func ToACKTags(tags []*svcapitypes.Tag) acktags.Tags { - result := acktags.NewTags() - if tags == nil || len(tags) == 0 { - return result - } - - for _, t := range tags { - if t.Key != nil { - if t.Value == nil { - result[*t.Key] = "" - } else { - result[*t.Key] = *t.Value - } - } - } - - return result -} - -// toACKTagsWithKeyOrder converts the tags parameter into 'acktags.Tags' shape. +// convertToOrderedACKTags converts the tags parameter into 'acktags.Tags' shape. // This method helps in creating the hub(acktags.Tags) for merging // default controller tags with existing resource tags. It also returns a slice // of keys maintaining the original key Order when the tags are a list -func toACKTagsWithKeyOrder(tags []*svcapitypes.Tag) (acktags.Tags, []string) { +func convertToOrderedACKTags(tags []*svcapitypes.Tag) (acktags.Tags, []string) { result := acktags.NewTags() keyOrder := []string{} - if tags == nil || len(tags) == 0 { + + if len(tags) == 0 { return result, keyOrder } - for _, t := range tags { if t.Key != nil { keyOrder = append(keyOrder, *t.Key) + if t.Value != nil { + result[*t.Key] = *t.Value + } else { + result[*t.Key] = "" + } } } - result = ToACKTags(tags) return result, keyOrder } -// FromACKTags converts the tags parameter into []*svcapitypes.Tag shape. -// This method helps in setting the tags back inside AWSResource after merging -// default controller tags with existing resource tags. -func FromACKTags(tags acktags.Tags) []*svcapitypes.Tag { - result := []*svcapitypes.Tag{} - for k, v := range tags { - kCopy := k - vCopy := v - tag := svcapitypes.Tag{Key: &kCopy, Value: &vCopy} - result = append(result, &tag) - } - return result -} - -// fromACKTagsWithTagKeys converts the tags parameter into []*svcapitypes.Tag shape. +// fromACKTags converts the tags parameter into []*svcapitypes.Tag shape. // This method helps in setting the tags back inside AWSResource after merging // default controller tags with existing resource tags. When a list, // it maintains the order from original -func fromACKTagsWithKeyOrder(tags acktags.Tags, keyOrder []string) []*svcapitypes.Tag { +func fromACKTags(tags acktags.Tags, keyOrder []string) []*svcapitypes.Tag { result := []*svcapitypes.Tag{} + for _, k := range keyOrder { v, ok := tags[k] if ok { @@ -101,7 +70,11 @@ func fromACKTagsWithKeyOrder(tags acktags.Tags, keyOrder []string) []*svcapitype delete(tags, k) } } - result = append(result, FromACKTags(tags)...) + for k, v := range tags { + tag := svcapitypes.Tag{Key: &k, Value: &v} + result = append(result, &tag) + } + return result } diff --git a/pkg/resource/hyper_parameter_tuning_job/manager.go b/pkg/resource/hyper_parameter_tuning_job/manager.go index 5e8ccb82..b0a59b18 100644 --- a/pkg/resource/hyper_parameter_tuning_job/manager.go +++ b/pkg/resource/hyper_parameter_tuning_job/manager.go @@ -352,9 +352,9 @@ func (rm *resourceManager) EnsureTags( defaultTags := ackrt.GetDefaultTags(&rm.cfg, r.ko, md) var existingTags []*svcapitypes.Tag existingTags = r.ko.Spec.Tags - resourceTags := ToACKTags(existingTags) + resourceTags, keyOrder := convertToOrderedACKTags(existingTags) tags := acktags.Merge(resourceTags, defaultTags) - r.ko.Spec.Tags = FromACKTags(tags) + r.ko.Spec.Tags = fromACKTags(tags, keyOrder) return nil } @@ -371,9 +371,9 @@ func (rm *resourceManager) FilterSystemTags(res acktypes.AWSResource) { } var existingTags []*svcapitypes.Tag existingTags = r.ko.Spec.Tags - resourceTags, tagKeyOrder := toACKTagsWithKeyOrder(existingTags) + resourceTags, tagKeyOrder := convertToOrderedACKTags(existingTags) ignoreSystemTags(resourceTags) - r.ko.Spec.Tags = fromACKTagsWithKeyOrder(resourceTags, tagKeyOrder) + r.ko.Spec.Tags = fromACKTags(resourceTags, tagKeyOrder) } // mirrorAWSTags ensures that AWS tags are included in the desired resource @@ -395,10 +395,10 @@ func mirrorAWSTags(a *resource, b *resource) { var existingDesiredTags []*svcapitypes.Tag existingDesiredTags = a.ko.Spec.Tags existingLatestTags = b.ko.Spec.Tags - desiredTags, desiredTagKeyOrder := toACKTagsWithKeyOrder(existingDesiredTags) - latestTags, _ := toACKTagsWithKeyOrder(existingLatestTags) + desiredTags, desiredTagKeyOrder := convertToOrderedACKTags(existingDesiredTags) + latestTags, _ := convertToOrderedACKTags(existingLatestTags) syncAWSTags(desiredTags, latestTags) - a.ko.Spec.Tags = fromACKTagsWithKeyOrder(desiredTags, desiredTagKeyOrder) + a.ko.Spec.Tags = fromACKTags(desiredTags, desiredTagKeyOrder) } // newResourceManager returns a new struct implementing diff --git a/pkg/resource/hyper_parameter_tuning_job/tags.go b/pkg/resource/hyper_parameter_tuning_job/tags.go index c068abca..fc1d85a4 100644 --- a/pkg/resource/hyper_parameter_tuning_job/tags.go +++ b/pkg/resource/hyper_parameter_tuning_job/tags.go @@ -30,69 +30,38 @@ var ( ACKSystemTags = []string{"services.k8s.aws/namespace", "services.k8s.aws/controller-version"} ) -// ToACKTags converts the tags parameter into 'acktags.Tags' shape. -// This method helps in creating the hub(acktags.Tags) for merging -// default controller tags with existing resource tags. -func ToACKTags(tags []*svcapitypes.Tag) acktags.Tags { - result := acktags.NewTags() - if tags == nil || len(tags) == 0 { - return result - } - - for _, t := range tags { - if t.Key != nil { - if t.Value == nil { - result[*t.Key] = "" - } else { - result[*t.Key] = *t.Value - } - } - } - - return result -} - -// toACKTagsWithKeyOrder converts the tags parameter into 'acktags.Tags' shape. +// convertToOrderedACKTags converts the tags parameter into 'acktags.Tags' shape. // This method helps in creating the hub(acktags.Tags) for merging // default controller tags with existing resource tags. It also returns a slice // of keys maintaining the original key Order when the tags are a list -func toACKTagsWithKeyOrder(tags []*svcapitypes.Tag) (acktags.Tags, []string) { +func convertToOrderedACKTags(tags []*svcapitypes.Tag) (acktags.Tags, []string) { result := acktags.NewTags() keyOrder := []string{} - if tags == nil || len(tags) == 0 { + + if len(tags) == 0 { return result, keyOrder } - for _, t := range tags { if t.Key != nil { keyOrder = append(keyOrder, *t.Key) + if t.Value != nil { + result[*t.Key] = *t.Value + } else { + result[*t.Key] = "" + } } } - result = ToACKTags(tags) return result, keyOrder } -// FromACKTags converts the tags parameter into []*svcapitypes.Tag shape. -// This method helps in setting the tags back inside AWSResource after merging -// default controller tags with existing resource tags. -func FromACKTags(tags acktags.Tags) []*svcapitypes.Tag { - result := []*svcapitypes.Tag{} - for k, v := range tags { - kCopy := k - vCopy := v - tag := svcapitypes.Tag{Key: &kCopy, Value: &vCopy} - result = append(result, &tag) - } - return result -} - -// fromACKTagsWithTagKeys converts the tags parameter into []*svcapitypes.Tag shape. +// fromACKTags converts the tags parameter into []*svcapitypes.Tag shape. // This method helps in setting the tags back inside AWSResource after merging // default controller tags with existing resource tags. When a list, // it maintains the order from original -func fromACKTagsWithKeyOrder(tags acktags.Tags, keyOrder []string) []*svcapitypes.Tag { +func fromACKTags(tags acktags.Tags, keyOrder []string) []*svcapitypes.Tag { result := []*svcapitypes.Tag{} + for _, k := range keyOrder { v, ok := tags[k] if ok { @@ -101,7 +70,11 @@ func fromACKTagsWithKeyOrder(tags acktags.Tags, keyOrder []string) []*svcapitype delete(tags, k) } } - result = append(result, FromACKTags(tags)...) + for k, v := range tags { + tag := svcapitypes.Tag{Key: &k, Value: &v} + result = append(result, &tag) + } + return result } diff --git a/pkg/resource/inference_component/manager.go b/pkg/resource/inference_component/manager.go index 533bc051..f2403cdd 100644 --- a/pkg/resource/inference_component/manager.go +++ b/pkg/resource/inference_component/manager.go @@ -291,9 +291,9 @@ func (rm *resourceManager) EnsureTags( defaultTags := ackrt.GetDefaultTags(&rm.cfg, r.ko, md) var existingTags []*svcapitypes.Tag existingTags = r.ko.Spec.Tags - resourceTags := ToACKTags(existingTags) + resourceTags, keyOrder := convertToOrderedACKTags(existingTags) tags := acktags.Merge(resourceTags, defaultTags) - r.ko.Spec.Tags = FromACKTags(tags) + r.ko.Spec.Tags = fromACKTags(tags, keyOrder) return nil } @@ -310,9 +310,9 @@ func (rm *resourceManager) FilterSystemTags(res acktypes.AWSResource) { } var existingTags []*svcapitypes.Tag existingTags = r.ko.Spec.Tags - resourceTags, tagKeyOrder := toACKTagsWithKeyOrder(existingTags) + resourceTags, tagKeyOrder := convertToOrderedACKTags(existingTags) ignoreSystemTags(resourceTags) - r.ko.Spec.Tags = fromACKTagsWithKeyOrder(resourceTags, tagKeyOrder) + r.ko.Spec.Tags = fromACKTags(resourceTags, tagKeyOrder) } // mirrorAWSTags ensures that AWS tags are included in the desired resource @@ -334,10 +334,10 @@ func mirrorAWSTags(a *resource, b *resource) { var existingDesiredTags []*svcapitypes.Tag existingDesiredTags = a.ko.Spec.Tags existingLatestTags = b.ko.Spec.Tags - desiredTags, desiredTagKeyOrder := toACKTagsWithKeyOrder(existingDesiredTags) - latestTags, _ := toACKTagsWithKeyOrder(existingLatestTags) + desiredTags, desiredTagKeyOrder := convertToOrderedACKTags(existingDesiredTags) + latestTags, _ := convertToOrderedACKTags(existingLatestTags) syncAWSTags(desiredTags, latestTags) - a.ko.Spec.Tags = fromACKTagsWithKeyOrder(desiredTags, desiredTagKeyOrder) + a.ko.Spec.Tags = fromACKTags(desiredTags, desiredTagKeyOrder) } // newResourceManager returns a new struct implementing diff --git a/pkg/resource/inference_component/tags.go b/pkg/resource/inference_component/tags.go index 5de00f8f..d0d50974 100644 --- a/pkg/resource/inference_component/tags.go +++ b/pkg/resource/inference_component/tags.go @@ -30,69 +30,38 @@ var ( ACKSystemTags = []string{"services.k8s.aws/namespace", "services.k8s.aws/controller-version"} ) -// ToACKTags converts the tags parameter into 'acktags.Tags' shape. -// This method helps in creating the hub(acktags.Tags) for merging -// default controller tags with existing resource tags. -func ToACKTags(tags []*svcapitypes.Tag) acktags.Tags { - result := acktags.NewTags() - if tags == nil || len(tags) == 0 { - return result - } - - for _, t := range tags { - if t.Key != nil { - if t.Value == nil { - result[*t.Key] = "" - } else { - result[*t.Key] = *t.Value - } - } - } - - return result -} - -// toACKTagsWithKeyOrder converts the tags parameter into 'acktags.Tags' shape. +// convertToOrderedACKTags converts the tags parameter into 'acktags.Tags' shape. // This method helps in creating the hub(acktags.Tags) for merging // default controller tags with existing resource tags. It also returns a slice // of keys maintaining the original key Order when the tags are a list -func toACKTagsWithKeyOrder(tags []*svcapitypes.Tag) (acktags.Tags, []string) { +func convertToOrderedACKTags(tags []*svcapitypes.Tag) (acktags.Tags, []string) { result := acktags.NewTags() keyOrder := []string{} - if tags == nil || len(tags) == 0 { + + if len(tags) == 0 { return result, keyOrder } - for _, t := range tags { if t.Key != nil { keyOrder = append(keyOrder, *t.Key) + if t.Value != nil { + result[*t.Key] = *t.Value + } else { + result[*t.Key] = "" + } } } - result = ToACKTags(tags) return result, keyOrder } -// FromACKTags converts the tags parameter into []*svcapitypes.Tag shape. -// This method helps in setting the tags back inside AWSResource after merging -// default controller tags with existing resource tags. -func FromACKTags(tags acktags.Tags) []*svcapitypes.Tag { - result := []*svcapitypes.Tag{} - for k, v := range tags { - kCopy := k - vCopy := v - tag := svcapitypes.Tag{Key: &kCopy, Value: &vCopy} - result = append(result, &tag) - } - return result -} - -// fromACKTagsWithTagKeys converts the tags parameter into []*svcapitypes.Tag shape. +// fromACKTags converts the tags parameter into []*svcapitypes.Tag shape. // This method helps in setting the tags back inside AWSResource after merging // default controller tags with existing resource tags. When a list, // it maintains the order from original -func fromACKTagsWithKeyOrder(tags acktags.Tags, keyOrder []string) []*svcapitypes.Tag { +func fromACKTags(tags acktags.Tags, keyOrder []string) []*svcapitypes.Tag { result := []*svcapitypes.Tag{} + for _, k := range keyOrder { v, ok := tags[k] if ok { @@ -101,7 +70,11 @@ func fromACKTagsWithKeyOrder(tags acktags.Tags, keyOrder []string) []*svcapitype delete(tags, k) } } - result = append(result, FromACKTags(tags)...) + for k, v := range tags { + tag := svcapitypes.Tag{Key: &k, Value: &v} + result = append(result, &tag) + } + return result } diff --git a/pkg/resource/model/manager.go b/pkg/resource/model/manager.go index 432143ab..d2091a2b 100644 --- a/pkg/resource/model/manager.go +++ b/pkg/resource/model/manager.go @@ -300,9 +300,9 @@ func (rm *resourceManager) EnsureTags( defaultTags := ackrt.GetDefaultTags(&rm.cfg, r.ko, md) var existingTags []*svcapitypes.Tag existingTags = r.ko.Spec.Tags - resourceTags := ToACKTags(existingTags) + resourceTags, keyOrder := convertToOrderedACKTags(existingTags) tags := acktags.Merge(resourceTags, defaultTags) - r.ko.Spec.Tags = FromACKTags(tags) + r.ko.Spec.Tags = fromACKTags(tags, keyOrder) return nil } @@ -319,9 +319,9 @@ func (rm *resourceManager) FilterSystemTags(res acktypes.AWSResource) { } var existingTags []*svcapitypes.Tag existingTags = r.ko.Spec.Tags - resourceTags, tagKeyOrder := toACKTagsWithKeyOrder(existingTags) + resourceTags, tagKeyOrder := convertToOrderedACKTags(existingTags) ignoreSystemTags(resourceTags) - r.ko.Spec.Tags = fromACKTagsWithKeyOrder(resourceTags, tagKeyOrder) + r.ko.Spec.Tags = fromACKTags(resourceTags, tagKeyOrder) } // mirrorAWSTags ensures that AWS tags are included in the desired resource @@ -343,10 +343,10 @@ func mirrorAWSTags(a *resource, b *resource) { var existingDesiredTags []*svcapitypes.Tag existingDesiredTags = a.ko.Spec.Tags existingLatestTags = b.ko.Spec.Tags - desiredTags, desiredTagKeyOrder := toACKTagsWithKeyOrder(existingDesiredTags) - latestTags, _ := toACKTagsWithKeyOrder(existingLatestTags) + desiredTags, desiredTagKeyOrder := convertToOrderedACKTags(existingDesiredTags) + latestTags, _ := convertToOrderedACKTags(existingLatestTags) syncAWSTags(desiredTags, latestTags) - a.ko.Spec.Tags = fromACKTagsWithKeyOrder(desiredTags, desiredTagKeyOrder) + a.ko.Spec.Tags = fromACKTags(desiredTags, desiredTagKeyOrder) } // newResourceManager returns a new struct implementing diff --git a/pkg/resource/model/tags.go b/pkg/resource/model/tags.go index 4ad5a464..8038b5b6 100644 --- a/pkg/resource/model/tags.go +++ b/pkg/resource/model/tags.go @@ -30,69 +30,38 @@ var ( ACKSystemTags = []string{"services.k8s.aws/namespace", "services.k8s.aws/controller-version"} ) -// ToACKTags converts the tags parameter into 'acktags.Tags' shape. -// This method helps in creating the hub(acktags.Tags) for merging -// default controller tags with existing resource tags. -func ToACKTags(tags []*svcapitypes.Tag) acktags.Tags { - result := acktags.NewTags() - if tags == nil || len(tags) == 0 { - return result - } - - for _, t := range tags { - if t.Key != nil { - if t.Value == nil { - result[*t.Key] = "" - } else { - result[*t.Key] = *t.Value - } - } - } - - return result -} - -// toACKTagsWithKeyOrder converts the tags parameter into 'acktags.Tags' shape. +// convertToOrderedACKTags converts the tags parameter into 'acktags.Tags' shape. // This method helps in creating the hub(acktags.Tags) for merging // default controller tags with existing resource tags. It also returns a slice // of keys maintaining the original key Order when the tags are a list -func toACKTagsWithKeyOrder(tags []*svcapitypes.Tag) (acktags.Tags, []string) { +func convertToOrderedACKTags(tags []*svcapitypes.Tag) (acktags.Tags, []string) { result := acktags.NewTags() keyOrder := []string{} - if tags == nil || len(tags) == 0 { + + if len(tags) == 0 { return result, keyOrder } - for _, t := range tags { if t.Key != nil { keyOrder = append(keyOrder, *t.Key) + if t.Value != nil { + result[*t.Key] = *t.Value + } else { + result[*t.Key] = "" + } } } - result = ToACKTags(tags) return result, keyOrder } -// FromACKTags converts the tags parameter into []*svcapitypes.Tag shape. -// This method helps in setting the tags back inside AWSResource after merging -// default controller tags with existing resource tags. -func FromACKTags(tags acktags.Tags) []*svcapitypes.Tag { - result := []*svcapitypes.Tag{} - for k, v := range tags { - kCopy := k - vCopy := v - tag := svcapitypes.Tag{Key: &kCopy, Value: &vCopy} - result = append(result, &tag) - } - return result -} - -// fromACKTagsWithTagKeys converts the tags parameter into []*svcapitypes.Tag shape. +// fromACKTags converts the tags parameter into []*svcapitypes.Tag shape. // This method helps in setting the tags back inside AWSResource after merging // default controller tags with existing resource tags. When a list, // it maintains the order from original -func fromACKTagsWithKeyOrder(tags acktags.Tags, keyOrder []string) []*svcapitypes.Tag { +func fromACKTags(tags acktags.Tags, keyOrder []string) []*svcapitypes.Tag { result := []*svcapitypes.Tag{} + for _, k := range keyOrder { v, ok := tags[k] if ok { @@ -101,7 +70,11 @@ func fromACKTagsWithKeyOrder(tags acktags.Tags, keyOrder []string) []*svcapitype delete(tags, k) } } - result = append(result, FromACKTags(tags)...) + for k, v := range tags { + tag := svcapitypes.Tag{Key: &k, Value: &v} + result = append(result, &tag) + } + return result } diff --git a/pkg/resource/model_bias_job_definition/manager.go b/pkg/resource/model_bias_job_definition/manager.go index 55e1d139..835a8792 100644 --- a/pkg/resource/model_bias_job_definition/manager.go +++ b/pkg/resource/model_bias_job_definition/manager.go @@ -291,9 +291,9 @@ func (rm *resourceManager) EnsureTags( defaultTags := ackrt.GetDefaultTags(&rm.cfg, r.ko, md) var existingTags []*svcapitypes.Tag existingTags = r.ko.Spec.Tags - resourceTags := ToACKTags(existingTags) + resourceTags, keyOrder := convertToOrderedACKTags(existingTags) tags := acktags.Merge(resourceTags, defaultTags) - r.ko.Spec.Tags = FromACKTags(tags) + r.ko.Spec.Tags = fromACKTags(tags, keyOrder) return nil } @@ -310,9 +310,9 @@ func (rm *resourceManager) FilterSystemTags(res acktypes.AWSResource) { } var existingTags []*svcapitypes.Tag existingTags = r.ko.Spec.Tags - resourceTags, tagKeyOrder := toACKTagsWithKeyOrder(existingTags) + resourceTags, tagKeyOrder := convertToOrderedACKTags(existingTags) ignoreSystemTags(resourceTags) - r.ko.Spec.Tags = fromACKTagsWithKeyOrder(resourceTags, tagKeyOrder) + r.ko.Spec.Tags = fromACKTags(resourceTags, tagKeyOrder) } // mirrorAWSTags ensures that AWS tags are included in the desired resource @@ -334,10 +334,10 @@ func mirrorAWSTags(a *resource, b *resource) { var existingDesiredTags []*svcapitypes.Tag existingDesiredTags = a.ko.Spec.Tags existingLatestTags = b.ko.Spec.Tags - desiredTags, desiredTagKeyOrder := toACKTagsWithKeyOrder(existingDesiredTags) - latestTags, _ := toACKTagsWithKeyOrder(existingLatestTags) + desiredTags, desiredTagKeyOrder := convertToOrderedACKTags(existingDesiredTags) + latestTags, _ := convertToOrderedACKTags(existingLatestTags) syncAWSTags(desiredTags, latestTags) - a.ko.Spec.Tags = fromACKTagsWithKeyOrder(desiredTags, desiredTagKeyOrder) + a.ko.Spec.Tags = fromACKTags(desiredTags, desiredTagKeyOrder) } // newResourceManager returns a new struct implementing diff --git a/pkg/resource/model_bias_job_definition/tags.go b/pkg/resource/model_bias_job_definition/tags.go index c7534be5..864d6b86 100644 --- a/pkg/resource/model_bias_job_definition/tags.go +++ b/pkg/resource/model_bias_job_definition/tags.go @@ -30,69 +30,38 @@ var ( ACKSystemTags = []string{"services.k8s.aws/namespace", "services.k8s.aws/controller-version"} ) -// ToACKTags converts the tags parameter into 'acktags.Tags' shape. -// This method helps in creating the hub(acktags.Tags) for merging -// default controller tags with existing resource tags. -func ToACKTags(tags []*svcapitypes.Tag) acktags.Tags { - result := acktags.NewTags() - if tags == nil || len(tags) == 0 { - return result - } - - for _, t := range tags { - if t.Key != nil { - if t.Value == nil { - result[*t.Key] = "" - } else { - result[*t.Key] = *t.Value - } - } - } - - return result -} - -// toACKTagsWithKeyOrder converts the tags parameter into 'acktags.Tags' shape. +// convertToOrderedACKTags converts the tags parameter into 'acktags.Tags' shape. // This method helps in creating the hub(acktags.Tags) for merging // default controller tags with existing resource tags. It also returns a slice // of keys maintaining the original key Order when the tags are a list -func toACKTagsWithKeyOrder(tags []*svcapitypes.Tag) (acktags.Tags, []string) { +func convertToOrderedACKTags(tags []*svcapitypes.Tag) (acktags.Tags, []string) { result := acktags.NewTags() keyOrder := []string{} - if tags == nil || len(tags) == 0 { + + if len(tags) == 0 { return result, keyOrder } - for _, t := range tags { if t.Key != nil { keyOrder = append(keyOrder, *t.Key) + if t.Value != nil { + result[*t.Key] = *t.Value + } else { + result[*t.Key] = "" + } } } - result = ToACKTags(tags) return result, keyOrder } -// FromACKTags converts the tags parameter into []*svcapitypes.Tag shape. -// This method helps in setting the tags back inside AWSResource after merging -// default controller tags with existing resource tags. -func FromACKTags(tags acktags.Tags) []*svcapitypes.Tag { - result := []*svcapitypes.Tag{} - for k, v := range tags { - kCopy := k - vCopy := v - tag := svcapitypes.Tag{Key: &kCopy, Value: &vCopy} - result = append(result, &tag) - } - return result -} - -// fromACKTagsWithTagKeys converts the tags parameter into []*svcapitypes.Tag shape. +// fromACKTags converts the tags parameter into []*svcapitypes.Tag shape. // This method helps in setting the tags back inside AWSResource after merging // default controller tags with existing resource tags. When a list, // it maintains the order from original -func fromACKTagsWithKeyOrder(tags acktags.Tags, keyOrder []string) []*svcapitypes.Tag { +func fromACKTags(tags acktags.Tags, keyOrder []string) []*svcapitypes.Tag { result := []*svcapitypes.Tag{} + for _, k := range keyOrder { v, ok := tags[k] if ok { @@ -101,7 +70,11 @@ func fromACKTagsWithKeyOrder(tags acktags.Tags, keyOrder []string) []*svcapitype delete(tags, k) } } - result = append(result, FromACKTags(tags)...) + for k, v := range tags { + tag := svcapitypes.Tag{Key: &k, Value: &v} + result = append(result, &tag) + } + return result } diff --git a/pkg/resource/model_explainability_job_definition/manager.go b/pkg/resource/model_explainability_job_definition/manager.go index 22bd5f1a..978cec69 100644 --- a/pkg/resource/model_explainability_job_definition/manager.go +++ b/pkg/resource/model_explainability_job_definition/manager.go @@ -291,9 +291,9 @@ func (rm *resourceManager) EnsureTags( defaultTags := ackrt.GetDefaultTags(&rm.cfg, r.ko, md) var existingTags []*svcapitypes.Tag existingTags = r.ko.Spec.Tags - resourceTags := ToACKTags(existingTags) + resourceTags, keyOrder := convertToOrderedACKTags(existingTags) tags := acktags.Merge(resourceTags, defaultTags) - r.ko.Spec.Tags = FromACKTags(tags) + r.ko.Spec.Tags = fromACKTags(tags, keyOrder) return nil } @@ -310,9 +310,9 @@ func (rm *resourceManager) FilterSystemTags(res acktypes.AWSResource) { } var existingTags []*svcapitypes.Tag existingTags = r.ko.Spec.Tags - resourceTags, tagKeyOrder := toACKTagsWithKeyOrder(existingTags) + resourceTags, tagKeyOrder := convertToOrderedACKTags(existingTags) ignoreSystemTags(resourceTags) - r.ko.Spec.Tags = fromACKTagsWithKeyOrder(resourceTags, tagKeyOrder) + r.ko.Spec.Tags = fromACKTags(resourceTags, tagKeyOrder) } // mirrorAWSTags ensures that AWS tags are included in the desired resource @@ -334,10 +334,10 @@ func mirrorAWSTags(a *resource, b *resource) { var existingDesiredTags []*svcapitypes.Tag existingDesiredTags = a.ko.Spec.Tags existingLatestTags = b.ko.Spec.Tags - desiredTags, desiredTagKeyOrder := toACKTagsWithKeyOrder(existingDesiredTags) - latestTags, _ := toACKTagsWithKeyOrder(existingLatestTags) + desiredTags, desiredTagKeyOrder := convertToOrderedACKTags(existingDesiredTags) + latestTags, _ := convertToOrderedACKTags(existingLatestTags) syncAWSTags(desiredTags, latestTags) - a.ko.Spec.Tags = fromACKTagsWithKeyOrder(desiredTags, desiredTagKeyOrder) + a.ko.Spec.Tags = fromACKTags(desiredTags, desiredTagKeyOrder) } // newResourceManager returns a new struct implementing diff --git a/pkg/resource/model_explainability_job_definition/tags.go b/pkg/resource/model_explainability_job_definition/tags.go index e7d23c0f..3aa3282c 100644 --- a/pkg/resource/model_explainability_job_definition/tags.go +++ b/pkg/resource/model_explainability_job_definition/tags.go @@ -30,69 +30,38 @@ var ( ACKSystemTags = []string{"services.k8s.aws/namespace", "services.k8s.aws/controller-version"} ) -// ToACKTags converts the tags parameter into 'acktags.Tags' shape. -// This method helps in creating the hub(acktags.Tags) for merging -// default controller tags with existing resource tags. -func ToACKTags(tags []*svcapitypes.Tag) acktags.Tags { - result := acktags.NewTags() - if tags == nil || len(tags) == 0 { - return result - } - - for _, t := range tags { - if t.Key != nil { - if t.Value == nil { - result[*t.Key] = "" - } else { - result[*t.Key] = *t.Value - } - } - } - - return result -} - -// toACKTagsWithKeyOrder converts the tags parameter into 'acktags.Tags' shape. +// convertToOrderedACKTags converts the tags parameter into 'acktags.Tags' shape. // This method helps in creating the hub(acktags.Tags) for merging // default controller tags with existing resource tags. It also returns a slice // of keys maintaining the original key Order when the tags are a list -func toACKTagsWithKeyOrder(tags []*svcapitypes.Tag) (acktags.Tags, []string) { +func convertToOrderedACKTags(tags []*svcapitypes.Tag) (acktags.Tags, []string) { result := acktags.NewTags() keyOrder := []string{} - if tags == nil || len(tags) == 0 { + + if len(tags) == 0 { return result, keyOrder } - for _, t := range tags { if t.Key != nil { keyOrder = append(keyOrder, *t.Key) + if t.Value != nil { + result[*t.Key] = *t.Value + } else { + result[*t.Key] = "" + } } } - result = ToACKTags(tags) return result, keyOrder } -// FromACKTags converts the tags parameter into []*svcapitypes.Tag shape. -// This method helps in setting the tags back inside AWSResource after merging -// default controller tags with existing resource tags. -func FromACKTags(tags acktags.Tags) []*svcapitypes.Tag { - result := []*svcapitypes.Tag{} - for k, v := range tags { - kCopy := k - vCopy := v - tag := svcapitypes.Tag{Key: &kCopy, Value: &vCopy} - result = append(result, &tag) - } - return result -} - -// fromACKTagsWithTagKeys converts the tags parameter into []*svcapitypes.Tag shape. +// fromACKTags converts the tags parameter into []*svcapitypes.Tag shape. // This method helps in setting the tags back inside AWSResource after merging // default controller tags with existing resource tags. When a list, // it maintains the order from original -func fromACKTagsWithKeyOrder(tags acktags.Tags, keyOrder []string) []*svcapitypes.Tag { +func fromACKTags(tags acktags.Tags, keyOrder []string) []*svcapitypes.Tag { result := []*svcapitypes.Tag{} + for _, k := range keyOrder { v, ok := tags[k] if ok { @@ -101,7 +70,11 @@ func fromACKTagsWithKeyOrder(tags acktags.Tags, keyOrder []string) []*svcapitype delete(tags, k) } } - result = append(result, FromACKTags(tags)...) + for k, v := range tags { + tag := svcapitypes.Tag{Key: &k, Value: &v} + result = append(result, &tag) + } + return result } diff --git a/pkg/resource/model_package_group/manager.go b/pkg/resource/model_package_group/manager.go index d84cb3de..9c81c565 100644 --- a/pkg/resource/model_package_group/manager.go +++ b/pkg/resource/model_package_group/manager.go @@ -291,9 +291,9 @@ func (rm *resourceManager) EnsureTags( defaultTags := ackrt.GetDefaultTags(&rm.cfg, r.ko, md) var existingTags []*svcapitypes.Tag existingTags = r.ko.Spec.Tags - resourceTags := ToACKTags(existingTags) + resourceTags, keyOrder := convertToOrderedACKTags(existingTags) tags := acktags.Merge(resourceTags, defaultTags) - r.ko.Spec.Tags = FromACKTags(tags) + r.ko.Spec.Tags = fromACKTags(tags, keyOrder) return nil } @@ -310,9 +310,9 @@ func (rm *resourceManager) FilterSystemTags(res acktypes.AWSResource) { } var existingTags []*svcapitypes.Tag existingTags = r.ko.Spec.Tags - resourceTags, tagKeyOrder := toACKTagsWithKeyOrder(existingTags) + resourceTags, tagKeyOrder := convertToOrderedACKTags(existingTags) ignoreSystemTags(resourceTags) - r.ko.Spec.Tags = fromACKTagsWithKeyOrder(resourceTags, tagKeyOrder) + r.ko.Spec.Tags = fromACKTags(resourceTags, tagKeyOrder) } // mirrorAWSTags ensures that AWS tags are included in the desired resource @@ -334,10 +334,10 @@ func mirrorAWSTags(a *resource, b *resource) { var existingDesiredTags []*svcapitypes.Tag existingDesiredTags = a.ko.Spec.Tags existingLatestTags = b.ko.Spec.Tags - desiredTags, desiredTagKeyOrder := toACKTagsWithKeyOrder(existingDesiredTags) - latestTags, _ := toACKTagsWithKeyOrder(existingLatestTags) + desiredTags, desiredTagKeyOrder := convertToOrderedACKTags(existingDesiredTags) + latestTags, _ := convertToOrderedACKTags(existingLatestTags) syncAWSTags(desiredTags, latestTags) - a.ko.Spec.Tags = fromACKTagsWithKeyOrder(desiredTags, desiredTagKeyOrder) + a.ko.Spec.Tags = fromACKTags(desiredTags, desiredTagKeyOrder) } // newResourceManager returns a new struct implementing diff --git a/pkg/resource/model_package_group/tags.go b/pkg/resource/model_package_group/tags.go index 7d9173aa..b4d7b031 100644 --- a/pkg/resource/model_package_group/tags.go +++ b/pkg/resource/model_package_group/tags.go @@ -30,69 +30,38 @@ var ( ACKSystemTags = []string{"services.k8s.aws/namespace", "services.k8s.aws/controller-version"} ) -// ToACKTags converts the tags parameter into 'acktags.Tags' shape. -// This method helps in creating the hub(acktags.Tags) for merging -// default controller tags with existing resource tags. -func ToACKTags(tags []*svcapitypes.Tag) acktags.Tags { - result := acktags.NewTags() - if tags == nil || len(tags) == 0 { - return result - } - - for _, t := range tags { - if t.Key != nil { - if t.Value == nil { - result[*t.Key] = "" - } else { - result[*t.Key] = *t.Value - } - } - } - - return result -} - -// toACKTagsWithKeyOrder converts the tags parameter into 'acktags.Tags' shape. +// convertToOrderedACKTags converts the tags parameter into 'acktags.Tags' shape. // This method helps in creating the hub(acktags.Tags) for merging // default controller tags with existing resource tags. It also returns a slice // of keys maintaining the original key Order when the tags are a list -func toACKTagsWithKeyOrder(tags []*svcapitypes.Tag) (acktags.Tags, []string) { +func convertToOrderedACKTags(tags []*svcapitypes.Tag) (acktags.Tags, []string) { result := acktags.NewTags() keyOrder := []string{} - if tags == nil || len(tags) == 0 { + + if len(tags) == 0 { return result, keyOrder } - for _, t := range tags { if t.Key != nil { keyOrder = append(keyOrder, *t.Key) + if t.Value != nil { + result[*t.Key] = *t.Value + } else { + result[*t.Key] = "" + } } } - result = ToACKTags(tags) return result, keyOrder } -// FromACKTags converts the tags parameter into []*svcapitypes.Tag shape. -// This method helps in setting the tags back inside AWSResource after merging -// default controller tags with existing resource tags. -func FromACKTags(tags acktags.Tags) []*svcapitypes.Tag { - result := []*svcapitypes.Tag{} - for k, v := range tags { - kCopy := k - vCopy := v - tag := svcapitypes.Tag{Key: &kCopy, Value: &vCopy} - result = append(result, &tag) - } - return result -} - -// fromACKTagsWithTagKeys converts the tags parameter into []*svcapitypes.Tag shape. +// fromACKTags converts the tags parameter into []*svcapitypes.Tag shape. // This method helps in setting the tags back inside AWSResource after merging // default controller tags with existing resource tags. When a list, // it maintains the order from original -func fromACKTagsWithKeyOrder(tags acktags.Tags, keyOrder []string) []*svcapitypes.Tag { +func fromACKTags(tags acktags.Tags, keyOrder []string) []*svcapitypes.Tag { result := []*svcapitypes.Tag{} + for _, k := range keyOrder { v, ok := tags[k] if ok { @@ -101,7 +70,11 @@ func fromACKTagsWithKeyOrder(tags acktags.Tags, keyOrder []string) []*svcapitype delete(tags, k) } } - result = append(result, FromACKTags(tags)...) + for k, v := range tags { + tag := svcapitypes.Tag{Key: &k, Value: &v} + result = append(result, &tag) + } + return result } diff --git a/pkg/resource/model_quality_job_definition/manager.go b/pkg/resource/model_quality_job_definition/manager.go index 7130dac2..6b766a1d 100644 --- a/pkg/resource/model_quality_job_definition/manager.go +++ b/pkg/resource/model_quality_job_definition/manager.go @@ -291,9 +291,9 @@ func (rm *resourceManager) EnsureTags( defaultTags := ackrt.GetDefaultTags(&rm.cfg, r.ko, md) var existingTags []*svcapitypes.Tag existingTags = r.ko.Spec.Tags - resourceTags := ToACKTags(existingTags) + resourceTags, keyOrder := convertToOrderedACKTags(existingTags) tags := acktags.Merge(resourceTags, defaultTags) - r.ko.Spec.Tags = FromACKTags(tags) + r.ko.Spec.Tags = fromACKTags(tags, keyOrder) return nil } @@ -310,9 +310,9 @@ func (rm *resourceManager) FilterSystemTags(res acktypes.AWSResource) { } var existingTags []*svcapitypes.Tag existingTags = r.ko.Spec.Tags - resourceTags, tagKeyOrder := toACKTagsWithKeyOrder(existingTags) + resourceTags, tagKeyOrder := convertToOrderedACKTags(existingTags) ignoreSystemTags(resourceTags) - r.ko.Spec.Tags = fromACKTagsWithKeyOrder(resourceTags, tagKeyOrder) + r.ko.Spec.Tags = fromACKTags(resourceTags, tagKeyOrder) } // mirrorAWSTags ensures that AWS tags are included in the desired resource @@ -334,10 +334,10 @@ func mirrorAWSTags(a *resource, b *resource) { var existingDesiredTags []*svcapitypes.Tag existingDesiredTags = a.ko.Spec.Tags existingLatestTags = b.ko.Spec.Tags - desiredTags, desiredTagKeyOrder := toACKTagsWithKeyOrder(existingDesiredTags) - latestTags, _ := toACKTagsWithKeyOrder(existingLatestTags) + desiredTags, desiredTagKeyOrder := convertToOrderedACKTags(existingDesiredTags) + latestTags, _ := convertToOrderedACKTags(existingLatestTags) syncAWSTags(desiredTags, latestTags) - a.ko.Spec.Tags = fromACKTagsWithKeyOrder(desiredTags, desiredTagKeyOrder) + a.ko.Spec.Tags = fromACKTags(desiredTags, desiredTagKeyOrder) } // newResourceManager returns a new struct implementing diff --git a/pkg/resource/model_quality_job_definition/tags.go b/pkg/resource/model_quality_job_definition/tags.go index ffa0aa25..5d4f6c0c 100644 --- a/pkg/resource/model_quality_job_definition/tags.go +++ b/pkg/resource/model_quality_job_definition/tags.go @@ -30,69 +30,38 @@ var ( ACKSystemTags = []string{"services.k8s.aws/namespace", "services.k8s.aws/controller-version"} ) -// ToACKTags converts the tags parameter into 'acktags.Tags' shape. -// This method helps in creating the hub(acktags.Tags) for merging -// default controller tags with existing resource tags. -func ToACKTags(tags []*svcapitypes.Tag) acktags.Tags { - result := acktags.NewTags() - if tags == nil || len(tags) == 0 { - return result - } - - for _, t := range tags { - if t.Key != nil { - if t.Value == nil { - result[*t.Key] = "" - } else { - result[*t.Key] = *t.Value - } - } - } - - return result -} - -// toACKTagsWithKeyOrder converts the tags parameter into 'acktags.Tags' shape. +// convertToOrderedACKTags converts the tags parameter into 'acktags.Tags' shape. // This method helps in creating the hub(acktags.Tags) for merging // default controller tags with existing resource tags. It also returns a slice // of keys maintaining the original key Order when the tags are a list -func toACKTagsWithKeyOrder(tags []*svcapitypes.Tag) (acktags.Tags, []string) { +func convertToOrderedACKTags(tags []*svcapitypes.Tag) (acktags.Tags, []string) { result := acktags.NewTags() keyOrder := []string{} - if tags == nil || len(tags) == 0 { + + if len(tags) == 0 { return result, keyOrder } - for _, t := range tags { if t.Key != nil { keyOrder = append(keyOrder, *t.Key) + if t.Value != nil { + result[*t.Key] = *t.Value + } else { + result[*t.Key] = "" + } } } - result = ToACKTags(tags) return result, keyOrder } -// FromACKTags converts the tags parameter into []*svcapitypes.Tag shape. -// This method helps in setting the tags back inside AWSResource after merging -// default controller tags with existing resource tags. -func FromACKTags(tags acktags.Tags) []*svcapitypes.Tag { - result := []*svcapitypes.Tag{} - for k, v := range tags { - kCopy := k - vCopy := v - tag := svcapitypes.Tag{Key: &kCopy, Value: &vCopy} - result = append(result, &tag) - } - return result -} - -// fromACKTagsWithTagKeys converts the tags parameter into []*svcapitypes.Tag shape. +// fromACKTags converts the tags parameter into []*svcapitypes.Tag shape. // This method helps in setting the tags back inside AWSResource after merging // default controller tags with existing resource tags. When a list, // it maintains the order from original -func fromACKTagsWithKeyOrder(tags acktags.Tags, keyOrder []string) []*svcapitypes.Tag { +func fromACKTags(tags acktags.Tags, keyOrder []string) []*svcapitypes.Tag { result := []*svcapitypes.Tag{} + for _, k := range keyOrder { v, ok := tags[k] if ok { @@ -101,7 +70,11 @@ func fromACKTagsWithKeyOrder(tags acktags.Tags, keyOrder []string) []*svcapitype delete(tags, k) } } - result = append(result, FromACKTags(tags)...) + for k, v := range tags { + tag := svcapitypes.Tag{Key: &k, Value: &v} + result = append(result, &tag) + } + return result } diff --git a/pkg/resource/monitoring_schedule/manager.go b/pkg/resource/monitoring_schedule/manager.go index bff7f877..2e3bb55e 100644 --- a/pkg/resource/monitoring_schedule/manager.go +++ b/pkg/resource/monitoring_schedule/manager.go @@ -291,9 +291,9 @@ func (rm *resourceManager) EnsureTags( defaultTags := ackrt.GetDefaultTags(&rm.cfg, r.ko, md) var existingTags []*svcapitypes.Tag existingTags = r.ko.Spec.Tags - resourceTags := ToACKTags(existingTags) + resourceTags, keyOrder := convertToOrderedACKTags(existingTags) tags := acktags.Merge(resourceTags, defaultTags) - r.ko.Spec.Tags = FromACKTags(tags) + r.ko.Spec.Tags = fromACKTags(tags, keyOrder) return nil } @@ -310,9 +310,9 @@ func (rm *resourceManager) FilterSystemTags(res acktypes.AWSResource) { } var existingTags []*svcapitypes.Tag existingTags = r.ko.Spec.Tags - resourceTags, tagKeyOrder := toACKTagsWithKeyOrder(existingTags) + resourceTags, tagKeyOrder := convertToOrderedACKTags(existingTags) ignoreSystemTags(resourceTags) - r.ko.Spec.Tags = fromACKTagsWithKeyOrder(resourceTags, tagKeyOrder) + r.ko.Spec.Tags = fromACKTags(resourceTags, tagKeyOrder) } // mirrorAWSTags ensures that AWS tags are included in the desired resource @@ -334,10 +334,10 @@ func mirrorAWSTags(a *resource, b *resource) { var existingDesiredTags []*svcapitypes.Tag existingDesiredTags = a.ko.Spec.Tags existingLatestTags = b.ko.Spec.Tags - desiredTags, desiredTagKeyOrder := toACKTagsWithKeyOrder(existingDesiredTags) - latestTags, _ := toACKTagsWithKeyOrder(existingLatestTags) + desiredTags, desiredTagKeyOrder := convertToOrderedACKTags(existingDesiredTags) + latestTags, _ := convertToOrderedACKTags(existingLatestTags) syncAWSTags(desiredTags, latestTags) - a.ko.Spec.Tags = fromACKTagsWithKeyOrder(desiredTags, desiredTagKeyOrder) + a.ko.Spec.Tags = fromACKTags(desiredTags, desiredTagKeyOrder) } // newResourceManager returns a new struct implementing diff --git a/pkg/resource/monitoring_schedule/tags.go b/pkg/resource/monitoring_schedule/tags.go index 698f8adf..04eca51b 100644 --- a/pkg/resource/monitoring_schedule/tags.go +++ b/pkg/resource/monitoring_schedule/tags.go @@ -30,69 +30,38 @@ var ( ACKSystemTags = []string{"services.k8s.aws/namespace", "services.k8s.aws/controller-version"} ) -// ToACKTags converts the tags parameter into 'acktags.Tags' shape. -// This method helps in creating the hub(acktags.Tags) for merging -// default controller tags with existing resource tags. -func ToACKTags(tags []*svcapitypes.Tag) acktags.Tags { - result := acktags.NewTags() - if tags == nil || len(tags) == 0 { - return result - } - - for _, t := range tags { - if t.Key != nil { - if t.Value == nil { - result[*t.Key] = "" - } else { - result[*t.Key] = *t.Value - } - } - } - - return result -} - -// toACKTagsWithKeyOrder converts the tags parameter into 'acktags.Tags' shape. +// convertToOrderedACKTags converts the tags parameter into 'acktags.Tags' shape. // This method helps in creating the hub(acktags.Tags) for merging // default controller tags with existing resource tags. It also returns a slice // of keys maintaining the original key Order when the tags are a list -func toACKTagsWithKeyOrder(tags []*svcapitypes.Tag) (acktags.Tags, []string) { +func convertToOrderedACKTags(tags []*svcapitypes.Tag) (acktags.Tags, []string) { result := acktags.NewTags() keyOrder := []string{} - if tags == nil || len(tags) == 0 { + + if len(tags) == 0 { return result, keyOrder } - for _, t := range tags { if t.Key != nil { keyOrder = append(keyOrder, *t.Key) + if t.Value != nil { + result[*t.Key] = *t.Value + } else { + result[*t.Key] = "" + } } } - result = ToACKTags(tags) return result, keyOrder } -// FromACKTags converts the tags parameter into []*svcapitypes.Tag shape. -// This method helps in setting the tags back inside AWSResource after merging -// default controller tags with existing resource tags. -func FromACKTags(tags acktags.Tags) []*svcapitypes.Tag { - result := []*svcapitypes.Tag{} - for k, v := range tags { - kCopy := k - vCopy := v - tag := svcapitypes.Tag{Key: &kCopy, Value: &vCopy} - result = append(result, &tag) - } - return result -} - -// fromACKTagsWithTagKeys converts the tags parameter into []*svcapitypes.Tag shape. +// fromACKTags converts the tags parameter into []*svcapitypes.Tag shape. // This method helps in setting the tags back inside AWSResource after merging // default controller tags with existing resource tags. When a list, // it maintains the order from original -func fromACKTagsWithKeyOrder(tags acktags.Tags, keyOrder []string) []*svcapitypes.Tag { +func fromACKTags(tags acktags.Tags, keyOrder []string) []*svcapitypes.Tag { result := []*svcapitypes.Tag{} + for _, k := range keyOrder { v, ok := tags[k] if ok { @@ -101,7 +70,11 @@ func fromACKTagsWithKeyOrder(tags acktags.Tags, keyOrder []string) []*svcapitype delete(tags, k) } } - result = append(result, FromACKTags(tags)...) + for k, v := range tags { + tag := svcapitypes.Tag{Key: &k, Value: &v} + result = append(result, &tag) + } + return result } diff --git a/pkg/resource/notebook_instance/manager.go b/pkg/resource/notebook_instance/manager.go index 1419d772..a8799374 100644 --- a/pkg/resource/notebook_instance/manager.go +++ b/pkg/resource/notebook_instance/manager.go @@ -306,9 +306,9 @@ func (rm *resourceManager) EnsureTags( defaultTags := ackrt.GetDefaultTags(&rm.cfg, r.ko, md) var existingTags []*svcapitypes.Tag existingTags = r.ko.Spec.Tags - resourceTags := ToACKTags(existingTags) + resourceTags, keyOrder := convertToOrderedACKTags(existingTags) tags := acktags.Merge(resourceTags, defaultTags) - r.ko.Spec.Tags = FromACKTags(tags) + r.ko.Spec.Tags = fromACKTags(tags, keyOrder) return nil } @@ -325,9 +325,9 @@ func (rm *resourceManager) FilterSystemTags(res acktypes.AWSResource) { } var existingTags []*svcapitypes.Tag existingTags = r.ko.Spec.Tags - resourceTags, tagKeyOrder := toACKTagsWithKeyOrder(existingTags) + resourceTags, tagKeyOrder := convertToOrderedACKTags(existingTags) ignoreSystemTags(resourceTags) - r.ko.Spec.Tags = fromACKTagsWithKeyOrder(resourceTags, tagKeyOrder) + r.ko.Spec.Tags = fromACKTags(resourceTags, tagKeyOrder) } // mirrorAWSTags ensures that AWS tags are included in the desired resource @@ -349,10 +349,10 @@ func mirrorAWSTags(a *resource, b *resource) { var existingDesiredTags []*svcapitypes.Tag existingDesiredTags = a.ko.Spec.Tags existingLatestTags = b.ko.Spec.Tags - desiredTags, desiredTagKeyOrder := toACKTagsWithKeyOrder(existingDesiredTags) - latestTags, _ := toACKTagsWithKeyOrder(existingLatestTags) + desiredTags, desiredTagKeyOrder := convertToOrderedACKTags(existingDesiredTags) + latestTags, _ := convertToOrderedACKTags(existingLatestTags) syncAWSTags(desiredTags, latestTags) - a.ko.Spec.Tags = fromACKTagsWithKeyOrder(desiredTags, desiredTagKeyOrder) + a.ko.Spec.Tags = fromACKTags(desiredTags, desiredTagKeyOrder) } // newResourceManager returns a new struct implementing diff --git a/pkg/resource/notebook_instance/tags.go b/pkg/resource/notebook_instance/tags.go index 61db48d1..dd35ba45 100644 --- a/pkg/resource/notebook_instance/tags.go +++ b/pkg/resource/notebook_instance/tags.go @@ -30,69 +30,38 @@ var ( ACKSystemTags = []string{"services.k8s.aws/namespace", "services.k8s.aws/controller-version"} ) -// ToACKTags converts the tags parameter into 'acktags.Tags' shape. -// This method helps in creating the hub(acktags.Tags) for merging -// default controller tags with existing resource tags. -func ToACKTags(tags []*svcapitypes.Tag) acktags.Tags { - result := acktags.NewTags() - if tags == nil || len(tags) == 0 { - return result - } - - for _, t := range tags { - if t.Key != nil { - if t.Value == nil { - result[*t.Key] = "" - } else { - result[*t.Key] = *t.Value - } - } - } - - return result -} - -// toACKTagsWithKeyOrder converts the tags parameter into 'acktags.Tags' shape. +// convertToOrderedACKTags converts the tags parameter into 'acktags.Tags' shape. // This method helps in creating the hub(acktags.Tags) for merging // default controller tags with existing resource tags. It also returns a slice // of keys maintaining the original key Order when the tags are a list -func toACKTagsWithKeyOrder(tags []*svcapitypes.Tag) (acktags.Tags, []string) { +func convertToOrderedACKTags(tags []*svcapitypes.Tag) (acktags.Tags, []string) { result := acktags.NewTags() keyOrder := []string{} - if tags == nil || len(tags) == 0 { + + if len(tags) == 0 { return result, keyOrder } - for _, t := range tags { if t.Key != nil { keyOrder = append(keyOrder, *t.Key) + if t.Value != nil { + result[*t.Key] = *t.Value + } else { + result[*t.Key] = "" + } } } - result = ToACKTags(tags) return result, keyOrder } -// FromACKTags converts the tags parameter into []*svcapitypes.Tag shape. -// This method helps in setting the tags back inside AWSResource after merging -// default controller tags with existing resource tags. -func FromACKTags(tags acktags.Tags) []*svcapitypes.Tag { - result := []*svcapitypes.Tag{} - for k, v := range tags { - kCopy := k - vCopy := v - tag := svcapitypes.Tag{Key: &kCopy, Value: &vCopy} - result = append(result, &tag) - } - return result -} - -// fromACKTagsWithTagKeys converts the tags parameter into []*svcapitypes.Tag shape. +// fromACKTags converts the tags parameter into []*svcapitypes.Tag shape. // This method helps in setting the tags back inside AWSResource after merging // default controller tags with existing resource tags. When a list, // it maintains the order from original -func fromACKTagsWithKeyOrder(tags acktags.Tags, keyOrder []string) []*svcapitypes.Tag { +func fromACKTags(tags acktags.Tags, keyOrder []string) []*svcapitypes.Tag { result := []*svcapitypes.Tag{} + for _, k := range keyOrder { v, ok := tags[k] if ok { @@ -101,7 +70,11 @@ func fromACKTagsWithKeyOrder(tags acktags.Tags, keyOrder []string) []*svcapitype delete(tags, k) } } - result = append(result, FromACKTags(tags)...) + for k, v := range tags { + tag := svcapitypes.Tag{Key: &k, Value: &v} + result = append(result, &tag) + } + return result } diff --git a/pkg/resource/pipeline/manager.go b/pkg/resource/pipeline/manager.go index 234be64d..390ac587 100644 --- a/pkg/resource/pipeline/manager.go +++ b/pkg/resource/pipeline/manager.go @@ -291,9 +291,9 @@ func (rm *resourceManager) EnsureTags( defaultTags := ackrt.GetDefaultTags(&rm.cfg, r.ko, md) var existingTags []*svcapitypes.Tag existingTags = r.ko.Spec.Tags - resourceTags := ToACKTags(existingTags) + resourceTags, keyOrder := convertToOrderedACKTags(existingTags) tags := acktags.Merge(resourceTags, defaultTags) - r.ko.Spec.Tags = FromACKTags(tags) + r.ko.Spec.Tags = fromACKTags(tags, keyOrder) return nil } @@ -310,9 +310,9 @@ func (rm *resourceManager) FilterSystemTags(res acktypes.AWSResource) { } var existingTags []*svcapitypes.Tag existingTags = r.ko.Spec.Tags - resourceTags, tagKeyOrder := toACKTagsWithKeyOrder(existingTags) + resourceTags, tagKeyOrder := convertToOrderedACKTags(existingTags) ignoreSystemTags(resourceTags) - r.ko.Spec.Tags = fromACKTagsWithKeyOrder(resourceTags, tagKeyOrder) + r.ko.Spec.Tags = fromACKTags(resourceTags, tagKeyOrder) } // mirrorAWSTags ensures that AWS tags are included in the desired resource @@ -334,10 +334,10 @@ func mirrorAWSTags(a *resource, b *resource) { var existingDesiredTags []*svcapitypes.Tag existingDesiredTags = a.ko.Spec.Tags existingLatestTags = b.ko.Spec.Tags - desiredTags, desiredTagKeyOrder := toACKTagsWithKeyOrder(existingDesiredTags) - latestTags, _ := toACKTagsWithKeyOrder(existingLatestTags) + desiredTags, desiredTagKeyOrder := convertToOrderedACKTags(existingDesiredTags) + latestTags, _ := convertToOrderedACKTags(existingLatestTags) syncAWSTags(desiredTags, latestTags) - a.ko.Spec.Tags = fromACKTagsWithKeyOrder(desiredTags, desiredTagKeyOrder) + a.ko.Spec.Tags = fromACKTags(desiredTags, desiredTagKeyOrder) } // newResourceManager returns a new struct implementing diff --git a/pkg/resource/pipeline/tags.go b/pkg/resource/pipeline/tags.go index 9410d70d..491e12e3 100644 --- a/pkg/resource/pipeline/tags.go +++ b/pkg/resource/pipeline/tags.go @@ -30,69 +30,38 @@ var ( ACKSystemTags = []string{"services.k8s.aws/namespace", "services.k8s.aws/controller-version"} ) -// ToACKTags converts the tags parameter into 'acktags.Tags' shape. -// This method helps in creating the hub(acktags.Tags) for merging -// default controller tags with existing resource tags. -func ToACKTags(tags []*svcapitypes.Tag) acktags.Tags { - result := acktags.NewTags() - if tags == nil || len(tags) == 0 { - return result - } - - for _, t := range tags { - if t.Key != nil { - if t.Value == nil { - result[*t.Key] = "" - } else { - result[*t.Key] = *t.Value - } - } - } - - return result -} - -// toACKTagsWithKeyOrder converts the tags parameter into 'acktags.Tags' shape. +// convertToOrderedACKTags converts the tags parameter into 'acktags.Tags' shape. // This method helps in creating the hub(acktags.Tags) for merging // default controller tags with existing resource tags. It also returns a slice // of keys maintaining the original key Order when the tags are a list -func toACKTagsWithKeyOrder(tags []*svcapitypes.Tag) (acktags.Tags, []string) { +func convertToOrderedACKTags(tags []*svcapitypes.Tag) (acktags.Tags, []string) { result := acktags.NewTags() keyOrder := []string{} - if tags == nil || len(tags) == 0 { + + if len(tags) == 0 { return result, keyOrder } - for _, t := range tags { if t.Key != nil { keyOrder = append(keyOrder, *t.Key) + if t.Value != nil { + result[*t.Key] = *t.Value + } else { + result[*t.Key] = "" + } } } - result = ToACKTags(tags) return result, keyOrder } -// FromACKTags converts the tags parameter into []*svcapitypes.Tag shape. -// This method helps in setting the tags back inside AWSResource after merging -// default controller tags with existing resource tags. -func FromACKTags(tags acktags.Tags) []*svcapitypes.Tag { - result := []*svcapitypes.Tag{} - for k, v := range tags { - kCopy := k - vCopy := v - tag := svcapitypes.Tag{Key: &kCopy, Value: &vCopy} - result = append(result, &tag) - } - return result -} - -// fromACKTagsWithTagKeys converts the tags parameter into []*svcapitypes.Tag shape. +// fromACKTags converts the tags parameter into []*svcapitypes.Tag shape. // This method helps in setting the tags back inside AWSResource after merging // default controller tags with existing resource tags. When a list, // it maintains the order from original -func fromACKTagsWithKeyOrder(tags acktags.Tags, keyOrder []string) []*svcapitypes.Tag { +func fromACKTags(tags acktags.Tags, keyOrder []string) []*svcapitypes.Tag { result := []*svcapitypes.Tag{} + for _, k := range keyOrder { v, ok := tags[k] if ok { @@ -101,7 +70,11 @@ func fromACKTagsWithKeyOrder(tags acktags.Tags, keyOrder []string) []*svcapitype delete(tags, k) } } - result = append(result, FromACKTags(tags)...) + for k, v := range tags { + tag := svcapitypes.Tag{Key: &k, Value: &v} + result = append(result, &tag) + } + return result } diff --git a/pkg/resource/processing_job/manager.go b/pkg/resource/processing_job/manager.go index d3126095..7f43c548 100644 --- a/pkg/resource/processing_job/manager.go +++ b/pkg/resource/processing_job/manager.go @@ -291,9 +291,9 @@ func (rm *resourceManager) EnsureTags( defaultTags := ackrt.GetDefaultTags(&rm.cfg, r.ko, md) var existingTags []*svcapitypes.Tag existingTags = r.ko.Spec.Tags - resourceTags := ToACKTags(existingTags) + resourceTags, keyOrder := convertToOrderedACKTags(existingTags) tags := acktags.Merge(resourceTags, defaultTags) - r.ko.Spec.Tags = FromACKTags(tags) + r.ko.Spec.Tags = fromACKTags(tags, keyOrder) return nil } @@ -310,9 +310,9 @@ func (rm *resourceManager) FilterSystemTags(res acktypes.AWSResource) { } var existingTags []*svcapitypes.Tag existingTags = r.ko.Spec.Tags - resourceTags, tagKeyOrder := toACKTagsWithKeyOrder(existingTags) + resourceTags, tagKeyOrder := convertToOrderedACKTags(existingTags) ignoreSystemTags(resourceTags) - r.ko.Spec.Tags = fromACKTagsWithKeyOrder(resourceTags, tagKeyOrder) + r.ko.Spec.Tags = fromACKTags(resourceTags, tagKeyOrder) } // mirrorAWSTags ensures that AWS tags are included in the desired resource @@ -334,10 +334,10 @@ func mirrorAWSTags(a *resource, b *resource) { var existingDesiredTags []*svcapitypes.Tag existingDesiredTags = a.ko.Spec.Tags existingLatestTags = b.ko.Spec.Tags - desiredTags, desiredTagKeyOrder := toACKTagsWithKeyOrder(existingDesiredTags) - latestTags, _ := toACKTagsWithKeyOrder(existingLatestTags) + desiredTags, desiredTagKeyOrder := convertToOrderedACKTags(existingDesiredTags) + latestTags, _ := convertToOrderedACKTags(existingLatestTags) syncAWSTags(desiredTags, latestTags) - a.ko.Spec.Tags = fromACKTagsWithKeyOrder(desiredTags, desiredTagKeyOrder) + a.ko.Spec.Tags = fromACKTags(desiredTags, desiredTagKeyOrder) } // newResourceManager returns a new struct implementing diff --git a/pkg/resource/processing_job/tags.go b/pkg/resource/processing_job/tags.go index d5b9e5d9..e375d426 100644 --- a/pkg/resource/processing_job/tags.go +++ b/pkg/resource/processing_job/tags.go @@ -30,69 +30,38 @@ var ( ACKSystemTags = []string{"services.k8s.aws/namespace", "services.k8s.aws/controller-version"} ) -// ToACKTags converts the tags parameter into 'acktags.Tags' shape. -// This method helps in creating the hub(acktags.Tags) for merging -// default controller tags with existing resource tags. -func ToACKTags(tags []*svcapitypes.Tag) acktags.Tags { - result := acktags.NewTags() - if tags == nil || len(tags) == 0 { - return result - } - - for _, t := range tags { - if t.Key != nil { - if t.Value == nil { - result[*t.Key] = "" - } else { - result[*t.Key] = *t.Value - } - } - } - - return result -} - -// toACKTagsWithKeyOrder converts the tags parameter into 'acktags.Tags' shape. +// convertToOrderedACKTags converts the tags parameter into 'acktags.Tags' shape. // This method helps in creating the hub(acktags.Tags) for merging // default controller tags with existing resource tags. It also returns a slice // of keys maintaining the original key Order when the tags are a list -func toACKTagsWithKeyOrder(tags []*svcapitypes.Tag) (acktags.Tags, []string) { +func convertToOrderedACKTags(tags []*svcapitypes.Tag) (acktags.Tags, []string) { result := acktags.NewTags() keyOrder := []string{} - if tags == nil || len(tags) == 0 { + + if len(tags) == 0 { return result, keyOrder } - for _, t := range tags { if t.Key != nil { keyOrder = append(keyOrder, *t.Key) + if t.Value != nil { + result[*t.Key] = *t.Value + } else { + result[*t.Key] = "" + } } } - result = ToACKTags(tags) return result, keyOrder } -// FromACKTags converts the tags parameter into []*svcapitypes.Tag shape. -// This method helps in setting the tags back inside AWSResource after merging -// default controller tags with existing resource tags. -func FromACKTags(tags acktags.Tags) []*svcapitypes.Tag { - result := []*svcapitypes.Tag{} - for k, v := range tags { - kCopy := k - vCopy := v - tag := svcapitypes.Tag{Key: &kCopy, Value: &vCopy} - result = append(result, &tag) - } - return result -} - -// fromACKTagsWithTagKeys converts the tags parameter into []*svcapitypes.Tag shape. +// fromACKTags converts the tags parameter into []*svcapitypes.Tag shape. // This method helps in setting the tags back inside AWSResource after merging // default controller tags with existing resource tags. When a list, // it maintains the order from original -func fromACKTagsWithKeyOrder(tags acktags.Tags, keyOrder []string) []*svcapitypes.Tag { +func fromACKTags(tags acktags.Tags, keyOrder []string) []*svcapitypes.Tag { result := []*svcapitypes.Tag{} + for _, k := range keyOrder { v, ok := tags[k] if ok { @@ -101,7 +70,11 @@ func fromACKTagsWithKeyOrder(tags acktags.Tags, keyOrder []string) []*svcapitype delete(tags, k) } } - result = append(result, FromACKTags(tags)...) + for k, v := range tags { + tag := svcapitypes.Tag{Key: &k, Value: &v} + result = append(result, &tag) + } + return result } diff --git a/pkg/resource/training_job/manager.go b/pkg/resource/training_job/manager.go index aa939495..31101f59 100644 --- a/pkg/resource/training_job/manager.go +++ b/pkg/resource/training_job/manager.go @@ -352,9 +352,9 @@ func (rm *resourceManager) EnsureTags( defaultTags := ackrt.GetDefaultTags(&rm.cfg, r.ko, md) var existingTags []*svcapitypes.Tag existingTags = r.ko.Spec.Tags - resourceTags := ToACKTags(existingTags) + resourceTags, keyOrder := convertToOrderedACKTags(existingTags) tags := acktags.Merge(resourceTags, defaultTags) - r.ko.Spec.Tags = FromACKTags(tags) + r.ko.Spec.Tags = fromACKTags(tags, keyOrder) return nil } @@ -371,9 +371,9 @@ func (rm *resourceManager) FilterSystemTags(res acktypes.AWSResource) { } var existingTags []*svcapitypes.Tag existingTags = r.ko.Spec.Tags - resourceTags, tagKeyOrder := toACKTagsWithKeyOrder(existingTags) + resourceTags, tagKeyOrder := convertToOrderedACKTags(existingTags) ignoreSystemTags(resourceTags) - r.ko.Spec.Tags = fromACKTagsWithKeyOrder(resourceTags, tagKeyOrder) + r.ko.Spec.Tags = fromACKTags(resourceTags, tagKeyOrder) } // mirrorAWSTags ensures that AWS tags are included in the desired resource @@ -395,10 +395,10 @@ func mirrorAWSTags(a *resource, b *resource) { var existingDesiredTags []*svcapitypes.Tag existingDesiredTags = a.ko.Spec.Tags existingLatestTags = b.ko.Spec.Tags - desiredTags, desiredTagKeyOrder := toACKTagsWithKeyOrder(existingDesiredTags) - latestTags, _ := toACKTagsWithKeyOrder(existingLatestTags) + desiredTags, desiredTagKeyOrder := convertToOrderedACKTags(existingDesiredTags) + latestTags, _ := convertToOrderedACKTags(existingLatestTags) syncAWSTags(desiredTags, latestTags) - a.ko.Spec.Tags = fromACKTagsWithKeyOrder(desiredTags, desiredTagKeyOrder) + a.ko.Spec.Tags = fromACKTags(desiredTags, desiredTagKeyOrder) } // newResourceManager returns a new struct implementing diff --git a/pkg/resource/training_job/tags.go b/pkg/resource/training_job/tags.go index 34410837..f4e741e1 100644 --- a/pkg/resource/training_job/tags.go +++ b/pkg/resource/training_job/tags.go @@ -30,69 +30,38 @@ var ( ACKSystemTags = []string{"services.k8s.aws/namespace", "services.k8s.aws/controller-version"} ) -// ToACKTags converts the tags parameter into 'acktags.Tags' shape. -// This method helps in creating the hub(acktags.Tags) for merging -// default controller tags with existing resource tags. -func ToACKTags(tags []*svcapitypes.Tag) acktags.Tags { - result := acktags.NewTags() - if tags == nil || len(tags) == 0 { - return result - } - - for _, t := range tags { - if t.Key != nil { - if t.Value == nil { - result[*t.Key] = "" - } else { - result[*t.Key] = *t.Value - } - } - } - - return result -} - -// toACKTagsWithKeyOrder converts the tags parameter into 'acktags.Tags' shape. +// convertToOrderedACKTags converts the tags parameter into 'acktags.Tags' shape. // This method helps in creating the hub(acktags.Tags) for merging // default controller tags with existing resource tags. It also returns a slice // of keys maintaining the original key Order when the tags are a list -func toACKTagsWithKeyOrder(tags []*svcapitypes.Tag) (acktags.Tags, []string) { +func convertToOrderedACKTags(tags []*svcapitypes.Tag) (acktags.Tags, []string) { result := acktags.NewTags() keyOrder := []string{} - if tags == nil || len(tags) == 0 { + + if len(tags) == 0 { return result, keyOrder } - for _, t := range tags { if t.Key != nil { keyOrder = append(keyOrder, *t.Key) + if t.Value != nil { + result[*t.Key] = *t.Value + } else { + result[*t.Key] = "" + } } } - result = ToACKTags(tags) return result, keyOrder } -// FromACKTags converts the tags parameter into []*svcapitypes.Tag shape. -// This method helps in setting the tags back inside AWSResource after merging -// default controller tags with existing resource tags. -func FromACKTags(tags acktags.Tags) []*svcapitypes.Tag { - result := []*svcapitypes.Tag{} - for k, v := range tags { - kCopy := k - vCopy := v - tag := svcapitypes.Tag{Key: &kCopy, Value: &vCopy} - result = append(result, &tag) - } - return result -} - -// fromACKTagsWithTagKeys converts the tags parameter into []*svcapitypes.Tag shape. +// fromACKTags converts the tags parameter into []*svcapitypes.Tag shape. // This method helps in setting the tags back inside AWSResource after merging // default controller tags with existing resource tags. When a list, // it maintains the order from original -func fromACKTagsWithKeyOrder(tags acktags.Tags, keyOrder []string) []*svcapitypes.Tag { +func fromACKTags(tags acktags.Tags, keyOrder []string) []*svcapitypes.Tag { result := []*svcapitypes.Tag{} + for _, k := range keyOrder { v, ok := tags[k] if ok { @@ -101,7 +70,11 @@ func fromACKTagsWithKeyOrder(tags acktags.Tags, keyOrder []string) []*svcapitype delete(tags, k) } } - result = append(result, FromACKTags(tags)...) + for k, v := range tags { + tag := svcapitypes.Tag{Key: &k, Value: &v} + result = append(result, &tag) + } + return result } diff --git a/pkg/resource/transform_job/manager.go b/pkg/resource/transform_job/manager.go index 47c8665c..9e9b0430 100644 --- a/pkg/resource/transform_job/manager.go +++ b/pkg/resource/transform_job/manager.go @@ -314,9 +314,9 @@ func (rm *resourceManager) EnsureTags( defaultTags := ackrt.GetDefaultTags(&rm.cfg, r.ko, md) var existingTags []*svcapitypes.Tag existingTags = r.ko.Spec.Tags - resourceTags := ToACKTags(existingTags) + resourceTags, keyOrder := convertToOrderedACKTags(existingTags) tags := acktags.Merge(resourceTags, defaultTags) - r.ko.Spec.Tags = FromACKTags(tags) + r.ko.Spec.Tags = fromACKTags(tags, keyOrder) return nil } @@ -333,9 +333,9 @@ func (rm *resourceManager) FilterSystemTags(res acktypes.AWSResource) { } var existingTags []*svcapitypes.Tag existingTags = r.ko.Spec.Tags - resourceTags, tagKeyOrder := toACKTagsWithKeyOrder(existingTags) + resourceTags, tagKeyOrder := convertToOrderedACKTags(existingTags) ignoreSystemTags(resourceTags) - r.ko.Spec.Tags = fromACKTagsWithKeyOrder(resourceTags, tagKeyOrder) + r.ko.Spec.Tags = fromACKTags(resourceTags, tagKeyOrder) } // mirrorAWSTags ensures that AWS tags are included in the desired resource @@ -357,10 +357,10 @@ func mirrorAWSTags(a *resource, b *resource) { var existingDesiredTags []*svcapitypes.Tag existingDesiredTags = a.ko.Spec.Tags existingLatestTags = b.ko.Spec.Tags - desiredTags, desiredTagKeyOrder := toACKTagsWithKeyOrder(existingDesiredTags) - latestTags, _ := toACKTagsWithKeyOrder(existingLatestTags) + desiredTags, desiredTagKeyOrder := convertToOrderedACKTags(existingDesiredTags) + latestTags, _ := convertToOrderedACKTags(existingLatestTags) syncAWSTags(desiredTags, latestTags) - a.ko.Spec.Tags = fromACKTagsWithKeyOrder(desiredTags, desiredTagKeyOrder) + a.ko.Spec.Tags = fromACKTags(desiredTags, desiredTagKeyOrder) } // newResourceManager returns a new struct implementing diff --git a/pkg/resource/transform_job/tags.go b/pkg/resource/transform_job/tags.go index f8a8b0d8..0b628e04 100644 --- a/pkg/resource/transform_job/tags.go +++ b/pkg/resource/transform_job/tags.go @@ -30,69 +30,38 @@ var ( ACKSystemTags = []string{"services.k8s.aws/namespace", "services.k8s.aws/controller-version"} ) -// ToACKTags converts the tags parameter into 'acktags.Tags' shape. -// This method helps in creating the hub(acktags.Tags) for merging -// default controller tags with existing resource tags. -func ToACKTags(tags []*svcapitypes.Tag) acktags.Tags { - result := acktags.NewTags() - if tags == nil || len(tags) == 0 { - return result - } - - for _, t := range tags { - if t.Key != nil { - if t.Value == nil { - result[*t.Key] = "" - } else { - result[*t.Key] = *t.Value - } - } - } - - return result -} - -// toACKTagsWithKeyOrder converts the tags parameter into 'acktags.Tags' shape. +// convertToOrderedACKTags converts the tags parameter into 'acktags.Tags' shape. // This method helps in creating the hub(acktags.Tags) for merging // default controller tags with existing resource tags. It also returns a slice // of keys maintaining the original key Order when the tags are a list -func toACKTagsWithKeyOrder(tags []*svcapitypes.Tag) (acktags.Tags, []string) { +func convertToOrderedACKTags(tags []*svcapitypes.Tag) (acktags.Tags, []string) { result := acktags.NewTags() keyOrder := []string{} - if tags == nil || len(tags) == 0 { + + if len(tags) == 0 { return result, keyOrder } - for _, t := range tags { if t.Key != nil { keyOrder = append(keyOrder, *t.Key) + if t.Value != nil { + result[*t.Key] = *t.Value + } else { + result[*t.Key] = "" + } } } - result = ToACKTags(tags) return result, keyOrder } -// FromACKTags converts the tags parameter into []*svcapitypes.Tag shape. -// This method helps in setting the tags back inside AWSResource after merging -// default controller tags with existing resource tags. -func FromACKTags(tags acktags.Tags) []*svcapitypes.Tag { - result := []*svcapitypes.Tag{} - for k, v := range tags { - kCopy := k - vCopy := v - tag := svcapitypes.Tag{Key: &kCopy, Value: &vCopy} - result = append(result, &tag) - } - return result -} - -// fromACKTagsWithTagKeys converts the tags parameter into []*svcapitypes.Tag shape. +// fromACKTags converts the tags parameter into []*svcapitypes.Tag shape. // This method helps in setting the tags back inside AWSResource after merging // default controller tags with existing resource tags. When a list, // it maintains the order from original -func fromACKTagsWithKeyOrder(tags acktags.Tags, keyOrder []string) []*svcapitypes.Tag { +func fromACKTags(tags acktags.Tags, keyOrder []string) []*svcapitypes.Tag { result := []*svcapitypes.Tag{} + for _, k := range keyOrder { v, ok := tags[k] if ok { @@ -101,7 +70,11 @@ func fromACKTagsWithKeyOrder(tags acktags.Tags, keyOrder []string) []*svcapitype delete(tags, k) } } - result = append(result, FromACKTags(tags)...) + for k, v := range tags { + tag := svcapitypes.Tag{Key: &k, Value: &v} + result = append(result, &tag) + } + return result } diff --git a/pkg/resource/user_profile/manager.go b/pkg/resource/user_profile/manager.go index 649dc353..0e744839 100644 --- a/pkg/resource/user_profile/manager.go +++ b/pkg/resource/user_profile/manager.go @@ -304,9 +304,9 @@ func (rm *resourceManager) EnsureTags( defaultTags := ackrt.GetDefaultTags(&rm.cfg, r.ko, md) var existingTags []*svcapitypes.Tag existingTags = r.ko.Spec.Tags - resourceTags := ToACKTags(existingTags) + resourceTags, keyOrder := convertToOrderedACKTags(existingTags) tags := acktags.Merge(resourceTags, defaultTags) - r.ko.Spec.Tags = FromACKTags(tags) + r.ko.Spec.Tags = fromACKTags(tags, keyOrder) return nil } @@ -323,9 +323,9 @@ func (rm *resourceManager) FilterSystemTags(res acktypes.AWSResource) { } var existingTags []*svcapitypes.Tag existingTags = r.ko.Spec.Tags - resourceTags, tagKeyOrder := toACKTagsWithKeyOrder(existingTags) + resourceTags, tagKeyOrder := convertToOrderedACKTags(existingTags) ignoreSystemTags(resourceTags) - r.ko.Spec.Tags = fromACKTagsWithKeyOrder(resourceTags, tagKeyOrder) + r.ko.Spec.Tags = fromACKTags(resourceTags, tagKeyOrder) } // mirrorAWSTags ensures that AWS tags are included in the desired resource @@ -347,10 +347,10 @@ func mirrorAWSTags(a *resource, b *resource) { var existingDesiredTags []*svcapitypes.Tag existingDesiredTags = a.ko.Spec.Tags existingLatestTags = b.ko.Spec.Tags - desiredTags, desiredTagKeyOrder := toACKTagsWithKeyOrder(existingDesiredTags) - latestTags, _ := toACKTagsWithKeyOrder(existingLatestTags) + desiredTags, desiredTagKeyOrder := convertToOrderedACKTags(existingDesiredTags) + latestTags, _ := convertToOrderedACKTags(existingLatestTags) syncAWSTags(desiredTags, latestTags) - a.ko.Spec.Tags = fromACKTagsWithKeyOrder(desiredTags, desiredTagKeyOrder) + a.ko.Spec.Tags = fromACKTags(desiredTags, desiredTagKeyOrder) } // newResourceManager returns a new struct implementing diff --git a/pkg/resource/user_profile/tags.go b/pkg/resource/user_profile/tags.go index 4c920635..a0ce276a 100644 --- a/pkg/resource/user_profile/tags.go +++ b/pkg/resource/user_profile/tags.go @@ -30,69 +30,38 @@ var ( ACKSystemTags = []string{"services.k8s.aws/namespace", "services.k8s.aws/controller-version"} ) -// ToACKTags converts the tags parameter into 'acktags.Tags' shape. -// This method helps in creating the hub(acktags.Tags) for merging -// default controller tags with existing resource tags. -func ToACKTags(tags []*svcapitypes.Tag) acktags.Tags { - result := acktags.NewTags() - if tags == nil || len(tags) == 0 { - return result - } - - for _, t := range tags { - if t.Key != nil { - if t.Value == nil { - result[*t.Key] = "" - } else { - result[*t.Key] = *t.Value - } - } - } - - return result -} - -// toACKTagsWithKeyOrder converts the tags parameter into 'acktags.Tags' shape. +// convertToOrderedACKTags converts the tags parameter into 'acktags.Tags' shape. // This method helps in creating the hub(acktags.Tags) for merging // default controller tags with existing resource tags. It also returns a slice // of keys maintaining the original key Order when the tags are a list -func toACKTagsWithKeyOrder(tags []*svcapitypes.Tag) (acktags.Tags, []string) { +func convertToOrderedACKTags(tags []*svcapitypes.Tag) (acktags.Tags, []string) { result := acktags.NewTags() keyOrder := []string{} - if tags == nil || len(tags) == 0 { + + if len(tags) == 0 { return result, keyOrder } - for _, t := range tags { if t.Key != nil { keyOrder = append(keyOrder, *t.Key) + if t.Value != nil { + result[*t.Key] = *t.Value + } else { + result[*t.Key] = "" + } } } - result = ToACKTags(tags) return result, keyOrder } -// FromACKTags converts the tags parameter into []*svcapitypes.Tag shape. -// This method helps in setting the tags back inside AWSResource after merging -// default controller tags with existing resource tags. -func FromACKTags(tags acktags.Tags) []*svcapitypes.Tag { - result := []*svcapitypes.Tag{} - for k, v := range tags { - kCopy := k - vCopy := v - tag := svcapitypes.Tag{Key: &kCopy, Value: &vCopy} - result = append(result, &tag) - } - return result -} - -// fromACKTagsWithTagKeys converts the tags parameter into []*svcapitypes.Tag shape. +// fromACKTags converts the tags parameter into []*svcapitypes.Tag shape. // This method helps in setting the tags back inside AWSResource after merging // default controller tags with existing resource tags. When a list, // it maintains the order from original -func fromACKTagsWithKeyOrder(tags acktags.Tags, keyOrder []string) []*svcapitypes.Tag { +func fromACKTags(tags acktags.Tags, keyOrder []string) []*svcapitypes.Tag { result := []*svcapitypes.Tag{} + for _, k := range keyOrder { v, ok := tags[k] if ok { @@ -101,7 +70,11 @@ func fromACKTagsWithKeyOrder(tags acktags.Tags, keyOrder []string) []*svcapitype delete(tags, k) } } - result = append(result, FromACKTags(tags)...) + for k, v := range tags { + tag := svcapitypes.Tag{Key: &k, Value: &v} + result = append(result, &tag) + } + return result }