Add labels as a criteria for volume policy (#8713)
Some checks failed
Run the E2E test on kind / build (push) Failing after 6m23s
Run the E2E test on kind / setup-test-matrix (push) Successful in 3s
Run the E2E test on kind / run-e2e-test (push) Has been skipped
Main CI / Build (push) Failing after 38s
Close stale issues and PRs / stale (push) Successful in 9s
Trivy Nightly Scan / Trivy nightly scan (velero, main) (push) Failing after 1m5s
Trivy Nightly Scan / Trivy nightly scan (velero-restore-helper, main) (push) Failing after 55s

* Add labels as a criteria for volume policy

Signed-off-by: Shubham Pampattiwar <spampatt@redhat.com>

add changelog file

Signed-off-by: Shubham Pampattiwar <spampatt@redhat.com>

handle err

Signed-off-by: Shubham Pampattiwar <spampatt@redhat.com>

use labels selector.matches

Signed-off-by: Shubham Pampattiwar <spampatt@redhat.com>

make update

Signed-off-by: Shubham Pampattiwar <spampatt@redhat.com>

remove fetching pvc from volume policy filtering

Signed-off-by: Shubham Pampattiwar <spampatt@redhat.com>

add more ut coverage

Signed-off-by: Shubham Pampattiwar <spampatt@redhat.com>

* minor updates

Signed-off-by: Shubham Pampattiwar <spampatt@redhat.com>

use VolumeFilterData struct in GetMatchAction func

Signed-off-by: Shubham Pampattiwar <spampatt@redhat.com>

update parsePVC func and add more ut

Signed-off-by: Shubham Pampattiwar <spampatt@redhat.com>

lint fix

Signed-off-by: Shubham Pampattiwar <spampatt@redhat.com>

---------

Signed-off-by: Shubham Pampattiwar <spampatt@redhat.com>
This commit is contained in:
Shubham Pampattiwar
2025-02-26 07:02:45 -08:00
committed by GitHub
parent a45c9f27e8
commit 0eb1040a0a
13 changed files with 861 additions and 37 deletions

View File

@@ -706,3 +706,37 @@ func TestVolumeHelperImpl_ShouldPerformFSBackup(t *testing.T) {
})
}
}
func TestGetVolumeFromResource(t *testing.T) {
helper := &volumeHelperImpl{}
t.Run("PersistentVolume input", func(t *testing.T) {
pv := &corev1.PersistentVolume{
ObjectMeta: metav1.ObjectMeta{
Name: "test-pv",
},
}
outPV, outPod, err := helper.getVolumeFromResource(pv)
assert.NoError(t, err)
assert.NotNil(t, outPV)
assert.Nil(t, outPod)
assert.Equal(t, "test-pv", outPV.Name)
})
t.Run("Volume input", func(t *testing.T) {
vol := &corev1.Volume{
Name: "test-volume",
}
outPV, outPod, err := helper.getVolumeFromResource(vol)
assert.NoError(t, err)
assert.Nil(t, outPV)
assert.NotNil(t, outPod)
assert.Equal(t, "test-volume", outPod.Name)
})
t.Run("Invalid input", func(t *testing.T) {
_, _, err := helper.getVolumeFromResource("invalid")
assert.Error(t, err)
assert.Contains(t, err.Error(), "resource is not a PersistentVolume or Volume")
})
}