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

fix: cron generator to support hourly interval and default backup schedule variable #281

Merged
merged 4 commits into from
Dec 19, 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
28 changes: 27 additions & 1 deletion cmd/template_backups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func TestBackupTemplateGeneration(t *testing.T) {
controllerPRSchedule string
k8upVersion string
namespace string
defaultBackupSchedule string
}
tests := []struct {
name string
Expand Down Expand Up @@ -171,6 +172,27 @@ func TestBackupTemplateGeneration(t *testing.T) {
},
want: "../test-resources/template-backups/test6-results",
},
{
name: "test7",
args: args{
alertContact: "alertcontact",
statusPageID: "statuspageid",
projectName: "example-project",
environmentName: "main",
namespace: "example-project-main",
environmentType: "production",
buildType: "branch",
lagoonVersion: "v2.7.x",
branch: "main",
k8upVersion: "v1",
projectVars: `[{"name":"LAGOON_SYSTEM_ROUTER_PATTERN","value":"${service}-${project}-${environment}.example.com","scope":"internal_system"},{"name":"LAGOON_FASTLY_SERVICE_IDS","value":"example.com:service-id:true:annotationscom","scope":"build"}]`,
envVars: `[]`,
lagoonYAML: "../test-resources/template-backups/test7/lagoon.yml",
templatePath: "../test-resources/template-backups/output",
defaultBackupSchedule: "M */6 * * *",
},
want: "../test-resources/template-backups/test7-results",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -255,6 +277,10 @@ func TestBackupTemplateGeneration(t *testing.T) {
if err != nil {
t.Errorf("%v", err)
}
err = os.Setenv("DEFAULT_BACKUP_SCHEDULE", tt.args.defaultBackupSchedule)
if err != nil {
t.Errorf("%v", err)
}
generator, err := generatorInput(false)
if err != nil {
t.Errorf("%v", err)
Expand Down Expand Up @@ -335,7 +361,7 @@ func TestBackupTemplateGeneration(t *testing.T) {
t.Errorf("resulting templates do not match")
}
t.Cleanup(func() {
helpers.UnsetEnvVars(nil)
helpers.UnsetEnvVars([]helpers.EnvironmentVariable{{Name: "DEFAULT_BACKUP_SCHEDULE"}})
})
})
}
Expand Down
3 changes: 1 addition & 2 deletions internal/generator/backups.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
const (
defaultCheckSchedule = "M H(5-8) * * 1"
defaultPruneSchedule = "M H(3-5) * * 0"
defaultBackupSchedule = "M H(22-2) * * *"
hourlyDefaultBackupRetention = 0
dailyDefaultBackupRetention = 7
weeklyDefaultBackupRetention = 6
Expand All @@ -30,7 +29,7 @@ func generateBackupValues(
// builds need to calculate a new schedule from multiple places for backups
// create a new schedule placeholder set to the default value so it can be adjusted through this
// generator
newBackupSchedule := defaultBackupSchedule
newBackupSchedule := buildValues.DefaultBackupSchedule

customBackupConfig := CheckFeatureFlag("CUSTOM_BACKUP_CONFIG", mergedVariables, debug)
if customBackupConfig == "enabled" {
Expand Down
Loading