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

refactor: add tests for LAGOON_BACKUP_PROD_SCHEDULE #374

Merged
merged 2 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
21 changes: 21 additions & 0 deletions cmd/template_backups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 1 addition & 2 deletions docs/buildrequirements.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
36 changes: 36 additions & 0 deletions internal/generator/backups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: 1,
},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
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
keepMonthly: 1
keepWeekly: 6
schedule: 48 3 * * 0
resourceRequirementsTemplate: {}
status: {}
Loading