From dd6e19aecf5b3c496fab00a2c73161ddfdd2493c Mon Sep 17 00:00:00 2001 From: Sujay Kumar Suman Date: Thu, 14 Sep 2023 10:29:56 +0530 Subject: [PATCH] added BackupRetentionPeriod config parameter (#173) --- cmd/config/config.yaml | 3 +++ controllers/databaseclaim_controller.go | 18 +++++++++++++++++- helm/db-controller/values.yaml | 4 ++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/cmd/config/config.yaml b/cmd/config/config.yaml index 08ee56e2..febeca3e 100644 --- a/cmd/config/config.yaml +++ b/cmd/config/config.yaml @@ -22,6 +22,9 @@ defaultSkipFinalSnapshotBeforeDeletion: true defaultPubliclyAccessible: false defaultDeletionPolicy: Orphan defaultBackupPolicyValue: Bronze +backupRetentionDays: 0 +enablePerfInsight: false +enableCloudwatchLogsExport: "none" passwordConfig: passwordComplexity: enabled diff --git a/controllers/databaseclaim_controller.go b/controllers/databaseclaim_controller.go index a5a703b2..85328f5b 100644 --- a/controllers/databaseclaim_controller.go +++ b/controllers/databaseclaim_controller.go @@ -91,6 +91,7 @@ type input struct { EnableSuperUser bool EnablePerfInsight bool EnableCloudwatchLogsExport []*string + BackupRetentionDays int64 } const ( @@ -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"} @@ -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 @@ -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{ @@ -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{ @@ -1485,6 +1497,7 @@ func (r *DatabaseClaimReconciler) managePostgresDBInstance(ctx context.Context, EnableIAMDatabaseAuthentication: ¶ms.EnableIAMDatabaseAuthentication, EnablePerformanceInsights: &r.Input.EnablePerfInsight, EnableCloudwatchLogsExports: r.Input.EnableCloudwatchLogsExport, + BackupRetentionPeriod: &r.Input.BackupRetentionDays, StorageEncrypted: &trueVal, StorageType: &storageType, Port: ¶ms.Port, @@ -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) diff --git a/helm/db-controller/values.yaml b/helm/db-controller/values.yaml index da71d966..54774ae2 100644 --- a/helm/db-controller/values.yaml +++ b/helm/db-controller/values.yaml @@ -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