mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 19:31:44 +00:00
code cleanup for pkg volume csi
This commit is contained in:
parent
a55bd63172
commit
b3fea118dc
@ -35,9 +35,7 @@ import (
|
||||
authenticationv1 "k8s.io/api/authentication/v1"
|
||||
api "k8s.io/api/core/v1"
|
||||
storage "k8s.io/api/storage/v1"
|
||||
storagev1 "k8s.io/api/storage/v1"
|
||||
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
||||
@ -225,7 +223,7 @@ func TestMounterSetUp(t *testing.T) {
|
||||
DetachError: nil,
|
||||
},
|
||||
}
|
||||
_, err = csiMounter.k8s.StorageV1().VolumeAttachments().Create(context.TODO(), attachment, metav1.CreateOptions{})
|
||||
_, err = csiMounter.k8s.StorageV1().VolumeAttachments().Create(context.TODO(), attachment, meta.CreateOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("failed to setup VolumeAttachment: %v", err)
|
||||
}
|
||||
@ -352,7 +350,7 @@ func TestMounterSetUpSimple(t *testing.T) {
|
||||
|
||||
attachID := getAttachmentName(csiMounter.volumeID, string(csiMounter.driverName), string(plug.host.GetNodeName()))
|
||||
attachment := makeTestAttachment(attachID, "test-node", csiMounter.spec.Name())
|
||||
_, err = csiMounter.k8s.StorageV1().VolumeAttachments().Create(context.TODO(), attachment, metav1.CreateOptions{})
|
||||
_, err = csiMounter.k8s.StorageV1().VolumeAttachments().Create(context.TODO(), attachment, meta.CreateOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("failed to setup VolumeAttachment: %v", err)
|
||||
}
|
||||
@ -480,7 +478,7 @@ func TestMounterSetupWithStatusTracking(t *testing.T) {
|
||||
if tc.createAttachment {
|
||||
attachID := getAttachmentName(csiMounter.volumeID, string(csiMounter.driverName), string(plug.host.GetNodeName()))
|
||||
attachment := makeTestAttachment(attachID, "test-node", csiMounter.spec.Name())
|
||||
_, err = csiMounter.k8s.StorageV1().VolumeAttachments().Create(context.TODO(), attachment, metav1.CreateOptions{})
|
||||
_, err = csiMounter.k8s.StorageV1().VolumeAttachments().Create(context.TODO(), attachment, meta.CreateOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("failed to setup VolumeAttachment: %v", err)
|
||||
}
|
||||
@ -594,7 +592,7 @@ func TestMounterSetUpWithInline(t *testing.T) {
|
||||
if csiMounter.volumeLifecycleMode == storage.VolumeLifecyclePersistent {
|
||||
attachID := getAttachmentName(csiMounter.volumeID, string(csiMounter.driverName), string(plug.host.GetNodeName()))
|
||||
attachment := makeTestAttachment(attachID, "test-node", csiMounter.spec.Name())
|
||||
_, err = csiMounter.k8s.StorageV1().VolumeAttachments().Create(context.TODO(), attachment, metav1.CreateOptions{})
|
||||
_, err = csiMounter.k8s.StorageV1().VolumeAttachments().Create(context.TODO(), attachment, meta.CreateOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("failed to setup VolumeAttachment: %v", err)
|
||||
}
|
||||
@ -827,7 +825,7 @@ func TestMounterSetUpWithFSGroup(t *testing.T) {
|
||||
attachID := getAttachmentName(csiMounter.volumeID, string(csiMounter.driverName), string(plug.host.GetNodeName()))
|
||||
attachment := makeTestAttachment(attachID, "test-node", pvName)
|
||||
|
||||
_, err = csiMounter.k8s.StorageV1().VolumeAttachments().Create(context.TODO(), attachment, metav1.CreateOptions{})
|
||||
_, err = csiMounter.k8s.StorageV1().VolumeAttachments().Create(context.TODO(), attachment, meta.CreateOptions{})
|
||||
if err != nil {
|
||||
t.Errorf("failed to setup VolumeAttachment: %v", err)
|
||||
continue
|
||||
@ -950,28 +948,28 @@ func TestPodServiceAccountTokenAttrs(t *testing.T) {
|
||||
|
||||
tests := []struct {
|
||||
desc string
|
||||
driver *storagev1.CSIDriver
|
||||
driver *storage.CSIDriver
|
||||
volumeContext map[string]string
|
||||
wantVolumeContext map[string]string
|
||||
}{
|
||||
{
|
||||
desc: "csi driver has no ServiceAccountToken",
|
||||
driver: &storagev1.CSIDriver{
|
||||
driver: &storage.CSIDriver{
|
||||
ObjectMeta: meta.ObjectMeta{
|
||||
Name: testDriver,
|
||||
},
|
||||
Spec: storagev1.CSIDriverSpec{},
|
||||
Spec: storage.CSIDriverSpec{},
|
||||
},
|
||||
wantVolumeContext: nil,
|
||||
},
|
||||
{
|
||||
desc: "one token with empty string as audience",
|
||||
driver: &storagev1.CSIDriver{
|
||||
driver: &storage.CSIDriver{
|
||||
ObjectMeta: meta.ObjectMeta{
|
||||
Name: testDriver,
|
||||
},
|
||||
Spec: storagev1.CSIDriverSpec{
|
||||
TokenRequests: []storagev1.TokenRequest{
|
||||
Spec: storage.CSIDriverSpec{
|
||||
TokenRequests: []storage.TokenRequest{
|
||||
{
|
||||
Audience: "",
|
||||
},
|
||||
@ -982,12 +980,12 @@ func TestPodServiceAccountTokenAttrs(t *testing.T) {
|
||||
},
|
||||
{
|
||||
desc: "one token with non-empty string as audience",
|
||||
driver: &storagev1.CSIDriver{
|
||||
driver: &storage.CSIDriver{
|
||||
ObjectMeta: meta.ObjectMeta{
|
||||
Name: testDriver,
|
||||
},
|
||||
Spec: storagev1.CSIDriverSpec{
|
||||
TokenRequests: []storagev1.TokenRequest{
|
||||
Spec: storage.CSIDriverSpec{
|
||||
TokenRequests: []storage.TokenRequest{
|
||||
{
|
||||
Audience: gcp,
|
||||
},
|
||||
@ -1017,7 +1015,7 @@ func TestPodServiceAccountTokenAttrs(t *testing.T) {
|
||||
tr.Spec.Audiences = []string{"api"}
|
||||
}
|
||||
tr.Status.Token = fmt.Sprintf("%v:%v:%d:%v", action.GetNamespace(), testAccount, *tr.Spec.ExpirationSeconds, tr.Spec.Audiences)
|
||||
tr.Status.ExpirationTimestamp = metav1.NewTime(time.Unix(1, 1))
|
||||
tr.Status.ExpirationTimestamp = meta.NewTime(time.Unix(1, 1))
|
||||
return true, tr, nil
|
||||
}))
|
||||
plug, tmpDir := newTestPlugin(t, client)
|
||||
|
@ -27,9 +27,7 @@ import (
|
||||
api "k8s.io/api/core/v1"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
storage "k8s.io/api/storage/v1"
|
||||
storagev1 "k8s.io/api/storage/v1"
|
||||
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||
@ -68,7 +66,7 @@ func newTestPluginWithVolumeHost(t *testing.T, client *fakeclient.Clientset, hos
|
||||
}
|
||||
|
||||
client.Tracker().Add(&v1.Node{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
ObjectMeta: meta.ObjectMeta{
|
||||
Name: "fakeNode",
|
||||
},
|
||||
Spec: v1.NodeSpec{},
|
||||
@ -284,8 +282,8 @@ func TestPluginGetVolumeName(t *testing.T) {
|
||||
func TestPluginGetVolumeNameWithInline(t *testing.T) {
|
||||
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.CSIInlineVolume, true)()
|
||||
|
||||
modes := []storagev1.VolumeLifecycleMode{
|
||||
storagev1.VolumeLifecyclePersistent,
|
||||
modes := []storage.VolumeLifecycleMode{
|
||||
storage.VolumeLifecyclePersistent,
|
||||
}
|
||||
driver := getTestCSIDriver(testDriver, nil, nil, modes)
|
||||
client := fakeclient.NewSimpleClientset(driver)
|
||||
@ -517,7 +515,7 @@ func TestPluginConstructVolumeSpecWithInline(t *testing.T) {
|
||||
volHandle string
|
||||
podUID types.UID
|
||||
shouldFail bool
|
||||
modes []storagev1.VolumeLifecycleMode
|
||||
modes []storage.VolumeLifecycleMode
|
||||
}{
|
||||
{
|
||||
name: "construct spec1 from persistent spec",
|
||||
@ -525,7 +523,7 @@ func TestPluginConstructVolumeSpecWithInline(t *testing.T) {
|
||||
volHandle: "testvol-handle1",
|
||||
originSpec: volume.NewSpecFromPersistentVolume(makeTestPV("test.vol.id", 20, testDriver, "testvol-handle1"), true),
|
||||
podUID: types.UID(fmt.Sprintf("%08X", rand.Uint64())),
|
||||
modes: []storagev1.VolumeLifecycleMode{storagev1.VolumeLifecyclePersistent},
|
||||
modes: []storage.VolumeLifecycleMode{storage.VolumeLifecyclePersistent},
|
||||
},
|
||||
{
|
||||
name: "construct spec2 from persistent spec",
|
||||
@ -533,7 +531,7 @@ func TestPluginConstructVolumeSpecWithInline(t *testing.T) {
|
||||
volHandle: "handle2",
|
||||
originSpec: volume.NewSpecFromPersistentVolume(makeTestPV("spec2", 20, testDriver, "handle2"), true),
|
||||
podUID: types.UID(fmt.Sprintf("%08X", rand.Uint64())),
|
||||
modes: []storagev1.VolumeLifecycleMode{storagev1.VolumeLifecyclePersistent},
|
||||
modes: []storage.VolumeLifecycleMode{storage.VolumeLifecyclePersistent},
|
||||
},
|
||||
{
|
||||
name: "construct spec2 from persistent spec, missing mode",
|
||||
@ -541,7 +539,7 @@ func TestPluginConstructVolumeSpecWithInline(t *testing.T) {
|
||||
volHandle: "handle2",
|
||||
originSpec: volume.NewSpecFromPersistentVolume(makeTestPV("spec2", 20, testDriver, "handle2"), true),
|
||||
podUID: types.UID(fmt.Sprintf("%08X", rand.Uint64())),
|
||||
modes: []storagev1.VolumeLifecycleMode{},
|
||||
modes: []storage.VolumeLifecycleMode{},
|
||||
shouldFail: true,
|
||||
},
|
||||
{
|
||||
@ -549,21 +547,21 @@ func TestPluginConstructVolumeSpecWithInline(t *testing.T) {
|
||||
specVolID: "volspec",
|
||||
originSpec: volume.NewSpecFromVolume(makeTestVol("volspec", testDriver)),
|
||||
podUID: types.UID(fmt.Sprintf("%08X", rand.Uint64())),
|
||||
modes: []storagev1.VolumeLifecycleMode{storagev1.VolumeLifecycleEphemeral},
|
||||
modes: []storage.VolumeLifecycleMode{storage.VolumeLifecycleEphemeral},
|
||||
},
|
||||
{
|
||||
name: "construct spec from volume spec2",
|
||||
specVolID: "volspec2",
|
||||
originSpec: volume.NewSpecFromVolume(makeTestVol("volspec2", testDriver)),
|
||||
podUID: types.UID(fmt.Sprintf("%08X", rand.Uint64())),
|
||||
modes: []storagev1.VolumeLifecycleMode{storagev1.VolumeLifecycleEphemeral},
|
||||
modes: []storage.VolumeLifecycleMode{storage.VolumeLifecycleEphemeral},
|
||||
},
|
||||
{
|
||||
name: "construct spec from volume spec2, missing mode",
|
||||
specVolID: "volspec2",
|
||||
originSpec: volume.NewSpecFromVolume(makeTestVol("volspec2", testDriver)),
|
||||
podUID: types.UID(fmt.Sprintf("%08X", rand.Uint64())),
|
||||
modes: []storagev1.VolumeLifecycleMode{},
|
||||
modes: []storage.VolumeLifecycleMode{},
|
||||
shouldFail: true,
|
||||
},
|
||||
{
|
||||
@ -653,7 +651,7 @@ func TestPluginNewMounter(t *testing.T) {
|
||||
spec *volume.Spec
|
||||
podUID types.UID
|
||||
namespace string
|
||||
volumeLifecycleMode storagev1.VolumeLifecycleMode
|
||||
volumeLifecycleMode storage.VolumeLifecycleMode
|
||||
shouldFail bool
|
||||
}{
|
||||
{
|
||||
@ -661,14 +659,14 @@ func TestPluginNewMounter(t *testing.T) {
|
||||
spec: volume.NewSpecFromPersistentVolume(makeTestPV("test-pv1", 20, testDriver, testVol), true),
|
||||
podUID: types.UID(fmt.Sprintf("%08X", rand.Uint64())),
|
||||
namespace: "test-ns1",
|
||||
volumeLifecycleMode: storagev1.VolumeLifecyclePersistent,
|
||||
volumeLifecycleMode: storage.VolumeLifecyclePersistent,
|
||||
},
|
||||
{
|
||||
name: "mounter from volume source",
|
||||
spec: volume.NewSpecFromVolume(makeTestVol("test-vol1", testDriver)),
|
||||
podUID: types.UID(fmt.Sprintf("%08X", rand.Uint64())),
|
||||
namespace: "test-ns2",
|
||||
volumeLifecycleMode: storagev1.VolumeLifecycleEphemeral,
|
||||
volumeLifecycleMode: storage.VolumeLifecycleEphemeral,
|
||||
shouldFail: true, // csi inline not enabled
|
||||
},
|
||||
{
|
||||
@ -760,22 +758,22 @@ func TestPluginNewMounter(t *testing.T) {
|
||||
|
||||
func TestPluginNewMounterWithInline(t *testing.T) {
|
||||
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.CSIInlineVolume, true)()
|
||||
bothModes := []storagev1.VolumeLifecycleMode{
|
||||
storagev1.VolumeLifecycleEphemeral,
|
||||
storagev1.VolumeLifecyclePersistent,
|
||||
bothModes := []storage.VolumeLifecycleMode{
|
||||
storage.VolumeLifecycleEphemeral,
|
||||
storage.VolumeLifecyclePersistent,
|
||||
}
|
||||
persistentMode := []storagev1.VolumeLifecycleMode{
|
||||
storagev1.VolumeLifecyclePersistent,
|
||||
persistentMode := []storage.VolumeLifecycleMode{
|
||||
storage.VolumeLifecyclePersistent,
|
||||
}
|
||||
ephemeralMode := []storagev1.VolumeLifecycleMode{
|
||||
storagev1.VolumeLifecycleEphemeral,
|
||||
ephemeralMode := []storage.VolumeLifecycleMode{
|
||||
storage.VolumeLifecycleEphemeral,
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
spec *volume.Spec
|
||||
podUID types.UID
|
||||
namespace string
|
||||
volumeLifecycleMode storagev1.VolumeLifecycleMode
|
||||
volumeLifecycleMode storage.VolumeLifecycleMode
|
||||
shouldFail bool
|
||||
}{
|
||||
{
|
||||
@ -796,18 +794,18 @@ func TestPluginNewMounterWithInline(t *testing.T) {
|
||||
spec: volume.NewSpecFromPersistentVolume(makeTestPV("test-pv1", 20, testDriver, testVol), true),
|
||||
podUID: types.UID(fmt.Sprintf("%08X", rand.Uint64())),
|
||||
namespace: "test-ns1",
|
||||
volumeLifecycleMode: storagev1.VolumeLifecyclePersistent,
|
||||
volumeLifecycleMode: storage.VolumeLifecyclePersistent,
|
||||
},
|
||||
{
|
||||
name: "mounter with volume source",
|
||||
spec: volume.NewSpecFromVolume(makeTestVol("test-vol1", testDriver)),
|
||||
podUID: types.UID(fmt.Sprintf("%08X", rand.Uint64())),
|
||||
namespace: "test-ns2",
|
||||
volumeLifecycleMode: storagev1.VolumeLifecycleEphemeral,
|
||||
volumeLifecycleMode: storage.VolumeLifecycleEphemeral,
|
||||
},
|
||||
}
|
||||
|
||||
runAll := func(t *testing.T, supported []storagev1.VolumeLifecycleMode) {
|
||||
runAll := func(t *testing.T, supported []storage.VolumeLifecycleMode) {
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
driver := getTestCSIDriver(testDriver, nil, nil, supported)
|
||||
@ -1097,7 +1095,7 @@ func TestPluginFindAttachablePlugin(t *testing.T) {
|
||||
client := fakeclient.NewSimpleClientset(
|
||||
getTestCSIDriver(test.driverName, nil, &test.canAttach, nil),
|
||||
&v1.Node{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
ObjectMeta: meta.ObjectMeta{
|
||||
Name: "fakeNode",
|
||||
},
|
||||
Spec: v1.NodeSpec{},
|
||||
@ -1224,7 +1222,7 @@ func TestPluginFindDeviceMountablePluginBySpec(t *testing.T) {
|
||||
|
||||
client := fakeclient.NewSimpleClientset(
|
||||
&v1.Node{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
ObjectMeta: meta.ObjectMeta{
|
||||
Name: "fakeNode",
|
||||
},
|
||||
Spec: v1.NodeSpec{},
|
||||
|
@ -25,11 +25,8 @@ import (
|
||||
"time"
|
||||
|
||||
api "k8s.io/api/core/v1"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
storage "k8s.io/api/storage/v1"
|
||||
storagev1 "k8s.io/api/storage/v1"
|
||||
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
@ -47,7 +44,7 @@ import (
|
||||
// based on operations from the volume manager/reconciler/operation executor
|
||||
func TestCSI_VolumeAll(t *testing.T) {
|
||||
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.CSIInlineVolume, true)()
|
||||
defaultFSGroupPolicy := storagev1.ReadWriteOnceWithFSTypeFSGroupPolicy
|
||||
defaultFSGroupPolicy := storage.ReadWriteOnceWithFSTypeFSGroupPolicy
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
@ -259,18 +256,18 @@ func TestCSI_VolumeAll(t *testing.T) {
|
||||
objs := []runtime.Object{}
|
||||
if test.driverSpec != nil {
|
||||
driverInfo = &storage.CSIDriver{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
ObjectMeta: meta.ObjectMeta{
|
||||
Name: test.driver,
|
||||
},
|
||||
Spec: *test.driverSpec,
|
||||
}
|
||||
objs = append(objs, driverInfo)
|
||||
}
|
||||
objs = append(objs, &v1.Node{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
objs = append(objs, &api.Node{
|
||||
ObjectMeta: meta.ObjectMeta{
|
||||
Name: "fakeNode",
|
||||
},
|
||||
Spec: v1.NodeSpec{},
|
||||
Spec: api.NodeSpec{},
|
||||
})
|
||||
|
||||
client := fakeclient.NewSimpleClientset(objs...)
|
||||
|
Loading…
Reference in New Issue
Block a user