-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Shubham Pampattiwar <[email protected]> use VolumeFilterData struct in GetMatchAction func Signed-off-by: Shubham Pampattiwar <[email protected]> update parsePVC func and add more ut Signed-off-by: Shubham Pampattiwar <[email protected]> lint fix Signed-off-by: Shubham Pampattiwar <[email protected]>
- Loading branch information
1 parent
e6493fc
commit f756a6d
Showing
9 changed files
with
371 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package resourcepolicies | ||
|
||
import ( | ||
corev1 "k8s.io/api/core/v1" | ||
) | ||
|
||
// VolumeFilterData bundles the volume data needed for volume policy filtering | ||
type VolumeFilterData struct { | ||
PersistentVolume *corev1.PersistentVolume | ||
PodVolume *corev1.Volume | ||
PVC *corev1.PersistentVolumeClaim | ||
} | ||
|
||
// NewVolumeFilterData constructs a new VolumeFilterData instance. | ||
func NewVolumeFilterData(pv *corev1.PersistentVolume, podVol *corev1.Volume, pvc *corev1.PersistentVolumeClaim) VolumeFilterData { | ||
return VolumeFilterData{ | ||
PersistentVolume: pv, | ||
PodVolume: podVol, | ||
PVC: pvc, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package resourcepolicies | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func TestNewVolumeFilterData(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
pv *corev1.PersistentVolume | ||
podVol *corev1.Volume | ||
pvc *corev1.PersistentVolumeClaim | ||
expectedPVName string | ||
expectedPodName string | ||
expectedPVCName string | ||
}{ | ||
{ | ||
name: "all provided", | ||
pv: &corev1.PersistentVolume{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "pv-test", | ||
}, | ||
}, | ||
podVol: &corev1.Volume{ | ||
Name: "pod-vol-test", | ||
}, | ||
pvc: &corev1.PersistentVolumeClaim{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "pvc-test", | ||
}, | ||
}, | ||
expectedPVName: "pv-test", | ||
expectedPodName: "pod-vol-test", | ||
expectedPVCName: "pvc-test", | ||
}, | ||
{ | ||
name: "only PV provided", | ||
pv: &corev1.PersistentVolume{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "pv-only", | ||
}, | ||
}, | ||
podVol: nil, | ||
pvc: nil, | ||
expectedPVName: "pv-only", | ||
expectedPodName: "", | ||
expectedPVCName: "", | ||
}, | ||
{ | ||
name: "only PodVolume provided", | ||
pv: nil, | ||
podVol: &corev1.Volume{ | ||
Name: "pod-only", | ||
}, | ||
pvc: nil, | ||
expectedPVName: "", | ||
expectedPodName: "pod-only", | ||
expectedPVCName: "", | ||
}, | ||
{ | ||
name: "only PVC provided", | ||
pv: nil, | ||
podVol: nil, | ||
pvc: &corev1.PersistentVolumeClaim{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "pvc-only", | ||
}, | ||
}, | ||
expectedPVName: "", | ||
expectedPodName: "", | ||
expectedPVCName: "pvc-only", | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
vfd := NewVolumeFilterData(tc.pv, tc.podVol, tc.pvc) | ||
if tc.expectedPVName != "" { | ||
assert.NotNil(t, vfd.PersistentVolume) | ||
assert.Equal(t, tc.expectedPVName, vfd.PersistentVolume.Name) | ||
} else { | ||
assert.Nil(t, vfd.PersistentVolume) | ||
} | ||
if tc.expectedPodName != "" { | ||
assert.NotNil(t, vfd.PodVolume) | ||
assert.Equal(t, tc.expectedPodName, vfd.PodVolume.Name) | ||
} else { | ||
assert.Nil(t, vfd.PodVolume) | ||
} | ||
if tc.expectedPVCName != "" { | ||
assert.NotNil(t, vfd.PVC) | ||
assert.Equal(t, tc.expectedPVCName, vfd.PVC.Name) | ||
} else { | ||
assert.Nil(t, vfd.PVC) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.