Skip to content

Commit

Permalink
fix(database): allow empty array as value in enableCloudwatchLogsExpo…
Browse files Browse the repository at this point in the history
…rts + fix isuptodate check

Signed-off-by: Charel Baum (external expert on behalf of DB InfraGO AG) <[email protected]>
  • Loading branch information
Charel Baum (external expert on behalf of DB InfraGO AG) committed Oct 22, 2024
1 parent 2e142ad commit b03a708
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
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

0 comments on commit b03a708

Please sign in to comment.