mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-04 23:17:50 +00:00
Add more volume types and unbound pvcs etc
This commit is contained in:
@@ -17,6 +17,7 @@ limitations under the License.
|
||||
package predicates
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
@@ -35,7 +36,7 @@ func TestCSIVolumeCountPredicate(t *testing.T) {
|
||||
{
|
||||
VolumeSource: v1.VolumeSource{
|
||||
PersistentVolumeClaim: &v1.PersistentVolumeClaimVolumeSource{
|
||||
ClaimName: "csi-ebs",
|
||||
ClaimName: "csi-ebs-0",
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -83,7 +84,70 @@ func TestCSIVolumeCountPredicate(t *testing.T) {
|
||||
{
|
||||
VolumeSource: v1.VolumeSource{
|
||||
PersistentVolumeClaim: &v1.PersistentVolumeClaimVolumeSource{
|
||||
ClaimName: "csi-ebs-4",
|
||||
ClaimName: "csi-4",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// Different pod than pendingVolumePod, but using the same unbound PVC
|
||||
unboundPVCPod2 := &v1.Pod{
|
||||
Spec: v1.PodSpec{
|
||||
Volumes: []v1.Volume{
|
||||
{
|
||||
VolumeSource: v1.VolumeSource{
|
||||
PersistentVolumeClaim: &v1.PersistentVolumeClaimVolumeSource{
|
||||
ClaimName: "csi-4",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
missingPVPod := &v1.Pod{
|
||||
Spec: v1.PodSpec{
|
||||
Volumes: []v1.Volume{
|
||||
{
|
||||
VolumeSource: v1.VolumeSource{
|
||||
PersistentVolumeClaim: &v1.PersistentVolumeClaimVolumeSource{
|
||||
ClaimName: "csi-6",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
noSCPVCPod := &v1.Pod{
|
||||
Spec: v1.PodSpec{
|
||||
Volumes: []v1.Volume{
|
||||
{
|
||||
VolumeSource: v1.VolumeSource{
|
||||
PersistentVolumeClaim: &v1.PersistentVolumeClaimVolumeSource{
|
||||
ClaimName: "csi-5",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
gceTwoVolPod := &v1.Pod{
|
||||
Spec: v1.PodSpec{
|
||||
Volumes: []v1.Volume{
|
||||
{
|
||||
VolumeSource: v1.VolumeSource{
|
||||
PersistentVolumeClaim: &v1.PersistentVolumeClaimVolumeSource{
|
||||
ClaimName: "cs-gce-1",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
VolumeSource: v1.VolumeSource{
|
||||
PersistentVolumeClaim: &v1.PersistentVolumeClaimVolumeSource{
|
||||
ClaimName: "csi-gce-2",
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -96,22 +160,25 @@ func TestCSIVolumeCountPredicate(t *testing.T) {
|
||||
existingPods []*v1.Pod
|
||||
filterName string
|
||||
maxVols int
|
||||
driverNames []string
|
||||
fits bool
|
||||
test string
|
||||
}{
|
||||
{
|
||||
newPod: oneVolPod,
|
||||
existingPods: []*v1.Pod{runningPod, twoVolPod},
|
||||
filterName: "csi-ebs",
|
||||
filterName: "csi",
|
||||
maxVols: 4,
|
||||
driverNames: []string{"ebs"},
|
||||
fits: true,
|
||||
test: "fits when node capacity >= new pods CSI volume",
|
||||
},
|
||||
{
|
||||
newPod: oneVolPod,
|
||||
existingPods: []*v1.Pod{runningPod, twoVolPod},
|
||||
filterName: "csi-ebs",
|
||||
filterName: "csi",
|
||||
maxVols: 2,
|
||||
driverNames: []string{"ebs"},
|
||||
fits: false,
|
||||
test: "doesn't when node capacity <= pods CSI volume",
|
||||
},
|
||||
@@ -119,10 +186,60 @@ func TestCSIVolumeCountPredicate(t *testing.T) {
|
||||
{
|
||||
newPod: oneVolPod,
|
||||
existingPods: []*v1.Pod{pendingVolumePod, twoVolPod},
|
||||
filterName: "csi-ebs",
|
||||
filterName: "csi",
|
||||
maxVols: 2,
|
||||
driverNames: []string{"ebs"},
|
||||
fits: false,
|
||||
test: "doesn't when node capacity <= pods CSI volume",
|
||||
test: "count pending PVCs towards capacity <= pods CSI volume",
|
||||
},
|
||||
// two same pending PVCs should be counted as 1
|
||||
{
|
||||
newPod: oneVolPod,
|
||||
existingPods: []*v1.Pod{pendingVolumePod, unboundPVCPod2, twoVolPod},
|
||||
filterName: "csi",
|
||||
maxVols: 3,
|
||||
driverNames: []string{"ebs"},
|
||||
fits: true,
|
||||
test: "count multiple pending pvcs towards capacity >= pods CSI volume",
|
||||
},
|
||||
// should count PVCs with invalid PV name but valid SC
|
||||
{
|
||||
newPod: oneVolPod,
|
||||
existingPods: []*v1.Pod{missingPVPod, twoVolPod},
|
||||
filterName: "csi",
|
||||
maxVols: 2,
|
||||
driverNames: []string{"ebs"},
|
||||
fits: false,
|
||||
test: "should count PVCs with invalid PV name but valid SC",
|
||||
},
|
||||
// don't count a volume which has storageclass missing
|
||||
{
|
||||
newPod: oneVolPod,
|
||||
existingPods: []*v1.Pod{runningPod, noSCPVCPod},
|
||||
filterName: "csi",
|
||||
maxVols: 2,
|
||||
driverNames: []string{"ebs"},
|
||||
fits: true,
|
||||
test: "don't count pvcs with missing SC towards capacity",
|
||||
},
|
||||
// don't count multiple volume types
|
||||
{
|
||||
newPod: oneVolPod,
|
||||
existingPods: []*v1.Pod{gceTwoVolPod, twoVolPod},
|
||||
filterName: "csi",
|
||||
maxVols: 2,
|
||||
driverNames: []string{"ebs", "gce"},
|
||||
fits: true,
|
||||
test: "don't count pvcs with different type towards capacity",
|
||||
},
|
||||
{
|
||||
newPod: gceTwoVolPod,
|
||||
existingPods: []*v1.Pod{twoVolPod, runningPod},
|
||||
filterName: "csi",
|
||||
maxVols: 2,
|
||||
driverNames: []string{"ebs", "gce"},
|
||||
fits: true,
|
||||
test: "don't count pvcs with different type towards capacity",
|
||||
},
|
||||
}
|
||||
|
||||
@@ -130,8 +247,11 @@ func TestCSIVolumeCountPredicate(t *testing.T) {
|
||||
expectedFailureReasons := []PredicateFailureReason{ErrMaxVolumeCountExceeded}
|
||||
// running attachable predicate tests with feature gate and limit present on nodes
|
||||
for _, test := range tests {
|
||||
node := getNodeWithPodAndVolumeLimits(test.existingPods, int64(test.maxVols), test.filterName)
|
||||
pred := NewCSIMaxVolumeLimitPredicate(getFakeCSIPVInfo("csi-ebs", "csi-ebs"), getFakeCSIPVCInfo("csi-ebs", "csi-ebs-gp2"), getFakeCSIStorageClassInfo("csi-ebs-gp2", "csi-ebs"))
|
||||
node := getNodeWithPodAndVolumeLimits(test.existingPods, int64(test.maxVols), test.driverNames...)
|
||||
pred := NewCSIMaxVolumeLimitPredicate(getFakeCSIPVInfo(test.filterName, test.driverNames...),
|
||||
getFakeCSIPVCInfo(test.filterName, "csi-sc", test.driverNames...),
|
||||
getFakeCSIStorageClassInfo("csi-sc", test.driverNames[0]))
|
||||
|
||||
fits, reasons, err := pred(test.newPod, GetPredicateMetadata(test.newPod, nil), node)
|
||||
if err != nil {
|
||||
t.Errorf("Using allocatable [%s]%s: unexpected error: %v", test.filterName, test.test, err)
|
||||
@@ -145,63 +265,56 @@ func TestCSIVolumeCountPredicate(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func getFakeCSIPVInfo(volumeName, driverName string) FakePersistentVolumeInfo {
|
||||
return FakePersistentVolumeInfo{
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: volumeName},
|
||||
Spec: v1.PersistentVolumeSpec{
|
||||
PersistentVolumeSource: v1.PersistentVolumeSource{
|
||||
CSI: &v1.CSIPersistentVolumeSource{
|
||||
Driver: driverName,
|
||||
VolumeHandle: volumeName,
|
||||
func getFakeCSIPVInfo(volumeName string, driverNames ...string) FakePersistentVolumeInfo {
|
||||
pvInfos := FakePersistentVolumeInfo{}
|
||||
for _, driver := range driverNames {
|
||||
for j := 0; j < 4; j++ {
|
||||
volumeHandle := fmt.Sprintf("%s-%s-%d", volumeName, driver, j)
|
||||
pv := v1.PersistentVolume{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: volumeHandle},
|
||||
Spec: v1.PersistentVolumeSpec{
|
||||
PersistentVolumeSource: v1.PersistentVolumeSource{
|
||||
CSI: &v1.CSIPersistentVolumeSource{
|
||||
Driver: driver,
|
||||
VolumeHandle: volumeHandle,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: volumeName + "-2"},
|
||||
Spec: v1.PersistentVolumeSpec{
|
||||
PersistentVolumeSource: v1.PersistentVolumeSource{
|
||||
CSI: &v1.CSIPersistentVolumeSource{
|
||||
Driver: driverName,
|
||||
VolumeHandle: volumeName + "-2",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: volumeName + "-3"},
|
||||
Spec: v1.PersistentVolumeSpec{
|
||||
PersistentVolumeSource: v1.PersistentVolumeSource{
|
||||
CSI: &v1.CSIPersistentVolumeSource{
|
||||
Driver: driverName,
|
||||
VolumeHandle: volumeName + "-3",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
pvInfos = append(pvInfos, pv)
|
||||
}
|
||||
|
||||
}
|
||||
return pvInfos
|
||||
}
|
||||
|
||||
func getFakeCSIPVCInfo(volumeName, scName string) FakePersistentVolumeClaimInfo {
|
||||
return FakePersistentVolumeClaimInfo{
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: volumeName},
|
||||
Spec: v1.PersistentVolumeClaimSpec{VolumeName: volumeName},
|
||||
},
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: volumeName + "-2"},
|
||||
Spec: v1.PersistentVolumeClaimSpec{VolumeName: volumeName + "-2"},
|
||||
},
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: volumeName + "-3"},
|
||||
Spec: v1.PersistentVolumeClaimSpec{VolumeName: volumeName + "-3"},
|
||||
},
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: volumeName + "-4"},
|
||||
Spec: v1.PersistentVolumeClaimSpec{StorageClassName: &scName},
|
||||
},
|
||||
func getFakeCSIPVCInfo(volumeName, scName string, driverNames ...string) FakePersistentVolumeClaimInfo {
|
||||
pvcInfos := FakePersistentVolumeClaimInfo{}
|
||||
for _, driver := range driverNames {
|
||||
for j := 0; j < 4; j++ {
|
||||
v := fmt.Sprintf("%s-%s-%d", volumeName, driver, j)
|
||||
pvc := v1.PersistentVolumeClaim{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: v},
|
||||
Spec: v1.PersistentVolumeClaimSpec{VolumeName: v},
|
||||
}
|
||||
pvcInfos = append(pvcInfos, pvc)
|
||||
}
|
||||
}
|
||||
|
||||
pvcInfos = append(pvcInfos, v1.PersistentVolumeClaim{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: volumeName + "-4"},
|
||||
Spec: v1.PersistentVolumeClaimSpec{StorageClassName: &scName},
|
||||
})
|
||||
pvcInfos = append(pvcInfos, v1.PersistentVolumeClaim{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: volumeName + "-5"},
|
||||
Spec: v1.PersistentVolumeClaimSpec{},
|
||||
})
|
||||
// a pvc with missing PV but available storageclass.
|
||||
pvcInfos = append(pvcInfos, v1.PersistentVolumeClaim{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: volumeName + "-6"},
|
||||
Spec: v1.PersistentVolumeClaimSpec{StorageClassName: &scName, VolumeName: "missing-in-action"},
|
||||
})
|
||||
return pvcInfos
|
||||
}
|
||||
|
||||
func getFakeCSIStorageClassInfo(scName, provisionerName string) FakeStorageClassInfo {
|
||||
|
||||
Reference in New Issue
Block a user