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

added BackupRetentionPeriod config #173

Merged
merged 1 commit into from
Sep 14, 2023
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
3 changes: 3 additions & 0 deletions cmd/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ defaultSkipFinalSnapshotBeforeDeletion: true
defaultPubliclyAccessible: false
defaultDeletionPolicy: Orphan
defaultBackupPolicyValue: Bronze
backupRetentionDays: 0
enablePerfInsight: false
enableCloudwatchLogsExport: "none"

passwordConfig:
passwordComplexity: enabled
Expand Down
18 changes: 17 additions & 1 deletion controllers/databaseclaim_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ type input struct {
EnableSuperUser bool
EnablePerfInsight bool
EnableCloudwatchLogsExport []*string
BackupRetentionDays int64
}

const (
Expand Down Expand Up @@ -211,8 +212,10 @@ func (r *DatabaseClaimReconciler) setReqInfo(dbClaim *persistancev1.DatabaseClai
sharedDBHost bool
enablePerfInsight bool
cloudwatchLogsExport []*string
backupRetentionDays int64
)

backupRetentionDays = r.Config.GetInt64("backupRetentionDays")
enablePerfInsight = r.Config.GetBool("enablePerfInsight")
enableCloudwatchLogsExport := r.Config.GetString("enableCloudwatchLogsExport")
postgresCloudwatchLogsExportLabels := []string{"postgresql", "upgrade"}
Expand Down Expand Up @@ -263,6 +266,7 @@ func (r *DatabaseClaimReconciler) setReqInfo(dbClaim *persistancev1.DatabaseClai
DbType: string(dbClaim.Spec.Type), HostParams: *hostParams,
EnablePerfInsight: enablePerfInsight,
EnableCloudwatchLogsExport: cloudwatchLogsExport,
BackupRetentionDays: backupRetentionDays,
}
if manageCloudDB {
//check if dbclaim.name is > maxNameLen and if so, error out
Expand Down Expand Up @@ -1320,6 +1324,13 @@ func (r *DatabaseClaimReconciler) manageDBCluster(ctx context.Context, dbHostNam
restoreFromSource := defaultRestoreFromSource
encryptStrg := true

var auroraBackupRetentionPeriod *int64
if r.Input.BackupRetentionDays != 0 {
auroraBackupRetentionPeriod = &r.Input.BackupRetentionDays
} else {
auroraBackupRetentionPeriod = nil
}

dbClaim.Spec.Tags = r.configureBackupPolicy(dbClaim.Spec.BackupPolicy, dbClaim.Spec.Tags)

err = r.Client.Get(ctx, client.ObjectKey{
Expand All @@ -1335,7 +1346,8 @@ func (r *DatabaseClaimReconciler) manageDBCluster(ctx context.Context, dbHostNam
},
Spec: crossplanerds.DBClusterSpec{
ForProvider: crossplanerds.DBClusterParameters{
Region: r.getRegion(),
Region: r.getRegion(),
BackupRetentionPeriod: auroraBackupRetentionPeriod,
CustomDBClusterParameters: crossplanerds.CustomDBClusterParameters{
SkipFinalSnapshot: params.SkipFinalSnapshotBeforeDeletion,
VPCSecurityGroupIDRefs: []xpv1.Reference{
Expand Down Expand Up @@ -1485,6 +1497,7 @@ func (r *DatabaseClaimReconciler) managePostgresDBInstance(ctx context.Context,
EnableIAMDatabaseAuthentication: &params.EnableIAMDatabaseAuthentication,
EnablePerformanceInsights: &r.Input.EnablePerfInsight,
EnableCloudwatchLogsExports: r.Input.EnableCloudwatchLogsExport,
BackupRetentionPeriod: &r.Input.BackupRetentionDays,
StorageEncrypted: &trueVal,
StorageType: &storageType,
Port: &params.Port,
Expand Down Expand Up @@ -2020,6 +2033,9 @@ func (r *DatabaseClaimReconciler) updateDBCluster(ctx context.Context, dbClaim *
// Update DBCluster
dbClaim.Spec.Tags = r.configureBackupPolicy(dbClaim.Spec.BackupPolicy, dbClaim.Spec.Tags)
dbCluster.Spec.ForProvider.Tags = DBClaimTags(dbClaim.Spec.Tags).DBTags()
if r.Input.BackupRetentionDays != 0 {
dbCluster.Spec.ForProvider.BackupRetentionPeriod = &r.Input.BackupRetentionDays
}

// Compute a json patch based on the changed RDSInstance
dbClusterPatchData, err := patchDBCluster.Data(dbCluster)
Expand Down
4 changes: 4 additions & 0 deletions helm/db-controller/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ controllerConfig:
defaultDeletionPolicy: orphan
providerConfig: default
defaultBackupPolicyValue: Bronze
# The number of days for which automated backups are retained. Setting this parameter to a positive number enables backups.
# Setting this parameter to 0 disables automated backups (in case of Aurora, 0 is N/A and will be set to 1 by default).
# Possible values (0-35)
backupRetentionDays: 0
passwordConfig:
passwordComplexity: enabled
minPasswordLength: 15
Expand Down
Loading