Skip to content

Commit 948ebf3

Browse files
fix: create schedule if additional volumes are used (#455)
* fix: create schedule if additional volumes are used * test: add no backup schedule for additional volumes with backups disabled
1 parent dee7687 commit 948ebf3

File tree

6 files changed

+120
-0
lines changed

6 files changed

+120
-0
lines changed

cmd/template_backups_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,45 @@ func TestBackupTemplateGeneration(t *testing.T) {
332332
templatePath: "testoutput",
333333
want: "internal/testdata/node/backup-templates/test-generic-backup-rootless-workloads-onrootmismatch",
334334
},
335+
{
336+
name: "schedules-with-additional-volumes",
337+
args: testdata.GetSeedData(
338+
testdata.TestData{
339+
ProjectName: "example-project",
340+
EnvironmentName: "main",
341+
Branch: "main",
342+
LagoonYAML: "internal/testdata/basic/lagoon.multiple-volumes-2.yml",
343+
ProjectVariables: []lagoon.EnvironmentVariable{
344+
{
345+
Name: "LAGOON_FEATURE_FLAG_IMAGECACHE_REGISTRY",
346+
Value: "imagecache.example.com",
347+
Scope: "global",
348+
},
349+
},
350+
}, true),
351+
templatePath: "testoutput",
352+
want: "internal/testdata/basic/backup-templates/schedules-with-additional-volumes",
353+
},
354+
{
355+
name: "no-schedules-with-additional-volumes-with-no-backups",
356+
args: testdata.GetSeedData(
357+
testdata.TestData{
358+
ProjectName: "example-project",
359+
EnvironmentName: "main",
360+
Branch: "main",
361+
LagoonYAML: "internal/testdata/basic/lagoon.additional-volumes-no-backup.yml",
362+
ProjectVariables: []lagoon.EnvironmentVariable{
363+
{
364+
Name: "LAGOON_FEATURE_FLAG_IMAGECACHE_REGISTRY",
365+
Value: "imagecache.example.com",
366+
Scope: "global",
367+
},
368+
},
369+
}, true),
370+
templatePath: "testoutput",
371+
emptyDir: true,
372+
want: "internal/testdata/basic/backup-templates/schedules-with-additional-volumes-no-backup",
373+
},
335374
}
336375
for _, tt := range tests {
337376
t.Run(tt.name, func(t *testing.T) {

internal/generator/services.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,12 @@ func composeToServiceValues(
560560

561561
}
562562
}
563+
// if there are any additional volumes that have backups configured, enable the backup schedule
564+
for _, v := range serviceVolumes {
565+
if v.Backup {
566+
backupsEnabled = true
567+
}
568+
}
563569

564570
// create the service values
565571
cService := &ServiceValues{

internal/testdata/basic/backup-templates/schedules-with-additional-volumes-no-backup/.gitkeep

Whitespace-only changes.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
apiVersion: backup.appuio.ch/v1alpha1
3+
kind: Schedule
4+
metadata:
5+
annotations:
6+
lagoon.sh/branch: main
7+
lagoon.sh/version: v2.7.x
8+
creationTimestamp: null
9+
labels:
10+
app.kubernetes.io/instance: k8up-lagoon-backup-schedule
11+
app.kubernetes.io/managed-by: build-deploy-tool
12+
app.kubernetes.io/name: k8up-schedule
13+
lagoon.sh/buildType: branch
14+
lagoon.sh/environment: main
15+
lagoon.sh/environmentType: production
16+
lagoon.sh/project: example-project
17+
lagoon.sh/service: k8up-lagoon-backup-schedule
18+
lagoon.sh/service-type: k8up-schedule
19+
lagoon.sh/template: k8up-schedule-0.1.0
20+
name: k8up-lagoon-backup-schedule
21+
spec:
22+
backend:
23+
repoPasswordSecretRef:
24+
key: repo-pw
25+
name: baas-repo-pw
26+
s3:
27+
bucket: baas-example-project
28+
backup:
29+
resources: {}
30+
schedule: 48 22 * * *
31+
check:
32+
resources: {}
33+
schedule: 48 5 * * 1
34+
prune:
35+
resources: {}
36+
retention:
37+
keepDaily: 7
38+
keepWeekly: 6
39+
schedule: 48 3 * * 0
40+
resourceRequirementsTemplate: {}
41+
status: {}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
version: '2'
2+
services:
3+
node:
4+
networks:
5+
- amazeeio-network
6+
- default
7+
build:
8+
context: internal/testdata/basic/docker
9+
dockerfile: basic.dockerfile
10+
labels:
11+
lagoon.type: basic
12+
lagoon.volumes.scratch.path: /scratch
13+
volumes:
14+
- scratch:/scratch
15+
16+
networks:
17+
amazeeio-network:
18+
external: true
19+
20+
volumes:
21+
scratch:
22+
labels:
23+
lagoon.type: persistent
24+
lagoon.backup: false
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
docker-compose-yaml: internal/testdata/basic/docker-compose.additional-volumes-no-backup.yml
2+
3+
environment_variables:
4+
git_sha: "true"
5+
6+
environments:
7+
main:
8+
routes:
9+
- node:
10+
- example.com

0 commit comments

Comments
 (0)