Skip to content

Commit 179661e

Browse files
authored
Keep Trilio backups out of volume recovery queue
1 parent 539de6a commit 179661e

3 files changed

Lines changed: 143 additions & 2 deletions

File tree

‎frontend/csi/controller_helpers/kubernetes/config.go‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ const (
9797

9898
// Third-party backup annotations
9999
AnnVeeamKastenBackup = "k10.kasten.io/readyForGCAt"
100+
101+
// Third-party backup labels
102+
LabelK8sAppManagedByKey = "app.kubernetes.io/managed-by"
103+
LabelK8sAppManagedByTrilioValue = "k8s-triliovault"
100104
)
101105

102106
var features = map[controllerhelpers.Feature]*versionutils.Version{

‎frontend/csi/controller_helpers/kubernetes/helper.go‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ func (h *helper) GetVolumeConfig(
134134
// If this is a clone created by a backup vendor, default SkipRecoveryQueue to true.
135135
// If the user already set SkipRecoveryQueue via annotation, respect that value instead.
136136
if volumeConfig.SkipRecoveryQueue == "" && IsEphemeralPVC(pvc) {
137-
Logc(ctx).Debug("Detected backup annotation on PVC; setting SkipRecoveryQueue to true.")
137+
Logc(ctx).Debug("Detected backup vendor metadata on PVC; setting SkipRecoveryQueue to true.")
138138
volumeConfig.SkipRecoveryQueue = "true"
139139
}
140140

@@ -1034,7 +1034,7 @@ func isValidAccessControlPermission(permission string) bool {
10341034

10351035
// IsEphemeralPVC checks whether a PVC being provisioned is an ephemeral one that is part of a backup workflow.
10361036
func IsEphemeralPVC(pvc *v1.PersistentVolumeClaim) bool {
1037-
return IsVeeamKastenEphemeralPVC(pvc)
1037+
return IsVeeamKastenEphemeralPVC(pvc) || IsTrilioEphemeralPVC(pvc)
10381038
}
10391039

10401040
// IsVeeamKastenEphemeralPVC checks if a PVC is part of a Veeam Kasten workflow.
@@ -1047,3 +1047,14 @@ func IsVeeamKastenEphemeralPVC(pvc *v1.PersistentVolumeClaim) bool {
10471047
value, exists := pvc.Annotations[AnnVeeamKastenBackup]
10481048
return exists && value != ""
10491049
}
1050+
1051+
// IsTrilioEphemeralPVC checks if a PVC is part of a TrilioVault workflow.
1052+
func IsTrilioEphemeralPVC(pvc *v1.PersistentVolumeClaim) bool {
1053+
if pvc == nil {
1054+
return false
1055+
}
1056+
1057+
// Check for the well-known TrilioVault managed-by label on the PVC.
1058+
value, exists := pvc.Labels[LabelK8sAppManagedByKey]
1059+
return exists && value == LabelK8sAppManagedByTrilioValue
1060+
}

‎frontend/csi/controller_helpers/kubernetes/helper_test.go‎

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2363,6 +2363,89 @@ func TestIsVeeamKastenEphemeralPVC(t *testing.T) {
23632363
}
23642364
}
23652365

2366+
func TestIsTrilioEphemeralPVC(t *testing.T) {
2367+
tests := []struct {
2368+
name string
2369+
pvc *v1.PersistentVolumeClaim
2370+
expected bool
2371+
}{
2372+
{
2373+
name: "Nil PVC",
2374+
pvc: nil,
2375+
expected: false,
2376+
},
2377+
{
2378+
name: "PVC with Trilio managed-by label",
2379+
pvc: &v1.PersistentVolumeClaim{
2380+
ObjectMeta: metav1.ObjectMeta{
2381+
Labels: map[string]string{
2382+
LabelK8sAppManagedByKey: LabelK8sAppManagedByTrilioValue,
2383+
},
2384+
},
2385+
},
2386+
expected: true,
2387+
},
2388+
{
2389+
name: "PVC with managed-by label set to a different value",
2390+
pvc: &v1.PersistentVolumeClaim{
2391+
ObjectMeta: metav1.ObjectMeta{
2392+
Labels: map[string]string{
2393+
LabelK8sAppManagedByKey: "some-other-tool",
2394+
},
2395+
},
2396+
},
2397+
expected: false,
2398+
},
2399+
{
2400+
name: "PVC without managed-by label",
2401+
pvc: &v1.PersistentVolumeClaim{
2402+
ObjectMeta: metav1.ObjectMeta{
2403+
Labels: map[string]string{
2404+
"some-other-key": "value",
2405+
},
2406+
},
2407+
},
2408+
expected: false,
2409+
},
2410+
{
2411+
name: "PVC with empty labels",
2412+
pvc: &v1.PersistentVolumeClaim{
2413+
ObjectMeta: metav1.ObjectMeta{
2414+
Labels: map[string]string{},
2415+
},
2416+
},
2417+
expected: false,
2418+
},
2419+
{
2420+
name: "PVC with nil labels",
2421+
pvc: &v1.PersistentVolumeClaim{
2422+
ObjectMeta: metav1.ObjectMeta{
2423+
Labels: nil,
2424+
},
2425+
},
2426+
expected: false,
2427+
},
2428+
{
2429+
name: "PVC with managed-by label set to empty string",
2430+
pvc: &v1.PersistentVolumeClaim{
2431+
ObjectMeta: metav1.ObjectMeta{
2432+
Labels: map[string]string{
2433+
LabelK8sAppManagedByKey: "",
2434+
},
2435+
},
2436+
},
2437+
expected: false,
2438+
},
2439+
}
2440+
2441+
for _, tt := range tests {
2442+
t.Run(tt.name, func(t *testing.T) {
2443+
result := IsTrilioEphemeralPVC(tt.pvc)
2444+
assert.Equal(t, tt.expected, result)
2445+
})
2446+
}
2447+
}
2448+
23662449
func TestIsEphemeralPVC(t *testing.T) {
23672450
tests := []struct {
23682451
name string
@@ -2380,6 +2463,17 @@ func TestIsEphemeralPVC(t *testing.T) {
23802463
},
23812464
expected: true,
23822465
},
2466+
{
2467+
name: "Trilio ephemeral PVC",
2468+
pvc: &v1.PersistentVolumeClaim{
2469+
ObjectMeta: metav1.ObjectMeta{
2470+
Labels: map[string]string{
2471+
LabelK8sAppManagedByKey: LabelK8sAppManagedByTrilioValue,
2472+
},
2473+
},
2474+
},
2475+
expected: true,
2476+
},
23832477
{
23842478
name: "No backup vendor - regular PVC",
23852479
pvc: &v1.PersistentVolumeClaim{
@@ -2391,6 +2485,17 @@ func TestIsEphemeralPVC(t *testing.T) {
23912485
},
23922486
expected: false,
23932487
},
2488+
{
2489+
name: "Non-matching managed-by label - regular PVC",
2490+
pvc: &v1.PersistentVolumeClaim{
2491+
ObjectMeta: metav1.ObjectMeta{
2492+
Labels: map[string]string{
2493+
LabelK8sAppManagedByKey: "some-other-tool",
2494+
},
2495+
},
2496+
},
2497+
expected: false,
2498+
},
23942499
{
23952500
name: "Empty PVC",
23962501
pvc: &v1.PersistentVolumeClaim{
@@ -2420,6 +2525,7 @@ func TestGetVolumeConfig_SkipRecoveryQueue(t *testing.T) {
24202525
name string
24212526
pvcName string
24222527
pvcAnnotations map[string]string
2528+
pvcLabels map[string]string
24232529
expectedSkipRecoveryQueue string
24242530
}{
24252531
{
@@ -2430,6 +2536,14 @@ func TestGetVolumeConfig_SkipRecoveryQueue(t *testing.T) {
24302536
},
24312537
expectedSkipRecoveryQueue: "true",
24322538
},
2539+
{
2540+
name: "Trilio ephemeral PVC defaults SkipRecoveryQueue to true",
2541+
pvcName: "trilio-pvc",
2542+
pvcLabels: map[string]string{
2543+
LabelK8sAppManagedByKey: LabelK8sAppManagedByTrilioValue,
2544+
},
2545+
expectedSkipRecoveryQueue: "true",
2546+
},
24332547
{
24342548
name: "non-ephemeral PVC leaves SkipRecoveryQueue empty",
24352549
pvcName: "regular-pvc",
@@ -2445,6 +2559,17 @@ func TestGetVolumeConfig_SkipRecoveryQueue(t *testing.T) {
24452559
},
24462560
expectedSkipRecoveryQueue: "false",
24472561
},
2562+
{
2563+
name: "Trilio ephemeral PVC with explicit annotation preserves annotation value",
2564+
pvcName: "trilio-pvc-explicit",
2565+
pvcAnnotations: map[string]string{
2566+
AnnSkipRecoveryQueue: "false",
2567+
},
2568+
pvcLabels: map[string]string{
2569+
LabelK8sAppManagedByKey: LabelK8sAppManagedByTrilioValue,
2570+
},
2571+
expectedSkipRecoveryQueue: "false",
2572+
},
24482573
}
24492574

24502575
for _, tt := range tests {
@@ -2455,6 +2580,7 @@ func TestGetVolumeConfig_SkipRecoveryQueue(t *testing.T) {
24552580
Namespace: "default",
24562581
UID: pvcUID,
24572582
Annotations: tt.pvcAnnotations,
2583+
Labels: tt.pvcLabels,
24582584
},
24592585
Spec: v1.PersistentVolumeClaimSpec{
24602586
StorageClassName: &scName,

0 commit comments

Comments
 (0)