From 57a76b7a6be3de0dddc45fbb45745ba82340f5f8 Mon Sep 17 00:00:00 2001 From: Alay Patel Date: Thu, 10 Jun 2021 03:39:39 -0400 Subject: [PATCH] skip backuping projected volume Signed-off-by: Alay Patel --- changelogs/unreleased/3866-alaypatel07 | 1 + pkg/restic/common.go | 4 +++ pkg/restic/common_test.go | 35 ++++++++++++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 changelogs/unreleased/3866-alaypatel07 diff --git a/changelogs/unreleased/3866-alaypatel07 b/changelogs/unreleased/3866-alaypatel07 new file mode 100644 index 000000000..7480bc062 --- /dev/null +++ b/changelogs/unreleased/3866-alaypatel07 @@ -0,0 +1 @@ +skip backuping projected volume when using restic \ No newline at end of file diff --git a/pkg/restic/common.go b/pkg/restic/common.go index 5798f0218..5ce15e32e 100644 --- a/pkg/restic/common.go +++ b/pkg/restic/common.go @@ -183,6 +183,10 @@ func GetPodVolumesUsingRestic(pod *corev1api.Pod, defaultVolumesToRestic bool) [ if pv.ConfigMap != nil { continue } + // don't backup volumes mounted as projected volumes, all data in those come from kube state. + if pv.Projected != nil { + continue + } // don't backup volumes that are included in the exclude list. if contains(volsToExclude, pv.Name) { continue diff --git a/pkg/restic/common_test.go b/pkg/restic/common_test.go index d08d1f076..b5e0f1ff9 100644 --- a/pkg/restic/common_test.go +++ b/pkg/restic/common_test.go @@ -507,6 +507,41 @@ func TestGetPodVolumesUsingRestic(t *testing.T) { }, expected: []string{"resticPV1", "resticPV2", "resticPV3"}, }, + { + name: "should exclude projected volumes", + defaultVolumesToRestic: true, + pod: &corev1api.Pod{ + ObjectMeta: metav1.ObjectMeta{ + Annotations: map[string]string{ + VolumesToExcludeAnnotation: "nonResticPV1,nonResticPV2,nonResticPV3", + }, + }, + Spec: corev1api.PodSpec{ + Volumes: []corev1api.Volume{ + {Name: "resticPV1"}, {Name: "resticPV2"}, {Name: "resticPV3"}, + { + Name: "projected", + VolumeSource: corev1api.VolumeSource{ + Projected: &corev1api.ProjectedVolumeSource{ + Sources: []corev1api.VolumeProjection{{ + Secret: &corev1api.SecretProjection{ + LocalObjectReference: corev1api.LocalObjectReference{}, + Items: nil, + Optional: nil, + }, + DownwardAPI: nil, + ConfigMap: nil, + ServiceAccountToken: nil, + }}, + DefaultMode: nil, + }, + }, + }, + }, + }, + }, + expected: []string{"resticPV1", "resticPV2", "resticPV3"}, + }, } for _, tc := range testCases {