Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(database): allow empty array as value in enableCloudwatchLogsExports + fix isuptodate check #2112

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apis/database/v1beta1/rdsinstance_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ type RDSInstanceParameters struct {
// information, see Publishing Database Logs to Amazon CloudWatch Logs (http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_LogAccess.html#USER_LogAccess.Procedural.UploadtoCloudWatch)
// in the Amazon Relational Database Service User Guide.
// +optional
EnableCloudwatchLogsExports []string `json:"enableCloudwatchLogsExports,omitempty"`
EnableCloudwatchLogsExports []string `json:"enableCloudwatchLogsExports"`

// EnableIAMDatabaseAuthentication should be true to enable mapping of AWS Identity and Access Management (IAM) accounts
// to database accounts, and otherwise false.
Expand Down
9 changes: 5 additions & 4 deletions pkg/clients/database/rds.go
Original file line number Diff line number Diff line change
Expand Up @@ -687,12 +687,13 @@ func LateInitialize(in *v1beta1.RDSInstanceParameters, db *rdstypes.DBInstance)
}
// TODO: remove deprecated field + code. Mapping to EnableCloudwatchLogsExports while in deprecation.
//nolint:staticcheck
if len(in.EnableCloudwatchLogsExports) == 0 && in.CloudwatchLogsExportConfiguration != nil {
if in.EnableCloudwatchLogsExports == nil && in.CloudwatchLogsExportConfiguration != nil {
in.EnableCloudwatchLogsExports = in.CloudwatchLogsExportConfiguration.EnableLogTypes
}

if in.EnableCloudwatchLogsExports == nil {
in.EnableCloudwatchLogsExports = db.EnabledCloudwatchLogsExports
}
in.OptionGroupName = lateInitializeOptionGroupName(in.OptionGroupName, db.OptionGroupMemberships)

}

func lateInitializeOptionGroupName(inOptionGroupName *string, members []rdstypes.OptionGroupMembership) *string {
Expand Down Expand Up @@ -757,7 +758,7 @@ func IsUpToDate(ctx context.Context, kube client.Client, r *v1beta1.RDSInstance,
cloudwatchLogsExportChanged := false
// only check CloudwatchLogsExports if there are no pending cloudwatchlogs exports (ignores the apply immediately setting)
// (to avoid: "api error InvalidParameterCombination: You cannot configure CloudWatch Logs while a previous configuration is in progress.")
if db.PendingModifiedValues != nil && db.PendingModifiedValues.PendingCloudwatchLogsExports == nil {
if db.PendingModifiedValues == nil || (db.PendingModifiedValues != nil && db.PendingModifiedValues.PendingCloudwatchLogsExports == nil) {
cloudwatchLogsExportChanged = !areSameElements(r.Spec.ForProvider.EnableCloudwatchLogsExports, db.EnabledCloudwatchLogsExports)
}

Expand Down
17 changes: 16 additions & 1 deletion pkg/clients/database/rds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,21 @@ func TestIsUpToDate(t *testing.T) {
},
want: false,
},
"EnableCloudwatchLogExportsEmptyAndNil": {
args: args{
db: rdstypes.DBInstance{
EnabledCloudwatchLogsExports: nil,
},
r: v1beta1.RDSInstance{
Spec: v1beta1.RDSInstanceSpec{
ForProvider: v1beta1.RDSInstanceParameters{
EnableCloudwatchLogsExports: []string{},
},
},
},
},
want: true,
},
}

for name, tc := range cases {
Expand Down Expand Up @@ -1130,7 +1145,7 @@ func TestLateInitialize(t *testing.T) {
Timezone: &zone,
DBSecurityGroups: []string{name},
DBSubnetGroupName: subnetGroup.DBSubnetGroupName,
EnableCloudwatchLogsExports: nil,
EnableCloudwatchLogsExports: enabledCloudwatchExports,
ProcessorFeatures: []v1beta1.ProcessorFeature{{
Name: name,
Value: value,
Expand Down
Loading