diff --git a/cmd/template_backups_test.go b/cmd/template_backups_test.go index 7fb56aef..bf9658de 100644 --- a/cmd/template_backups_test.go +++ b/cmd/template_backups_test.go @@ -240,6 +240,27 @@ func TestBackupTemplateGeneration(t *testing.T) { templatePath: "testdata/output", want: "internal/testdata/node/backup-templates/backup-8", }, + { + name: "test11 - custom prod schedule", + args: testdata.GetSeedData( + testdata.TestData{ + ProjectName: "example-project", + EnvironmentName: "main", + Branch: "main", + EnvironmentType: "production", + LagoonYAML: "internal/testdata/node/lagoon.yml", + ProjectVariables: []lagoon.EnvironmentVariable{ + { + Name: "LAGOON_FEATURE_FLAG_CUSTOM_BACKUP_CONFIG", + Value: "enabled", + Scope: "global", + }, + {Name: "LAGOON_BACKUP_PROD_SCHEDULE", Value: "2,21 22 * * *", Scope: "build"}, + }, + }, true), + templatePath: "testoutput", + want: "internal/testdata/node/backup-templates/backup-9", + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/docs/buildrequirements.md b/docs/buildrequirements.md index fbc88cc5..0b80a0bd 100644 --- a/docs/buildrequirements.md +++ b/docs/buildrequirements.md @@ -90,8 +90,7 @@ These are all variables that are provided by either core or remote * `WEEKLY_BACKUP_DEFAULT_RETENTION` * `DAILY_BACKUP_DEFAULT_RETENTION` * `HOURLY_BACKUP_DEFAULT_RETENTION` +* `LAGOON_FEATURE_BACKUP_PROD_SCHEDULE` (remote) / `LAGOON_BACKUP_PROD_SCHEDULE` (API) * `LAGOON_FEATURE_BACKUP_DEV_SCHEDULE` (remote) / `LAGOON_BACKUP_DEV_SCHEDULE` (API) * `LAGOON_FEATURE_BACKUP_PR_SCHEDULE` (remote) / `LAGOON_BACKUP_PR_SCHEDULE` (API) -* `LAGOON_FEATURE_BACKUP_DEV_RETENTION` (remote) / `LAGOON_BACKUP_DEV_RETENTION` (API) -* `LAGOON_FEATURE_BACKUP_PR_RETENTION` (remote) / `LAGOON_BACKUP_PR_RETENTION` (API) * `K8UP_WEEKLY_RANDOM_FEATURE_FLAG` diff --git a/internal/generator/backups_test.go b/internal/generator/backups_test.go index 06367204..2ce8ec73 100644 --- a/internal/generator/backups_test.go +++ b/internal/generator/backups_test.go @@ -775,6 +775,42 @@ func Test_generateBackupValues(t *testing.T) { }, }, }, + { + name: "test20- prod schedule from lagoon api variable", + args: args{ + buildValues: &BuildValues{ + BuildType: "branch", + EnvironmentType: "production", + Project: "example-project", + Namespace: "example-com-main", + DefaultBackupSchedule: "M H(22-2) * * *", + LagoonYAML: lagoon.YAML{}, + }, + mergedVariables: []lagoon.EnvironmentVariable{ + {Name: "LAGOON_FEATURE_FLAG_CUSTOM_BACKUP_CONFIG", Value: "enabled", Scope: "global"}, + {Name: "LAGOON_BACKUP_PROD_SCHEDULE", Value: "M/15 23 * * 0-5", Scope: "build"}, + }, + }, + want: &BuildValues{ + BuildType: "branch", + EnvironmentType: "production", + Project: "example-project", + Namespace: "example-com-main", + DefaultBackupSchedule: "M H(22-2) * * *", + Backup: BackupConfiguration{ + BackupSchedule: "1,16,31,46 23 * * 0-5", + CheckSchedule: "31 6 * * 1", + PruneSchedule: "31 4 * * 0", + S3BucketName: "baas-example-project", + PruneRetention: PruneRetention{ + Hourly: 0, + Daily: 7, + Weekly: 6, + Monthly: 0, + }, + }, + }, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/internal/testdata/node/backup-templates/backup-9/k8up-lagoon-backup-schedule.yaml b/internal/testdata/node/backup-templates/backup-9/k8up-lagoon-backup-schedule.yaml new file mode 100644 index 00000000..c523e6af --- /dev/null +++ b/internal/testdata/node/backup-templates/backup-9/k8up-lagoon-backup-schedule.yaml @@ -0,0 +1,41 @@ +--- +apiVersion: backup.appuio.ch/v1alpha1 +kind: Schedule +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: k8up-lagoon-backup-schedule + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: k8up-schedule + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: k8up-lagoon-backup-schedule + lagoon.sh/service-type: k8up-schedule + lagoon.sh/template: k8up-schedule-0.1.0 + name: k8up-lagoon-backup-schedule +spec: + backend: + repoPasswordSecretRef: + key: repo-pw + name: baas-repo-pw + s3: + bucket: baas-example-project + backup: + resources: {} + schedule: 2,21 22 * * * + check: + resources: {} + schedule: 48 5 * * 1 + prune: + resources: {} + retention: + keepDaily: 7 + keepWeekly: 6 + schedule: 48 3 * * 0 + resourceRequirementsTemplate: {} +status: {}