mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 11:21:47 +00:00
Add unit tests for local volume expansion
This commit is contained in:
parent
d166cabd9e
commit
593eda4ad3
@ -83,6 +83,37 @@ func getBlockPlugin(t *testing.T) (string, volume.BlockVolumePlugin) {
|
||||
return tmpDir, plug
|
||||
}
|
||||
|
||||
func getNodeExpandablePlugin(t *testing.T, isBlockDevice bool) (string, volume.NodeExpandableVolumePlugin) {
|
||||
tmpDir, err := utiltesting.MkTmpdir("localVolumeTest")
|
||||
if err != nil {
|
||||
t.Fatalf("can't make a temp dir: %v", err)
|
||||
}
|
||||
|
||||
plugMgr := volume.VolumePluginMgr{}
|
||||
var pathToFSType map[string]hostutil.FileType
|
||||
if isBlockDevice {
|
||||
pathToFSType = map[string]hostutil.FileType{
|
||||
tmpDir: hostutil.FileTypeBlockDev,
|
||||
}
|
||||
} else {
|
||||
pathToFSType = map[string]hostutil.FileType{
|
||||
tmpDir: hostutil.FileTypeDirectory,
|
||||
}
|
||||
}
|
||||
|
||||
plugMgr.InitPlugins(ProbeVolumePlugins(), nil /* prober */, volumetest.NewFakeKubeletVolumeHostWithMounterFSType(t, tmpDir, nil, nil, pathToFSType))
|
||||
|
||||
plug, err := plugMgr.FindNodeExpandablePluginByName(localVolumePluginName)
|
||||
if err != nil {
|
||||
os.RemoveAll(tmpDir)
|
||||
t.Fatalf("Can't find the plugin by name")
|
||||
}
|
||||
if plug.GetPluginName() != localVolumePluginName {
|
||||
t.Errorf("Wrong name: %s", plug.GetPluginName())
|
||||
}
|
||||
return tmpDir, plug
|
||||
}
|
||||
|
||||
func getPersistentPlugin(t *testing.T) (string, volume.PersistentVolumePlugin) {
|
||||
tmpDir, err := utiltesting.MkTmpdir("localVolumeTest")
|
||||
if err != nil {
|
||||
@ -148,6 +179,9 @@ func getTestVolume(readOnly bool, path string, isBlock bool, mountOptions []stri
|
||||
if isBlock {
|
||||
blockMode := v1.PersistentVolumeBlock
|
||||
pv.Spec.VolumeMode = &blockMode
|
||||
} else {
|
||||
fsMode := v1.PersistentVolumeFilesystem
|
||||
pv.Spec.VolumeMode = &fsMode
|
||||
}
|
||||
return volume.NewSpecFromPersistentVolume(pv, readOnly)
|
||||
}
|
||||
@ -289,6 +323,28 @@ func TestFSGlobalPathAndMountDevice(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestNodeExpand(t *testing.T) {
|
||||
// FS global path testing
|
||||
tmpFSDir, plug := getNodeExpandablePlugin(t, false)
|
||||
defer os.RemoveAll(tmpFSDir)
|
||||
|
||||
pvSpec := getTestVolume(false, tmpFSDir, false, nil)
|
||||
|
||||
resizeOptions := volume.NodeResizeOptions{
|
||||
VolumeSpec: pvSpec,
|
||||
DevicePath: tmpFSDir,
|
||||
}
|
||||
|
||||
// Actually, we will do no volume expansion if volume is of type dir
|
||||
resizeDone, err := plug.NodeExpand(resizeOptions)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !resizeDone {
|
||||
t.Errorf("expected resize to be done")
|
||||
}
|
||||
}
|
||||
|
||||
func TestMountUnmount(t *testing.T) {
|
||||
tmpDir, plug := getPlugin(t)
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
Loading…
Reference in New Issue
Block a user