diff --git a/apis/rds/v1alpha1/custom_types.go b/apis/rds/v1alpha1/custom_types.go index 12736d0e09..9e37b902c4 100644 --- a/apis/rds/v1alpha1/custom_types.go +++ b/apis/rds/v1alpha1/custom_types.go @@ -741,6 +741,11 @@ type CustomDBInstanceParameters struct { // deleted. // +optional DeleteAutomatedBackups *bool `json:"deleteAutomatedBackups,omitempty"` + + // TagIgnorePrefixes tells the reconciler to pretend tags with these + // prefixes don't exist during diff/updates. + // +optional + TagIgnorePrefixes []string `json:"tagIgnorePrefixes,omitempty"` } // CustomDBInstanceObservation includes the custom status fields of DBInstance. diff --git a/apis/rds/v1alpha1/zz_generated.deepcopy.go b/apis/rds/v1alpha1/zz_generated.deepcopy.go index b4e061d18f..b459804463 100644 --- a/apis/rds/v1alpha1/zz_generated.deepcopy.go +++ b/apis/rds/v1alpha1/zz_generated.deepcopy.go @@ -728,6 +728,11 @@ func (in *CustomDBInstanceParameters) DeepCopyInto(out *CustomDBInstanceParamete *out = new(bool) **out = **in } + if in.TagIgnorePrefixes != nil { + in, out := &in.TagIgnorePrefixes, &out.TagIgnorePrefixes + *out = make([]string, len(*in)) + copy(*out, *in) + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CustomDBInstanceParameters. diff --git a/package/crds/rds.aws.crossplane.io_dbinstances.yaml b/package/crds/rds.aws.crossplane.io_dbinstances.yaml index 0fcbee3742..6638bd70f1 100644 --- a/package/crds/rds.aws.crossplane.io_dbinstances.yaml +++ b/package/crds/rds.aws.crossplane.io_dbinstances.yaml @@ -1770,6 +1770,11 @@ spec: Default: io1, if the Iops parameter is specified. Otherwise, gp2. type: string + tagIgnorePrefixes: + description: List of tag prefixes to be ignored during reconciliation. + items: + type: string + type: array tags: description: Tags to assign to the DB instance. items: diff --git a/pkg/controller/rds/dbinstance/setup.go b/pkg/controller/rds/dbinstance/setup.go index 027ebf29ad..e1f6bf7ac0 100644 --- a/pkg/controller/rds/dbinstance/setup.go +++ b/pkg/controller/rds/dbinstance/setup.go @@ -534,7 +534,20 @@ func (e *custom) isUpToDate(ctx context.Context, cr *svcapitypes.DBInstance, out cmpopts.IgnoreFields(svcapitypes.CustomDBInstanceParameters{}, "DeleteAutomatedBackups"), ) - e.cache.addTags, e.cache.removeTags = utils.DiffTags(cr.Spec.ForProvider.Tags, db.TagList) + ignore := append([]string{"aws:"}, cr.Spec.ForProvider.TagIgnorePrefixes...) + var observedTags []*svcsdk.Tag + if db.TagList != nil { + for _, tag := range db.TagList { // index discarded with _ + if utils.ShouldIgnore(pointer.StringValue(tag.Key), ignore) { + continue + } + observedTags = append(observedTags, &svcsdk.Tag{ + Key: tag.Key, + Value: tag.Value, + }) + } + } + e.cache.addTags, e.cache.removeTags = utils.DiffTags(cr.Spec.ForProvider.Tags, observedTags) tagsChanged := len(e.cache.addTags) != 0 || len(e.cache.removeTags) != 0 if diff == "" && !maintenanceWindowChanged && !backupWindowChanged && !iopsChanged && !storageThroughputChanged && !versionChanged && !vpcSGsChanged && !dbParameterGroupChanged && !optionGroupChanged && !tagsChanged { diff --git a/pkg/controller/rds/utils/tags.go b/pkg/controller/rds/utils/tags.go index f3da92849a..c0e7160b3a 100644 --- a/pkg/controller/rds/utils/tags.go +++ b/pkg/controller/rds/utils/tags.go @@ -19,6 +19,7 @@ package utils import ( "context" "sort" + "strings" svcsdk "github.com/aws/aws-sdk-go/service/rds" "github.com/aws/aws-sdk-go/service/rds/rdsiface" @@ -35,6 +36,16 @@ const ( errCreateTags = "cannot create tags" ) +// ShouldIgnore returns true if `key` starts with any supplied prefix. +func ShouldIgnore(key string, prefixes []string) bool { + for _, p := range prefixes { + if strings.HasPrefix(key, p) { + return true + } + } + return false +} + // AreTagsUpToDate for spec and resourceName func AreTagsUpToDate(ctx context.Context, client rdsiface.RDSAPI, spec []*svcapitypes.Tag, resourceName *string) (bool, []*svcsdk.Tag, []*string, error) { current, err := ListTagsForResource(ctx, client, resourceName)