@@ -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+
23662449func 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