Skip to content

Commit

Permalink
Merge pull request #126 from uselagoon/dev-pr-backup-config
Browse files Browse the repository at this point in the history
chore: add dev and pr environment backup overrides
  • Loading branch information
shreddedbacon authored May 2, 2022
2 parents 9db8753 + afec189 commit a70c1a1
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 31 deletions.
20 changes: 15 additions & 5 deletions controllers/v1beta1/lagoonbuild_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
26 changes: 21 additions & 5 deletions controllers/v1beta1/lagoonbuild_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
62 changes: 41 additions & 21 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit a70c1a1

Please sign in to comment.