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

rdsinstance: AWS Backup might also manage PreferredBackupWindow #1406

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
14 changes: 11 additions & 3 deletions pkg/clients/rds/rds.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,17 @@ func CreatePatch(in *rdstypes.DBInstance, target *v1beta1.RDSInstanceParameters)
currentParams.AllocatedStorage = target.AllocatedStorage
}

// AWS Backup takes ownership of backupRetentionPeriod if it is in use, so we need to exclude the field in the diff
if in.AwsBackupRecoveryPointArn != nil && target.BackupRetentionPeriod != nil {
currentParams.BackupRetentionPeriod = target.BackupRetentionPeriod
// AWS Backup takes ownership of backupRetentionPeriod and
// preferredBackupWindow if it is in use, so we need to exclude
// the field in the diff
if in.AwsBackupRecoveryPointArn != nil {
if target.BackupRetentionPeriod != nil {
currentParams.BackupRetentionPeriod = target.BackupRetentionPeriod
}

if target.PreferredBackupWindow != nil {
currentParams.PreferredBackupWindow = target.PreferredBackupWindow
}
}

jsonPatch, err := awsclients.CreateJSONPatch(currentParams, target)
Expand Down
13 changes: 11 additions & 2 deletions pkg/controller/database/rdsinstance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ var (
snapshotSourceType = "Snapshot"
pointInTimeSourceType = "PointInTime"
s3BucketName = "database-backup"
backupWindow = "21:00-23:00"
snapshotIdentifier = "my-snapshot"
pointInTimeDBInstanceIdentifier = "my-instance"
awsBackupRecoveryPointARN = "arn:aws:backup:us-east-1:123456789012:recovery-point:1EB3B5E7-9EB-A80B-108B488B0D45"
Expand Down Expand Up @@ -163,6 +164,10 @@ func withBackupRetentionPeriod(i int) rdsModifier {
return func(r *v1beta1.RDSInstance) { r.Spec.ForProvider.BackupRetentionPeriod = &i }
}

func withPreferredBackupWindow(s string) rdsModifier {
return func(r *v1beta1.RDSInstance) { r.Spec.ForProvider.PreferredBackupWindow = &s }
}

func withStatusBackupRetentionPeriod(i int) rdsModifier {
return func(r *v1beta1.RDSInstance) { r.Status.AtProvider.BackupRetentionPeriod = i }
}
Expand Down Expand Up @@ -762,12 +767,16 @@ func TestUpdate(t *testing.T) {
if input.BackupRetentionPeriod != nil {
return &awsrds.ModifyDBInstanceOutput{}, errors.New("BackupRetentionPeriod must not be set when AWS Backup is used")
}
if input.PreferredBackupWindow != nil {
return &awsrds.ModifyDBInstanceOutput{}, errors.New("PreferredBackupWindow must not be set when AWS Backup is used")
}
return &awsrds.ModifyDBInstanceOutput{}, nil
},
MockDescribe: func(ctx context.Context, input *awsrds.DescribeDBInstancesInput, opts []func(*awsrds.Options)) (*awsrds.DescribeDBInstancesOutput, error) {
return &awsrds.DescribeDBInstancesOutput{
DBInstances: []awsrdstypes.DBInstance{{
BackupRetentionPeriod: 7,
PreferredBackupWindow: &backupWindow,
AwsBackupRecoveryPointArn: aws.String(awsBackupRecoveryPointARN),
}},
}, nil
Expand All @@ -776,10 +785,10 @@ func TestUpdate(t *testing.T) {
return &awsrds.AddTagsToResourceOutput{}, nil
},
},
cr: instance(withBackupRetentionPeriod(0), withStatusBackupRetentionPeriod(7)),
cr: instance(withBackupRetentionPeriod(0), withStatusBackupRetentionPeriod(7), withPreferredBackupWindow("x")),
},
want: want{
cr: instance(withBackupRetentionPeriod(0), withStatusBackupRetentionPeriod(7)),
cr: instance(withBackupRetentionPeriod(0), withStatusBackupRetentionPeriod(7), withPreferredBackupWindow("x")),
},
},
"AlreadyModifying": {
Expand Down