Skip to content

Commit b16b4bf

Browse files
authored
Merge pull request k8up-io#948 from Stogas/master
Add option to ignore PVCs without annotation
2 parents 99eef08 + 8da2222 commit b16b4bf

13 files changed

Lines changed: 31 additions & 12 deletions

File tree

charts/k8up/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ keywords:
66
- backup
77
- operator
88
- restic
9-
version: 4.5.0
9+
version: 4.5.1
1010
sources:
1111
- https://github.com/k8up-io/k8up
1212
maintainers:

charts/k8up/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# k8up
22

3-
![Version: 4.5.0](https://img.shields.io/badge/Version-4.5.0-informational?style=flat-square)
3+
![Version: 4.5.1](https://img.shields.io/badge/Version-4.5.1-informational?style=flat-square)
44

55
Kubernetes and OpenShift Backup Operator based on restic
66

@@ -13,7 +13,7 @@ helm repo add k8up-io https://k8up-io.github.io/k8up
1313
helm install k8up k8up-io/k8up
1414
```
1515
```bash
16-
kubectl apply -f https://github.com/k8up-io/k8up/releases/download/k8up-4.5.0/k8up-crd.yaml
16+
kubectl apply -f https://github.com/k8up-io/k8up/releases/download/k8up-4.5.1/k8up-crd.yaml
1717
```
1818

1919
<!---
@@ -60,6 +60,7 @@ Document your changes in values.yaml and let `make docs:helm` generate this sect
6060
| k8up.globalResources.requests.cpu | string | `""` | Global CPU resource requests applied to jobs. See [supported units][resource-units]. |
6161
| k8up.globalResources.requests.memory | string | `""` | Global Memory resource requests applied to jobs. See [supported units][resource-units]. |
6262
| k8up.operatorNamespace | string | `""` | Specifies the namespace in which K8up's `EffectiveSchedules` are stored. Defaults to release namespace if left empty. |
63+
| k8up.skipWithoutAnnotation | bool | `false` | Specifies whether K8up should ignore PVCs without the backup annotation (by default, `k8up.io/backup`) |
6364
| k8up.timezone | string | `""` | Specifies the timezone K8up is using for scheduling. Empty value defaults to the timezone in which Kubernetes is deployed. Accepts `tz database` compatible entries, e.g. `Europe/Zurich` |
6465
| metrics.prometheusRule.additionalLabels | object | `{}` | Add labels to the PrometheusRule object |
6566
| metrics.prometheusRule.additionalRules | list | `[]` | Provide additional alert rules in addition to the defaults |

charts/k8up/templates/deployment.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ spec:
3838
{{- end }}
3939
- name: BACKUP_ENABLE_LEADER_ELECTION
4040
value: "{{ .Values.k8up.enableLeaderElection }}"
41+
- name: BACKUP_SKIP_WITHOUT_ANNOTATION
42+
value: "{{ .Values.k8up.skipWithoutAnnotation }}"
4143
- name: BACKUP_OPERATOR_NAMESPACE
4244
{{- if .Values.k8up.operatorNamespace }}
4345
value: "{{ .Values.k8up.operatorNamespace }}"

charts/k8up/test/deployment_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,13 @@ func Test_Deployment_ShouldRender_EnvironmentVariables(t *testing.T) {
3737
assert.Equalf(t, wantRepo+":"+wantTag, envs[0].Value, "Deployment does not use required Env Value from %s", wantVar)
3838
assert.Equal(t, "TZ", envs[1].Name)
3939
assert.Equal(t, wantTimezone, envs[1].Value)
40-
assert.Equal(t, "BACKUP_OPERATOR_NAMESPACE", envs[3].Name)
41-
assert.Equal(t, "metadata.namespace", envs[3].ValueFrom.FieldRef.FieldPath)
42-
assert.Equal(t, "BACKUP_GLOBALCPU_REQUEST", envs[4].Name, "Deployment does not use configured Env Name")
43-
assert.Equal(t, wantCpuRequest, envs[4].Value, "Deployment does not use configured Env Value")
44-
assert.Equal(t, "VARIABLE", envs[5].Name, "Deployment does not use configured Env Name")
45-
assert.Equal(t, "VALUE", envs[5].Value, "Deployment does not use configured Env Value")
40+
assert.Equal(t, "BACKUP_SKIP_WITHOUT_ANNOTATION", envs[3].Name)
41+
assert.Equal(t, "BACKUP_OPERATOR_NAMESPACE", envs[4].Name)
42+
assert.Equal(t, "metadata.namespace", envs[4].ValueFrom.FieldRef.FieldPath)
43+
assert.Equal(t, "BACKUP_GLOBALCPU_REQUEST", envs[5].Name, "Deployment does not use configured Env Name")
44+
assert.Equal(t, wantCpuRequest, envs[5].Value, "Deployment does not use configured Env Value")
45+
assert.Equal(t, "VARIABLE", envs[6].Name, "Deployment does not use configured Env Name")
46+
assert.Equal(t, "VALUE", envs[6].Value, "Deployment does not use configured Env Value")
4647
}
4748

4849
func Test_Deployment_ShouldRender_Affinity(t *testing.T) {

charts/k8up/values.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ k8up:
5050
# -- Specifies whether leader election should be enabled.
5151
enableLeaderElection: true
5252

53+
# -- Specifies whether K8up should ignore PVCs without the backup annotation (by default, `k8up.io/backup`)
54+
skipWithoutAnnotation: false
55+
5356
# -- Specifies the namespace in which K8up's `EffectiveSchedules` are stored.
5457
# Defaults to release namespace if left empty.
5558
operatorNamespace: ""

cmd/operator/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ var (
8080
&cli.StringFlag{Destination: &cfg.Config.PodExecRoleName, Name: "podexecrolename", EnvVars: []string{"BACKUP_PODEXECROLENAME"}, Value: "pod-executor", Usage: "set the role name that should be used for pod command execution"},
8181

8282
&cli.BoolFlag{Destination: &cfg.Config.EnableLeaderElection, Name: "enable-leader-election", EnvVars: []string{"BACKUP_ENABLE_LEADER_ELECTION"}, Value: true, DefaultText: "enabled", Usage: "enable leader election within the operator Pod"},
83+
&cli.BoolFlag{Destination: &cfg.Config.SkipWithoutAnnotation, Name: "skip-pvcs-without-annotation", EnvVars: []string{"BACKUP_SKIP_WITHOUT_ANNOTATION"}, Value: false, DefaultText: "disabled", Usage: "skip selecting PVCs that don't have the BACKUP_ANNOTATION"},
8384
&cli.StringFlag{Destination: &cfg.Config.BackupCheckSchedule, Name: "checkschedule", EnvVars: []string{"BACKUP_CHECKSCHEDULE"}, Value: "0 0 * * 0", Usage: "the default check schedule"},
8485
&cli.StringFlag{Destination: &cfg.Config.OperatorNamespace, Name: "operator-namespace", EnvVars: []string{"BACKUP_OPERATOR_NAMESPACE"}, Required: true, Usage: "set the namespace in which the K8up operator itself runs"},
8586
},

docs/modules/ROOT/examples/usage/operator.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ OPTIONS:
4343
--podexecaccountname value, --serviceaccount value set the service account name that should be used for the pod command execution (default: "pod-executor") [$BACKUP_PODEXECACCOUNTNAME]
4444
--podexecrolename value set the role name that should be used for pod command execution (default: "pod-executor") [$BACKUP_PODEXECROLENAME]
4545
--enable-leader-election enable leader election within the operator Pod (default: enabled) [$BACKUP_ENABLE_LEADER_ELECTION]
46+
--skip-pvcs-without-annotation skip selecting PVCs that don't have the BACKUP_ANNOTATION (default: disabled) [$BACKUP_SKIP_WITHOUT_ANNOTATION]
4647
--checkschedule value the default check schedule (default: "0 0 * * 0") [$BACKUP_CHECKSCHEDULE]
4748
--operator-namespace value set the namespace in which the K8up operator itself runs [$BACKUP_OPERATOR_NAMESPACE]
4849
--help, -h show help (default: false)

docs/modules/ROOT/pages/how-tos/application-aware-backups.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ Tested with:
2929
3030
But it should work with any command that has the ability to output the backup to stdout.
3131

32+
TIP: By default, all PVCs are backed up automatically. If you are using Application-Aware Backups and want to skip backing up any related PVCs, adding the annotation `k8up.io/backup=false` to a PVC object will exclude it from all following backups. Alternatively, you can set the environment variable `BACKUP_SKIP_WITHOUT_ANNOTATION=true` if you want K8up to ignore objects without the annotation.
33+
3234
== PostgreSQL
3335

3436
Note that the PostgreSQL image used requires the utility `pg_dump`.

docs/modules/ROOT/pages/how-tos/backup.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ include::example$tutorial/backup.yaml[]
1010
Save the YAML above in a file named `backup.yaml` and use the `kubectl apply -f backup.yaml` command to deploy this configuration to your cluster.
1111

1212
TIP: To have backups run automatically at a regular interval look at xref:how-tos/schedules.adoc[schedules].
13+
14+
TIP: By default, all PVCs are backed up automatically. Adding the annotation `k8up.io/backup=false` to a PVC object will exclude it from all following backups. Alternatively, you can set the environment variable `BACKUP_SKIP_WITHOUT_ANNOTATION=true` if you want K8up to ignore objects without the annotation.

docs/modules/ROOT/pages/how-tos/schedules.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ The file above will instruct the Operator to do backups every 5 minute, prune th
1313

1414
Feel free to adjust the frequencies to your liking. To help you with the crontab syntax, we recommend to check out https://crontab.guru[crontab.guru].
1515

16-
TIP: You can always check the state and configuration of your backup by using `kubectl describe schedule`. By default, all PVCs are backed up automatically. Adding the annotation `k8up.io/backup=false` to a PVC object will excluded it from all following backup.
16+
TIP: You can always check the state and configuration of your backup by using `kubectl describe schedule`. By default, all PVCs are backed up automatically. Adding the annotation `k8up.io/backup=false` to a PVC object will exclude it from all following backups. Alternatively, you can set the environment variable `BACKUP_SKIP_WITHOUT_ANNOTATION=true` if you want K8up to ignore objects without the annotation.

0 commit comments

Comments
 (0)