mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-16 14:45:28 +00:00
pkg/admission/storageclass: pick random storageclass if >1 present
Signed-off-by: danishprakash <grafitykoncept@gmail.com>
This commit is contained in:
@@ -20,6 +20,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"k8s.io/kubernetes/pkg/volume/util"
|
||||
|
||||
"k8s.io/klog/v2"
|
||||
|
@@ -19,6 +19,7 @@ package setdefault
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"k8s.io/klog/v2"
|
||||
|
||||
@@ -96,6 +97,30 @@ func TestAdmission(t *testing.T) {
|
||||
},
|
||||
Provisioner: "nondefault1",
|
||||
}
|
||||
classWithCreateTime1 := &storagev1.StorageClass{
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
Kind: "StorageClass",
|
||||
},
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "default1",
|
||||
CreationTimestamp: metav1.NewTime(time.Date(2022, time.Month(1), 1, 0, 0, 0, 1, time.UTC)),
|
||||
Annotations: map[string]string{
|
||||
storageutil.IsDefaultStorageClassAnnotation: "true",
|
||||
},
|
||||
},
|
||||
}
|
||||
classWithCreateTime2 := &storagev1.StorageClass{
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
Kind: "StorageClass",
|
||||
},
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "default2",
|
||||
CreationTimestamp: metav1.NewTime(time.Date(2022, time.Month(1), 1, 0, 0, 0, 0, time.UTC)),
|
||||
Annotations: map[string]string{
|
||||
storageutil.IsDefaultStorageClassAnnotation: "true",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
claimWithClass := &api.PersistentVolumeClaim{
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
@@ -166,13 +191,6 @@ func TestAdmission(t *testing.T) {
|
||||
false,
|
||||
"foo",
|
||||
},
|
||||
{
|
||||
"two defaults, error with PVC with class=nil",
|
||||
[]*storagev1.StorageClass{defaultClass1, defaultClass2, classWithFalseDefault, classWithNoDefault, classWithEmptyDefault},
|
||||
claimWithNoClass,
|
||||
true,
|
||||
"",
|
||||
},
|
||||
{
|
||||
"two defaults, no modification of PVC with class=''",
|
||||
[]*storagev1.StorageClass{defaultClass1, defaultClass2, classWithFalseDefault, classWithNoDefault, classWithEmptyDefault},
|
||||
@@ -187,6 +205,20 @@ func TestAdmission(t *testing.T) {
|
||||
false,
|
||||
"foo",
|
||||
},
|
||||
{
|
||||
"two defaults with same creation time, choose the one with smaller name",
|
||||
[]*storagev1.StorageClass{defaultClass1, defaultClass2, classWithFalseDefault, classWithNoDefault, classWithEmptyDefault},
|
||||
claimWithNoClass,
|
||||
false,
|
||||
defaultClass1.Name,
|
||||
},
|
||||
{
|
||||
"two defaults, choose the one with newer creation time",
|
||||
[]*storagev1.StorageClass{classWithCreateTime1, classWithCreateTime2, classWithFalseDefault, classWithNoDefault, classWithEmptyDefault},
|
||||
claimWithNoClass,
|
||||
false,
|
||||
classWithCreateTime1.Name,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
|
Reference in New Issue
Block a user