diff --git a/controllers/v1beta1/lagoonbuild_controller.go b/controllers/v1beta1/lagoonbuild_controller.go index b9070e44..339416c7 100644 --- a/controllers/v1beta1/lagoonbuild_controller.go +++ b/controllers/v1beta1/lagoonbuild_controller.go @@ -64,14 +64,10 @@ type LagoonBuildReconciler struct { LFFDefaultInsights string LFFForceRWX2RWO string LFFDefaultRWX2RWO string - BackupDefaultSchedule string - BackupDefaultMonthlyRetention int - BackupDefaultWeeklyRetention int - BackupDefaultDailyRetention int - BackupDefaultHourlyRetention int LFFBackupWeeklyRandom bool LFFRouterURL bool LFFHarborEnabled bool + BackupConfig BackupConfig Harbor Harbor LFFQoSEnabled bool BuildQoS BuildQoS @@ -80,6 +76,20 @@ type LagoonBuildReconciler struct { ProxyConfig ProxyConfig } +// BackupConfig holds all the backup configuration settings +type BackupConfig struct { + BackupDefaultSchedule string + BackupDefaultMonthlyRetention int + BackupDefaultWeeklyRetention int + BackupDefaultDailyRetention int + BackupDefaultHourlyRetention int + + BackupDefaultDevelopmentSchedule string + BackupDefaultPullrequestSchedule string + BackupDefaultDevelopmentRetention string + BackupDefaultPullrequestRetention string +} + // ProxyConfig is used for proxy configuration. type ProxyConfig struct { HTTPProxy string diff --git a/controllers/v1beta1/lagoonbuild_helpers.go b/controllers/v1beta1/lagoonbuild_helpers.go index fae93aec..8b6e64c3 100644 --- a/controllers/v1beta1/lagoonbuild_helpers.go +++ b/controllers/v1beta1/lagoonbuild_helpers.go @@ -508,23 +508,39 @@ func (r *LagoonBuildReconciler) processBuild(ctx context.Context, opLog logr.Log }, { Name: "DEFAULT_BACKUP_SCHEDULE", - Value: r.BackupDefaultSchedule, + Value: r.BackupConfig.BackupDefaultSchedule, }, { Name: "MONTHLY_BACKUP_DEFAULT_RETENTION", - Value: strconv.Itoa(r.BackupDefaultMonthlyRetention), + Value: strconv.Itoa(r.BackupConfig.BackupDefaultMonthlyRetention), }, { Name: "WEEKLY_BACKUP_DEFAULT_RETENTION", - Value: strconv.Itoa(r.BackupDefaultWeeklyRetention), + Value: strconv.Itoa(r.BackupConfig.BackupDefaultWeeklyRetention), }, { Name: "DAILY_BACKUP_DEFAULT_RETENTION", - Value: strconv.Itoa(r.BackupDefaultDailyRetention), + Value: strconv.Itoa(r.BackupConfig.BackupDefaultDailyRetention), }, { Name: "HOURLY_BACKUP_DEFAULT_RETENTION", - Value: strconv.Itoa(r.BackupDefaultHourlyRetention), + Value: strconv.Itoa(r.BackupConfig.BackupDefaultHourlyRetention), + }, + { + Name: "LAGOON_FEATURE_BACKUP_DEV_SCHEDULE", + Value: r.BackupConfig.BackupDefaultDevelopmentSchedule, + }, + { + Name: "LAGOON_FEATURE_BACKUP_PR_SCHEDULE", + Value: r.BackupConfig.BackupDefaultPullrequestSchedule, + }, + { + Name: "LAGOON_FEATURE_BACKUP_DEV_RETENTION", + Value: r.BackupConfig.BackupDefaultDevelopmentRetention, + }, + { + Name: "LAGOON_FEATURE_BACKUP_PR_RETENTION", + Value: r.BackupConfig.BackupDefaultPullrequestRetention, }, { Name: "K8UP_WEEKLY_RANDOM_FEATURE_FLAG", diff --git a/main.go b/main.go index 4c3a9f72..60d69b8d 100644 --- a/main.go +++ b/main.go @@ -94,6 +94,12 @@ func main() { var backupDefaultWeeklyRetention int var backupDefaultMonthlyRetention int var backupDefaultSchedule string + + var backupDefaultDevelopmentSchedule string + var backupDefaultPullrequestSchedule string + var backupDefaultDevelopmentRetention string + var backupDefaultPullrequestRetention string + // Lagoon Feature Flags options control features in Lagoon. Default options // set a default cluster policy, while Force options enforce a cluster policy // and cannot be overridden. @@ -204,6 +210,14 @@ func main() { flag.UintVar(&buildPodFSGroup, "build-pod-fs-group", 0, "The build pod security context fsGroup.") flag.StringVar(&backupDefaultSchedule, "backup-default-schedule", "M H(22-2) * * *", "The default backup schedule for all projects on this cluster.") + flag.StringVar(&backupDefaultDevelopmentSchedule, "backup-default-dev-schedule", "", + "The default backup schedule for all devlopment environments on this cluster.") + flag.StringVar(&backupDefaultPullrequestSchedule, "backup-default-pr-schedule", "", + "The default backup schedule for all pullrequest environments on this cluster.") + flag.StringVar(&backupDefaultDevelopmentRetention, "backup-default-dev-retention", "", + "The default backup retention for all devlopment environments on this cluster (H:D:W:M).") + flag.StringVar(&backupDefaultPullrequestRetention, "backup-default-pr-retention", "", + "The default backup retention for all pullrequest environments on this cluster (H:D:W:M).") flag.IntVar(&backupDefaultMonthlyRetention, "backup-default-monthly-retention", 1, "The number of monthly backups k8up should retain after a prune operation.") flag.IntVar(&backupDefaultWeeklyRetention, "backup-default-weekly-retention", 6, @@ -637,27 +651,33 @@ func main() { setupLog.Info("starting controllers") if err = (&lagoonv1beta1ctrl.LagoonBuildReconciler{ - Client: mgr.GetClient(), - Log: ctrl.Log.WithName("v1beta1").WithName("LagoonBuild"), - Scheme: mgr.GetScheme(), - EnableMQ: enableMQ, - BuildImage: overrideBuildDeployImage, - Messaging: messaging, - IsOpenshift: isOpenshift, - NamespacePrefix: namespacePrefix, - RandomNamespacePrefix: randomPrefix, - ControllerNamespace: controllerNamespace, - EnableDebug: enableDebug, - FastlyServiceID: fastlyServiceID, - FastlyWatchStatus: fastlyWatchStatus, - BuildPodRunAsUser: int64(buildPodRunAsUser), - BuildPodRunAsGroup: int64(buildPodRunAsGroup), - BuildPodFSGroup: int64(buildPodFSGroup), - BackupDefaultSchedule: backupDefaultSchedule, - BackupDefaultMonthlyRetention: backupDefaultMonthlyRetention, - BackupDefaultWeeklyRetention: backupDefaultWeeklyRetention, - BackupDefaultDailyRetention: backupDefaultDailyRetention, - BackupDefaultHourlyRetention: backupDefaultHourlyRetention, + Client: mgr.GetClient(), + Log: ctrl.Log.WithName("v1beta1").WithName("LagoonBuild"), + Scheme: mgr.GetScheme(), + EnableMQ: enableMQ, + BuildImage: overrideBuildDeployImage, + Messaging: messaging, + IsOpenshift: isOpenshift, + NamespacePrefix: namespacePrefix, + RandomNamespacePrefix: randomPrefix, + ControllerNamespace: controllerNamespace, + EnableDebug: enableDebug, + FastlyServiceID: fastlyServiceID, + FastlyWatchStatus: fastlyWatchStatus, + BuildPodRunAsUser: int64(buildPodRunAsUser), + BuildPodRunAsGroup: int64(buildPodRunAsGroup), + BuildPodFSGroup: int64(buildPodFSGroup), + BackupConfig: lagoonv1beta1ctrl.BackupConfig{ + BackupDefaultSchedule: backupDefaultSchedule, + BackupDefaultDevelopmentSchedule: backupDefaultDevelopmentSchedule, + BackupDefaultPullrequestSchedule: backupDefaultPullrequestSchedule, + BackupDefaultDevelopmentRetention: backupDefaultDevelopmentRetention, + BackupDefaultPullrequestRetention: backupDefaultPullrequestRetention, + BackupDefaultMonthlyRetention: backupDefaultMonthlyRetention, + BackupDefaultWeeklyRetention: backupDefaultWeeklyRetention, + BackupDefaultDailyRetention: backupDefaultDailyRetention, + BackupDefaultHourlyRetention: backupDefaultHourlyRetention, + }, // Lagoon feature flags LFFForceRootlessWorkload: lffForceRootlessWorkload, LFFDefaultRootlessWorkload: lffDefaultRootlessWorkload,