Skip to content

Commit

Permalink
added BackupRetentionPeriod config parameter (#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssuman2-infoblox authored Sep 14, 2023
1 parent 92dc7d5 commit dd6e19a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
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

0 comments on commit dd6e19a

Please sign in to comment.