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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions apis/rds/v1alpha1/custom_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions apis/rds/v1alpha1/zz_generated.deepcopy.go

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

5 changes: 5 additions & 0 deletions package/crds/rds.aws.crossplane.io_dbinstances.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
15 changes: 14 additions & 1 deletion pkg/controller/rds/dbinstance/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 11 additions & 0 deletions pkg/controller/rds/utils/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand Down
Loading