Skip to content

Commit 1e695ef

Browse files
authored
Merge pull request #170 from projectsyn/fix/lib-ca-volume
Correctly configure custom CA volume on `Schedule` objects generated by the component library
2 parents 88a4ff8 + b604720 commit 1e695ef

9 files changed

Lines changed: 222 additions & 17 deletions

File tree

.cruft.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"template": "https://github.com/projectsyn/commodore-component-template.git",
3-
"commit": "8f2273cd8ab13c55eb0f6dd621c70c4c9e4786fd",
3+
"commit": "7e46facc758385bc32eeecab92b4639c66fd4e4f",
44
"checkout": "main",
55
"context": {
66
"cookiecutter": {
77
"name": "backup-k8up",
88
"slug": "backup-k8up",
99
"parameter_key": "backup_k8up",
10-
"test_cases": "defaults",
10+
"test_cases": "defaults component-lib",
1111
"add_lib": "y",
1212
"add_pp": "y",
1313
"add_golden": "y",
@@ -25,7 +25,7 @@
2525
"github_name": "component-backup-k8up",
2626
"github_url": "https://github.com/projectsyn/component-backup-k8up",
2727
"_template": "https://github.com/projectsyn/commodore-component-template.git",
28-
"_commit": "8f2273cd8ab13c55eb0f6dd621c70c4c9e4786fd"
28+
"_commit": "7e46facc758385bc32eeecab92b4639c66fd4e4f"
2929
}
3030
},
3131
"directory": null

.github/workflows/test.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ jobs:
3333
matrix:
3434
instance:
3535
- defaults
36+
- component-lib
3637
defaults:
3738
run:
3839
working-directory: ${{ env.COMPONENT_NAME }}
@@ -48,6 +49,7 @@ jobs:
4849
matrix:
4950
instance:
5051
- defaults
52+
- component-lib
5153
defaults:
5254
run:
5355
working-directory: ${{ env.COMPONENT_NAME }}

Makefile.vars.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,4 @@ KUBENT_IMAGE ?= ghcr.io/doitintl/kube-no-trouble:latest
5757
KUBENT_DOCKER ?= $(DOCKER_CMD) $(DOCKER_ARGS) $(root_volume) --entrypoint=/app/kubent $(KUBENT_IMAGE)
5858

5959
instance ?= defaults
60-
test_instances = tests/defaults.yml
60+
test_instances = tests/defaults.yml tests/component-lib.yml

lib/backup-k8up.libjsonnet

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ local Backend(backupkey, bucket, s3secret, create_bucket=true, caConfigMap=null)
8888
local CheckSpec(schedule) =
8989
{
9090
spec+: {
91-
check: {
91+
check+: {
9292
[if k8up_params.prometheus_push_gateway != null then 'promURL']:
9393
k8up_params.prometheus_push_gateway,
9494
schedule: schedule,
@@ -110,7 +110,7 @@ local CheckSpec(schedule) =
110110
local PruneSpec(schedule, keepDaily, keepLast) =
111111
{
112112
spec+: {
113-
prune: {
113+
prune+: {
114114
retention: {
115115
keepDaily: keepDaily,
116116
keepLast: keepLast,
@@ -179,10 +179,24 @@ local Job(name, keep_jobs=3, backupkey=null, bucket=null, s3secret=null, create_
179179
* See the documentation for \ref Job for definitions of the other arguments.
180180
*/
181181
local Schedule(name, schedule, keep_jobs=3, backupkey=null, bucket=null, s3secret=null, create_bucket=true, caConfigMap=null) =
182+
local caVolume = {
183+
[if caConfigMap != null then 'volumes']: [
184+
{
185+
name: 'ca',
186+
configMap: {
187+
name: caConfigMap,
188+
},
189+
},
190+
],
191+
};
182192
// prune backups daily, keep last 5 and 30 daily backups
183-
local pspec = PruneSpec('30 2 * * *', 30, 5);
193+
local pspec = PruneSpec('30 2 * * *', 30, 5) {
194+
spec+: { prune+: caVolume },
195+
};
184196
// check backup repo dalily
185-
local cspec = CheckSpec('30 3 * * *');
197+
local cspec = CheckSpec('30 3 * * *') {
198+
spec+: { check+: caVolume },
199+
};
186200
local backend = Backend(backupkey, bucket, s3secret, create_bucket, caConfigMap);
187201
local theschedule =
188202
{
@@ -198,15 +212,7 @@ local Schedule(name, schedule, keep_jobs=3, backupkey=null, bucket=null, s3secre
198212
k8up_params.prometheus_push_gateway,
199213
keepJobs: keep_jobs,
200214
schedule: schedule,
201-
[if caConfigMap != null then 'volumes']: [
202-
{
203-
name: 'ca',
204-
configMap: {
205-
name: caConfigMap,
206-
},
207-
},
208-
],
209-
},
215+
} + caVolume,
210216
},
211217
} + pspec + cspec;
212218
{

tests/component-lib-tests.jsonnet

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
local kap = import 'lib/kapitan.libjsonnet';
2+
3+
local k8up = import 'lib/backup-k8up.libjsonnet';
4+
5+
local inv = kap.inventory();
6+
7+
local test_cases = inv.parameters.test_cases;
8+
9+
local create_schedule(tc, spec) =
10+
local pspec = if std.objectHas(spec, 'prune_spec') then
11+
k8up.PruneSpec(
12+
spec.prune_spec.schedule,
13+
spec.prune_spec.keep_daily,
14+
spec.prune_spec.keep_last
15+
)
16+
else
17+
{};
18+
local cspec = if std.objectHas(spec, 'check_schedule') then
19+
k8up.CheckSpec(spec.check_schedule)
20+
else
21+
{};
22+
k8up.Schedule(
23+
tc,
24+
std.get(spec, 'schedule', '23 * * * *'),
25+
keep_jobs=std.get(spec, 'keep_jobs', 3),
26+
backupkey=std.get(spec, 'backupkey'),
27+
bucket=std.get(spec, 'bucket'),
28+
s3secret=std.get(spec, 's3secret'),
29+
create_bucket=false,
30+
caConfigMap=std.get(spec, 'caConfigMap'),
31+
).schedule + pspec + cspec;
32+
33+
std.mapWithKey(create_schedule, test_cases)

tests/component-lib.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
parameters:
2+
kapitan:
3+
~compile:
4+
- input_paths:
5+
- ${_base_directory}/tests/component-lib-tests.jsonnet
6+
input_type: jsonnet
7+
output_path: ${_instance}/
8+
9+
# disable commodore postprocessing for lib test
10+
~commodore: {}
11+
12+
backup_k8up:
13+
default_backup_bucket: null
14+
global_backup_config:
15+
s3_endpoint: https://s3.example.com
16+
17+
test_cases:
18+
default: &d
19+
schedule: "10 3 * * *"
20+
bucket: default-bucket
21+
backupkey:
22+
name: backup-secret
23+
key: password
24+
s3secret:
25+
name: s3-secret
26+
accesskeyname: username
27+
secretkeyname: password
28+
custom-ca:
29+
<<: *d
30+
bucket: custom-ca-bucket
31+
caConfigMap: custom-ca
32+
custom-ca-with-extra:
33+
<<: *d
34+
bucket: custom-ca-bucket
35+
caConfigMap: custom-ca
36+
prune_spec:
37+
schedule: "10 */4 * * *"
38+
keep_last: 20
39+
keep_daily: 30
40+
check_schedule: "30 3 * * *"
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
apiVersion: k8up.io/v1
2+
kind: Schedule
3+
metadata:
4+
name: custom-ca-with-extra
5+
spec:
6+
backend:
7+
repoPasswordSecretRef:
8+
key: password
9+
name: backup-secret
10+
s3:
11+
accessKeyIDSecretRef:
12+
key: username
13+
name: s3-secret
14+
bucket: custom-ca-bucket
15+
endpoint: https://s3.example.com
16+
secretAccessKeySecretRef:
17+
key: password
18+
name: s3-secret
19+
tlsOptions:
20+
caCert: /mnt/ca/ca.crt
21+
volumeMounts:
22+
- mountPath: /mnt/ca/
23+
name: ca
24+
backup:
25+
keepJobs: 3
26+
promURL: http://platform-prometheus-pushgateway.syn-synsights.svc:9091
27+
schedule: 10 3 * * *
28+
volumes:
29+
- configMap:
30+
name: custom-ca
31+
name: ca
32+
check:
33+
promURL: http://platform-prometheus-pushgateway.syn-synsights.svc:9091
34+
schedule: 30 3 * * *
35+
volumes:
36+
- configMap:
37+
name: custom-ca
38+
name: ca
39+
prune:
40+
retention:
41+
keepDaily: 30
42+
keepLast: 20
43+
schedule: 10 */4 * * *
44+
volumes:
45+
- configMap:
46+
name: custom-ca
47+
name: ca
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
apiVersion: k8up.io/v1
2+
kind: Schedule
3+
metadata:
4+
name: custom-ca
5+
spec:
6+
backend:
7+
repoPasswordSecretRef:
8+
key: password
9+
name: backup-secret
10+
s3:
11+
accessKeyIDSecretRef:
12+
key: username
13+
name: s3-secret
14+
bucket: custom-ca-bucket
15+
endpoint: https://s3.example.com
16+
secretAccessKeySecretRef:
17+
key: password
18+
name: s3-secret
19+
tlsOptions:
20+
caCert: /mnt/ca/ca.crt
21+
volumeMounts:
22+
- mountPath: /mnt/ca/
23+
name: ca
24+
backup:
25+
keepJobs: 3
26+
promURL: http://platform-prometheus-pushgateway.syn-synsights.svc:9091
27+
schedule: 10 3 * * *
28+
volumes:
29+
- configMap:
30+
name: custom-ca
31+
name: ca
32+
check:
33+
promURL: http://platform-prometheus-pushgateway.syn-synsights.svc:9091
34+
schedule: 30 3 * * *
35+
volumes:
36+
- configMap:
37+
name: custom-ca
38+
name: ca
39+
prune:
40+
retention:
41+
keepDaily: 30
42+
keepLast: 5
43+
schedule: 30 2 * * *
44+
volumes:
45+
- configMap:
46+
name: custom-ca
47+
name: ca
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
apiVersion: k8up.io/v1
2+
kind: Schedule
3+
metadata:
4+
name: default
5+
spec:
6+
backend:
7+
repoPasswordSecretRef:
8+
key: password
9+
name: backup-secret
10+
s3:
11+
accessKeyIDSecretRef:
12+
key: username
13+
name: s3-secret
14+
bucket: default-bucket
15+
endpoint: https://s3.example.com
16+
secretAccessKeySecretRef:
17+
key: password
18+
name: s3-secret
19+
backup:
20+
keepJobs: 3
21+
promURL: http://platform-prometheus-pushgateway.syn-synsights.svc:9091
22+
schedule: 10 3 * * *
23+
check:
24+
promURL: http://platform-prometheus-pushgateway.syn-synsights.svc:9091
25+
schedule: 30 3 * * *
26+
prune:
27+
retention:
28+
keepDaily: 30
29+
keepLast: 5
30+
schedule: 30 2 * * *

0 commit comments

Comments
 (0)