From 2a55dbf7db65a8d9a3215cab159fde4f9b81eda5 Mon Sep 17 00:00:00 2001 From: Ovidijus Balkauskas <570945@gmail.com> Date: Tue, 19 Mar 2024 15:43:04 +0200 Subject: [PATCH 1/4] Add option to ignore PVCs without annotation Signed-off-by: Ovidijus Balkauskas <570945@gmail.com> --- charts/k8up/Chart.yaml | 2 +- charts/k8up/templates/deployment.yaml | 2 ++ charts/k8up/values.yaml | 3 +++ cmd/operator/main.go | 1 + docs/modules/ROOT/examples/usage/operator.txt | 1 + .../ROOT/pages/how-tos/application-aware-backups.adoc | 2 ++ docs/modules/ROOT/pages/how-tos/backup.adoc | 2 ++ docs/modules/ROOT/pages/how-tos/schedules.adoc | 2 +- docs/modules/ROOT/pages/references/annotations.adoc | 2 +- operator/backupcontroller/executor.go | 7 ++++++- operator/cfg/config.go | 1 + 11 files changed, 21 insertions(+), 4 deletions(-) diff --git a/charts/k8up/Chart.yaml b/charts/k8up/Chart.yaml index 2c9a308aa..5ba505310 100644 --- a/charts/k8up/Chart.yaml +++ b/charts/k8up/Chart.yaml @@ -6,7 +6,7 @@ keywords: - backup - operator - restic -version: 4.5.0 +version: 4.5.1 sources: - https://github.com/k8up-io/k8up maintainers: diff --git a/charts/k8up/templates/deployment.yaml b/charts/k8up/templates/deployment.yaml index 6f0a45cc1..fbceb5b02 100644 --- a/charts/k8up/templates/deployment.yaml +++ b/charts/k8up/templates/deployment.yaml @@ -38,6 +38,8 @@ spec: {{- end }} - name: BACKUP_ENABLE_LEADER_ELECTION value: "{{ .Values.k8up.enableLeaderElection }}" + - name: BACKUP_SKIP_WITHOUT_ANNOTATION + value: "{{ .Values.k8up.skipWithoutAnnotation }}" - name: BACKUP_OPERATOR_NAMESPACE {{- if .Values.k8up.operatorNamespace }} value: "{{ .Values.k8up.operatorNamespace }}" diff --git a/charts/k8up/values.yaml b/charts/k8up/values.yaml index 6897c4e03..47e18e1de 100644 --- a/charts/k8up/values.yaml +++ b/charts/k8up/values.yaml @@ -50,6 +50,9 @@ k8up: # -- Specifies whether leader election should be enabled. enableLeaderElection: true + # -- Specifies whether K8up should ignore PVCs without the backup annotation (by default, `k8up.io/backup`) + skipWithoutAnnotation: false + # -- Specifies the namespace in which K8up's `EffectiveSchedules` are stored. # Defaults to release namespace if left empty. operatorNamespace: "" diff --git a/cmd/operator/main.go b/cmd/operator/main.go index 90df903ae..e4eefa99c 100644 --- a/cmd/operator/main.go +++ b/cmd/operator/main.go @@ -80,6 +80,7 @@ var ( &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"}, &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"}, + &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"}, &cli.StringFlag{Destination: &cfg.Config.BackupCheckSchedule, Name: "checkschedule", EnvVars: []string{"BACKUP_CHECKSCHEDULE"}, Value: "0 0 * * 0", Usage: "the default check schedule"}, &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"}, }, diff --git a/docs/modules/ROOT/examples/usage/operator.txt b/docs/modules/ROOT/examples/usage/operator.txt index d0aa62877..928e124fd 100644 --- a/docs/modules/ROOT/examples/usage/operator.txt +++ b/docs/modules/ROOT/examples/usage/operator.txt @@ -43,6 +43,7 @@ OPTIONS: --podexecaccountname value, --serviceaccount value set the service account name that should be used for the pod command execution (default: "pod-executor") [$BACKUP_PODEXECACCOUNTNAME] --podexecrolename value set the role name that should be used for pod command execution (default: "pod-executor") [$BACKUP_PODEXECROLENAME] --enable-leader-election enable leader election within the operator Pod (default: enabled) [$BACKUP_ENABLE_LEADER_ELECTION] + --skip-pvcs-without-annotation skip selecting PVCs that don't have the BACKUP_ANNOTATION (default: disabled) [$BACKUP_SKIP_WITHOUT_ANNOTATION] --checkschedule value the default check schedule (default: "0 0 * * 0") [$BACKUP_CHECKSCHEDULE] --operator-namespace value set the namespace in which the K8up operator itself runs [$BACKUP_OPERATOR_NAMESPACE] --help, -h show help (default: false) diff --git a/docs/modules/ROOT/pages/how-tos/application-aware-backups.adoc b/docs/modules/ROOT/pages/how-tos/application-aware-backups.adoc index 9efa3fd94..12ac23c33 100644 --- a/docs/modules/ROOT/pages/how-tos/application-aware-backups.adoc +++ b/docs/modules/ROOT/pages/how-tos/application-aware-backups.adoc @@ -29,6 +29,8 @@ Tested with: But it should work with any command that has the ability to output the backup to stdout. +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. + == PostgreSQL Note that the PostgreSQL image used requires the utility `pg_dump`. diff --git a/docs/modules/ROOT/pages/how-tos/backup.adoc b/docs/modules/ROOT/pages/how-tos/backup.adoc index ddc261dab..bcdf928c1 100644 --- a/docs/modules/ROOT/pages/how-tos/backup.adoc +++ b/docs/modules/ROOT/pages/how-tos/backup.adoc @@ -10,3 +10,5 @@ include::example$tutorial/backup.yaml[] 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. TIP: To have backups run automatically at a regular interval look at xref:how-tos/schedules.adoc[schedules]. + +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. diff --git a/docs/modules/ROOT/pages/how-tos/schedules.adoc b/docs/modules/ROOT/pages/how-tos/schedules.adoc index f9a33c532..f86fb58bd 100644 --- a/docs/modules/ROOT/pages/how-tos/schedules.adoc +++ b/docs/modules/ROOT/pages/how-tos/schedules.adoc @@ -13,4 +13,4 @@ The file above will instruct the Operator to do backups every 5 minute, prune th 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]. -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. +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. diff --git a/docs/modules/ROOT/pages/references/annotations.adoc b/docs/modules/ROOT/pages/references/annotations.adoc index b8340fe16..ed4a75d9d 100644 --- a/docs/modules/ROOT/pages/references/annotations.adoc +++ b/docs/modules/ROOT/pages/references/annotations.adoc @@ -12,7 +12,7 @@ See xref:references/operator-config-reference.adoc[Operator Configuration refere |Annotation |Description |Accepted Values |Applicable Resources |xref:references/operator-config-reference.adoc[Configuration Option] |`k8up.io/backup` -|If defined, this influences whether this pod shall be backed up (`true`) or not (`false`) +|If defined, this influences whether this Pod/PVC shall be backed up (`true`) or not (`false`). If omitted, K8up will default to `true`, unless `$BACKUP_SKIP_WITHOUT_ANNOTATION` is set to `true`. |Either `'true'` or `'false'` |`Pod`, `PersistentVolumeClaim` |`BACKUP_ANNOTATION` diff --git a/operator/backupcontroller/executor.go b/operator/backupcontroller/executor.go index a921e596f..32456029f 100644 --- a/operator/backupcontroller/executor.go +++ b/operator/backupcontroller/executor.go @@ -98,7 +98,12 @@ func (b *BackupExecutor) listAndFilterPVCs(ctx context.Context, annotation strin } if !hasBackupAnnotation { - log.Info("PVC doesn't have annotation, adding to list", "pvc", pvc.GetName()) + if cfg.Config.SkipWithoutAnnotation { + log.Info("PVC doesn't have annotation and BACKUP_SKIP_WITHOUT_ANNOTATION is true, skipping PVC", "pvc", pvc.GetName()) + continue + } else { + log.Info("PVC doesn't have annotation, adding to list", "pvc", pvc.GetName()) + } } else if shouldBackup, _ := strconv.ParseBool(backupAnnotation); !shouldBackup { log.Info("PVC skipped due to annotation", "pvc", pvc.GetName(), "annotation", backupAnnotation) continue diff --git a/operator/cfg/config.go b/operator/cfg/config.go index ac732ee06..086d526f7 100644 --- a/operator/cfg/config.go +++ b/operator/cfg/config.go @@ -76,6 +76,7 @@ type Configuration struct { PodFilter string PromURL string RestartPolicy string + SkipWithoutAnnotation bool // Enabling this will ensure there is only one active controller manager. EnableLeaderElection bool From 24e1796977107985b0b4d60eda368f337abead00 Mon Sep 17 00:00:00 2001 From: Ovidijus Balkauskas <570945@gmail.com> Date: Tue, 19 Mar 2024 17:33:37 +0200 Subject: [PATCH 2/4] Generate chart docs for 4.5.1 Signed-off-by: Ovidijus Balkauskas <570945@gmail.com> --- charts/k8up/README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/charts/k8up/README.md b/charts/k8up/README.md index 47544d633..bf7e622f2 100644 --- a/charts/k8up/README.md +++ b/charts/k8up/README.md @@ -1,6 +1,6 @@ # k8up -![Version: 4.5.0](https://img.shields.io/badge/Version-4.5.0-informational?style=flat-square) +![Version: 4.5.1](https://img.shields.io/badge/Version-4.5.1-informational?style=flat-square) Kubernetes and OpenShift Backup Operator based on restic @@ -13,7 +13,7 @@ helm repo add k8up-io https://k8up-io.github.io/k8up helm install k8up k8up-io/k8up ``` ```bash -kubectl apply -f https://github.com/k8up-io/k8up/releases/download/k8up-4.5.0/k8up-crd.yaml +kubectl apply -f https://github.com/k8up-io/k8up/releases/download/k8up-4.5.1/k8up-crd.yaml ```