Skip to content

Commit 0139209

Browse files
authored
Merge pull request #1196 from xantrix/skip-snapshot-sync
Add BACKUP_GLOBAL_SKIP_SNAPSHOT_SYNC flag
2 parents 85c54b8 + b1cd5eb commit 0139209

10 files changed

Lines changed: 29 additions & 8 deletions

File tree

charts/k8up/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ Document your changes in values.yaml and let `make docs:helm` generate this sect
6161
| k8up.globalResources.requests.cpu | string | `""` | Global CPU resource requests applied to jobs. See [supported units][resource-units]. |
6262
| k8up.globalResources.requests.memory | string | `""` | Global Memory resource requests applied to jobs. See [supported units][resource-units]. |
6363
| k8up.operatorNamespace | string | `""` | Specifies the namespace in which K8up's `EffectiveSchedules` are stored. Defaults to release namespace if left empty. |
64+
| k8up.skipSnapshotSync | bool | `false` | Specifies whether K8up should skip synchronizing Snapshot custom resources to the cluster after backup or prune operations. When enabled, the operator passes `BACKUP_SKIP_SNAPSHOT_SYNC=true` to backup and prune job pods. Webhook notifications are still sent. |
6465
| k8up.skipWithoutAnnotation | bool | `false` | Specifies whether K8up should ignore PVCs without the backup annotation (by default, `k8up.io/backup`) |
6566
| 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` |
6667
| metrics.grafanaDashboard.additionalLabels | object | `{}` | Add labels to the Grafana Dashboard object |

charts/k8up/templates/deployment.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ spec:
4141
value: "{{ .Values.k8up.enableLeaderElection }}"
4242
- name: BACKUP_SKIP_WITHOUT_ANNOTATION
4343
value: "{{ .Values.k8up.skipWithoutAnnotation }}"
44+
- name: BACKUP_GLOBAL_SKIP_SNAPSHOT_SYNC
45+
value: "{{ .Values.k8up.skipSnapshotSync }}"
4446
- name: BACKUP_OPERATOR_NAMESPACE
4547
{{- if .Values.k8up.operatorNamespace }}
4648
value: "{{ .Values.k8up.operatorNamespace }}"

charts/k8up/test/deployment_test.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,13 @@ func Test_Deployment_ShouldRender_EnvironmentVariables(t *testing.T) {
3838
assert.Equal(t, "TZ", envs[1].Name)
3939
assert.Equal(t, wantTimezone, envs[1].Value)
4040
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_GLOBAL_CPU_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")
41+
assert.Equal(t, "BACKUP_GLOBAL_SKIP_SNAPSHOT_SYNC", envs[4].Name)
42+
assert.Equal(t, "BACKUP_OPERATOR_NAMESPACE", envs[5].Name)
43+
assert.Equal(t, "metadata.namespace", envs[5].ValueFrom.FieldRef.FieldPath)
44+
assert.Equal(t, "BACKUP_GLOBAL_CPU_REQUEST", envs[6].Name, "Deployment does not use configured Env Name")
45+
assert.Equal(t, wantCpuRequest, envs[6].Value, "Deployment does not use configured Env Value")
46+
assert.Equal(t, "VARIABLE", envs[7].Name, "Deployment does not use configured Env Name")
47+
assert.Equal(t, "VALUE", envs[7].Value, "Deployment does not use configured Env Value")
4748
}
4849

4950
func Test_Deployment_ShouldRender_Affinity(t *testing.T) {
@@ -92,8 +93,8 @@ func Test_Deployment_ShouldRender_OverrideNamespace(t *testing.T) {
9293
got := renderDeployment(t, options, false)
9394

9495
assert.Equal(t, overrideNamespace, got.Namespace, "Deployment should use the overridden namespace")
95-
assert.Equal(t, "BACKUP_OPERATOR_NAMESPACE", got.Spec.Template.Spec.Containers[0].Env[3].Name)
96-
assert.Equal(t, "metadata.namespace", got.Spec.Template.Spec.Containers[0].Env[3].ValueFrom.FieldRef.FieldPath)
96+
assert.Equal(t, "BACKUP_OPERATOR_NAMESPACE", got.Spec.Template.Spec.Containers[0].Env[4].Name)
97+
assert.Equal(t, "metadata.namespace", got.Spec.Template.Spec.Containers[0].Env[4].ValueFrom.FieldRef.FieldPath)
9798
}
9899

99100
func Test_Deployment_ShouldRender_Resources(t *testing.T) {

charts/k8up/values.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ k8up:
5656
# -- Specifies whether K8up should ignore PVCs without the backup annotation (by default, `k8up.io/backup`)
5757
skipWithoutAnnotation: false
5858

59+
# -- Specifies whether K8up should skip synchronizing Snapshot custom resources to the cluster after backup or prune operations.
60+
# When enabled, the operator passes `BACKUP_SKIP_SNAPSHOT_SYNC=true` to backup and prune job pods. Webhook notifications are still sent.
61+
skipSnapshotSync: false
62+
5963
# -- Specifies the namespace in which K8up's `EffectiveSchedules` are stored.
6064
# Defaults to release namespace if left empty.
6165
operatorNamespace: ""

cmd/operator/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ var (
8585
&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"},
8686
&cli.BoolFlag{Destination: &cfg.Config.EnableRelaxedScheduling, Name: "enable-relaxed-scheduling", EnvVars: []string{"BACKUP_ENABLE_RELAXED_SCHEDULING"}, Value: false, DefaultText: "disabled", Usage: "enable relaxed scheduling of backup jobs relying on the Kubernetes scheduler"},
8787
&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"},
88+
&cli.BoolFlag{Destination: &cfg.Config.SkipSnapshotSync, Name: "global-skip-snapshot-sync", EnvVars: []string{"BACKUP_GLOBAL_SKIP_SNAPSHOT_SYNC"}, Value: false, DefaultText: "disabled", Usage: "if set, skip synchronizing Snapshot custom resources to the cluster after backup or prune operations. This sets the BACKUP_SKIP_SNAPSHOT_SYNC env var on backup and prune job pods."},
8889
&cli.StringFlag{Destination: &cfg.Config.BackupCheckSchedule, Name: "checkschedule", EnvVars: []string{"BACKUP_CHECKSCHEDULE"}, Value: "0 0 * * 0", Usage: "the default check schedule"},
8990
&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"},
9091

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ OPTIONS:
4949
--enable-leader-election enable leader election within the operator Pod (default: enabled) [$BACKUP_ENABLE_LEADER_ELECTION]
5050
--enable-relaxed-scheduling enable relaxed scheduling of backup jobs relying on the Kubernetes scheduler (default: disabled) [$BACKUP_ENABLE_RELAXED_SCHEDULING]
5151
--skip-pvcs-without-annotation skip selecting PVCs that don't have the BACKUP_ANNOTATION (default: disabled) [$BACKUP_SKIP_WITHOUT_ANNOTATION]
52+
--global-skip-snapshot-sync if set, skip synchronizing Snapshot custom resources to the cluster after backup or prune operations. This sets the BACKUP_SKIP_SNAPSHOT_SYNC env var on backup and prune job pods. (default: disabled) [$BACKUP_GLOBAL_SKIP_SNAPSHOT_SYNC]
5253
--checkschedule value the default check schedule (default: "0 0 * * 0") [$BACKUP_CHECKSCHEDULE]
5354
--operator-namespace value set the namespace in which the K8up operator itself runs [$BACKUP_OPERATOR_NAMESPACE]
5455
--insecure-allow-podexec-spdy-fallback enable fallback to SPDY connections for data streaming used by application aware backups. Might need to be enabled if the cluster has Kubernetes version 1.30 or lower. K8up uses WebSockets by default. CAUTION: Has been observed to cause silent data corruption in some network setups, use at own risk! (default: false) [$INSECURE_ALLOW_PODEXEC_SPDY_FALLBACK]

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ TIP: Deploying this configuration also creates a Backup of the current state and
1515

1616
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.
1717

18+
TIP: By default, K8up synchronizes Snapshot custom resources to the cluster after backup operations. You can disable this globally by setting the operator environment variable `BACKUP_GLOBAL_SKIP_SNAPSHOT_SYNC=true`. Webhook notifications are still sent even when snapshot synchronization is disabled.
19+
1820
== Self-signed issuer and Mutual TLS
1921

2022
If you are using self-signed issuer or using mutual tls for authenticate client, you're able use a volume for mounting cert files into the backup object.

operator/backupcontroller/backup_utils.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,10 @@ func (b *BackupExecutor) setupEnvVars() ([]corev1.EnvVar, error) {
193193
vars.SetString("BACKUPCOMMAND_ANNOTATION", cfg.Config.BackupCommandAnnotation)
194194
vars.SetString("FILEEXTENSION_ANNOTATION", cfg.Config.FileExtensionAnnotation)
195195

196+
if cfg.Config.SkipSnapshotSync {
197+
vars.SetString("BACKUP_SKIP_SNAPSHOT_SYNC", "true")
198+
}
199+
196200
err := vars.Merge(executor.DefaultEnv(b.backup.GetNamespace()))
197201
if err != nil {
198202
return nil, fmt.Errorf("cannot merge environment variables: %w", err)

operator/cfg/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ type Configuration struct {
8484
ClusterName string
8585
RestartPolicy string
8686
SkipWithoutAnnotation bool
87+
SkipSnapshotSync bool
8788
EnableRelaxedScheduling bool
8889
InsecureAllowPodExecSPDYFallback bool
8990

operator/prunecontroller/executor.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ func (p *PruneExecutor) setupEnvVars(ctx context.Context, prune *k8upv1.Prune) [
136136

137137
vars.SetString("PROM_URL", cfg.Config.PromURL)
138138

139+
if cfg.Config.SkipSnapshotSync {
140+
vars.SetString("BACKUP_SKIP_SNAPSHOT_SYNC", "true")
141+
}
142+
139143
err := vars.Merge(executor.DefaultEnv(p.Obj.GetNamespace()))
140144
if err != nil {
141145
log.Error(err, "error while merging the environment variables", "name", p.Obj.GetName(), "namespace", p.Obj.GetNamespace())

0 commit comments

Comments
 (0)