mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-13 19:36:22 +00:00
add some tests for expand controller
Update bazel file
This commit is contained in:
@@ -9,6 +9,7 @@ load(
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"fakegenerator.go",
|
||||
"operation_executor.go",
|
||||
"operation_generator.go",
|
||||
],
|
||||
|
||||
115
pkg/volume/util/operationexecutor/fakegenerator.go
Normal file
115
pkg/volume/util/operationexecutor/fakegenerator.go
Normal file
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
Copyright 2016 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package operationexecutor
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/kubernetes/pkg/util/mount"
|
||||
"k8s.io/kubernetes/pkg/volume"
|
||||
volumetypes "k8s.io/kubernetes/pkg/volume/util/types"
|
||||
)
|
||||
|
||||
// fakeOgCounter is a simple OperationGenerator which counts number of times a function
|
||||
// has been caled
|
||||
type fakeOgCounter struct {
|
||||
// calledFuncs stores name and count of functions
|
||||
calledFuncs map[string]int
|
||||
opFunc func() (error, error)
|
||||
}
|
||||
|
||||
var _ OperationGenerator = &fakeOgCounter{}
|
||||
|
||||
// NewFakeOgCounter returns a OperationGenerator
|
||||
func NewFakeOgCounter(opFunc func() (error, error)) OperationGenerator {
|
||||
return &fakeOgCounter{
|
||||
calledFuncs: map[string]int{},
|
||||
opFunc: opFunc,
|
||||
}
|
||||
}
|
||||
|
||||
func (f *fakeOgCounter) GenerateMountVolumeFunc(waitForAttachTimeout time.Duration, volumeToMount VolumeToMount, actualStateOfWorldMounterUpdater ActualStateOfWorldMounterUpdater, isRemount bool) volumetypes.GeneratedOperations {
|
||||
return f.recordFuncCall("GenerateMountVolumeFunc")
|
||||
}
|
||||
|
||||
func (f *fakeOgCounter) GenerateUnmountVolumeFunc(volumeToUnmount MountedVolume, actualStateOfWorld ActualStateOfWorldMounterUpdater, podsDir string) (volumetypes.GeneratedOperations, error) {
|
||||
return f.recordFuncCall("GenerateUnmountVolumeFunc"), nil
|
||||
}
|
||||
|
||||
func (f *fakeOgCounter) GenerateAttachVolumeFunc(volumeToAttach VolumeToAttach, actualStateOfWorld ActualStateOfWorldAttacherUpdater) volumetypes.GeneratedOperations {
|
||||
return f.recordFuncCall("GenerateAttachVolumeFunc")
|
||||
}
|
||||
|
||||
func (f *fakeOgCounter) GenerateDetachVolumeFunc(volumeToDetach AttachedVolume, verifySafeToDetach bool, actualStateOfWorld ActualStateOfWorldAttacherUpdater) (volumetypes.GeneratedOperations, error) {
|
||||
return f.recordFuncCall("GenerateDetachVolumeFunc"), nil
|
||||
}
|
||||
|
||||
func (f *fakeOgCounter) GenerateVolumesAreAttachedFunc(attachedVolumes []AttachedVolume, nodeName types.NodeName, actualStateOfWorld ActualStateOfWorldAttacherUpdater) (volumetypes.GeneratedOperations, error) {
|
||||
return f.recordFuncCall("GenerateVolumesAreAttachedFunc"), nil
|
||||
}
|
||||
|
||||
func (f *fakeOgCounter) GenerateUnmountDeviceFunc(deviceToDetach AttachedVolume, actualStateOfWorld ActualStateOfWorldMounterUpdater, mounter mount.Interface) (volumetypes.GeneratedOperations, error) {
|
||||
return f.recordFuncCall("GenerateUnmountDeviceFunc"), nil
|
||||
}
|
||||
|
||||
func (f *fakeOgCounter) GenerateVerifyControllerAttachedVolumeFunc(volumeToMount VolumeToMount, nodeName types.NodeName, actualStateOfWorld ActualStateOfWorldAttacherUpdater) (volumetypes.GeneratedOperations, error) {
|
||||
return f.recordFuncCall("GenerateVerifyControllerAttachedVolumeFunc"), nil
|
||||
}
|
||||
|
||||
func (f *fakeOgCounter) GenerateMapVolumeFunc(waitForAttachTimeout time.Duration, volumeToMount VolumeToMount, actualStateOfWorldMounterUpdater ActualStateOfWorldMounterUpdater) (volumetypes.GeneratedOperations, error) {
|
||||
return f.recordFuncCall("GenerateMapVolumeFunc"), nil
|
||||
}
|
||||
|
||||
func (f *fakeOgCounter) GenerateUnmapVolumeFunc(volumeToUnmount MountedVolume, actualStateOfWorld ActualStateOfWorldMounterUpdater) (volumetypes.GeneratedOperations, error) {
|
||||
return f.recordFuncCall("GenerateUnmapVolumeFunc"), nil
|
||||
}
|
||||
|
||||
func (f *fakeOgCounter) GenerateUnmapDeviceFunc(deviceToDetach AttachedVolume, actualStateOfWorld ActualStateOfWorldMounterUpdater, mounter mount.Interface) (volumetypes.GeneratedOperations, error) {
|
||||
return f.recordFuncCall("GenerateUnmapDeviceFunc"), nil
|
||||
}
|
||||
|
||||
func (f *fakeOgCounter) GetVolumePluginMgr() *volume.VolumePluginMgr {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *fakeOgCounter) GenerateBulkVolumeVerifyFunc(
|
||||
map[types.NodeName][]*volume.Spec,
|
||||
string,
|
||||
map[*volume.Spec]v1.UniqueVolumeName, ActualStateOfWorldAttacherUpdater) (volumetypes.GeneratedOperations, error) {
|
||||
return f.recordFuncCall("GenerateBulkVolumeVerifyFunc"), nil
|
||||
}
|
||||
|
||||
func (f *fakeOgCounter) GenerateExpandVolumeFunc(*v1.PersistentVolumeClaim, *v1.PersistentVolume) (volumetypes.GeneratedOperations, error) {
|
||||
return f.recordFuncCall("GenerateExpandVolumeFunc"), nil
|
||||
}
|
||||
|
||||
func (f *fakeOgCounter) GenerateExpandVolumeFSWithoutUnmountingFunc(volumeToMount VolumeToMount, actualStateOfWorld ActualStateOfWorldMounterUpdater) (volumetypes.GeneratedOperations, error) {
|
||||
return f.recordFuncCall("GenerateExpandVolumeFSWithoutUnmountingFunc"), nil
|
||||
}
|
||||
|
||||
func (f *fakeOgCounter) recordFuncCall(name string) volumetypes.GeneratedOperations {
|
||||
if _, ok := f.calledFuncs[name]; ok {
|
||||
f.calledFuncs[name]++
|
||||
}
|
||||
ops := volumetypes.GeneratedOperations{
|
||||
OperationName: name,
|
||||
OperationFunc: f.opFunc,
|
||||
}
|
||||
return ops
|
||||
}
|
||||
@@ -683,7 +683,7 @@ func (og *operationGenerator) GenerateMountVolumeFunc(
|
||||
|
||||
// resizeFileSystem will resize the file system if user has requested a resize of
|
||||
// underlying persistent volume and is allowed to do so.
|
||||
resizeDone, resizeError = og.resizeFileSystem(volumeToMount, resizeOptions, volumePluginName)
|
||||
resizeDone, resizeError = og.resizeFileSystem(volumeToMount, resizeOptions)
|
||||
|
||||
if resizeError != nil {
|
||||
klog.Errorf("MountVolume.resizeFileSystem failed with %v", resizeError)
|
||||
@@ -721,7 +721,7 @@ func (og *operationGenerator) GenerateMountVolumeFunc(
|
||||
// - Volume does not support DeviceMounter interface.
|
||||
// - In case of CSI the volume does not have node stage_unstage capability.
|
||||
if !resizeDone {
|
||||
resizeDone, resizeError = og.resizeFileSystem(volumeToMount, resizeOptions, volumePluginName)
|
||||
resizeDone, resizeError = og.resizeFileSystem(volumeToMount, resizeOptions)
|
||||
if resizeError != nil {
|
||||
klog.Errorf("MountVolume.resizeFileSystem failed with %v", resizeError)
|
||||
return volumeToMount.GenerateError("MountVolume.Setup failed while expanding volume", resizeError)
|
||||
@@ -760,7 +760,7 @@ func (og *operationGenerator) GenerateMountVolumeFunc(
|
||||
}
|
||||
}
|
||||
|
||||
func (og *operationGenerator) resizeFileSystem(volumeToMount VolumeToMount, rsOpts volume.NodeResizeOptions, pluginName string) (bool, error) {
|
||||
func (og *operationGenerator) resizeFileSystem(volumeToMount VolumeToMount, rsOpts volume.NodeResizeOptions) (bool, error) {
|
||||
if !utilfeature.DefaultFeatureGate.Enabled(features.ExpandPersistentVolumes) {
|
||||
klog.V(4).Infof("Resizing is not enabled for this volume %s", volumeToMount.VolumeName)
|
||||
return true, nil
|
||||
@@ -1577,6 +1577,18 @@ func (og *operationGenerator) GenerateExpandVolumeFunc(
|
||||
func (og *operationGenerator) GenerateExpandVolumeFSWithoutUnmountingFunc(
|
||||
volumeToMount VolumeToMount,
|
||||
actualStateOfWorld ActualStateOfWorldMounterUpdater) (volumetypes.GeneratedOperations, error) {
|
||||
// Need to translate the spec here if the plugin is migrated so that the metrics
|
||||
// emitted show the correct (migrated) plugin
|
||||
if useCSIPlugin(og.volumePluginMgr, volumeToMount.VolumeSpec) {
|
||||
csiSpec, err := translateSpec(volumeToMount.VolumeSpec)
|
||||
if err == nil {
|
||||
volumeToMount.VolumeSpec = csiSpec
|
||||
}
|
||||
// If we have an error here we ignore it, the metric emitted will then be for the
|
||||
// in-tree plugin. This error case(skipped one) will also trigger an error
|
||||
// while the generated function is executed. And those errors will be handled during the execution of the generated
|
||||
// function with a back off policy.
|
||||
}
|
||||
volumePlugin, err :=
|
||||
og.volumePluginMgr.FindPluginBySpec(volumeToMount.VolumeSpec)
|
||||
if err != nil || volumePlugin == nil {
|
||||
@@ -1603,7 +1615,7 @@ func (og *operationGenerator) GenerateExpandVolumeFSWithoutUnmountingFunc(
|
||||
return volumeToMount.GenerateError("VolumeFSResize.GetDeviceMountPath failed", err)
|
||||
}
|
||||
resizeOptions.DeviceMountPath = dmp
|
||||
resizeDone, simpleErr, detailedErr = og.doOnlineExpansion(volumeToMount, actualStateOfWorld, resizeOptions, volumePlugin.GetPluginName())
|
||||
resizeDone, simpleErr, detailedErr = og.doOnlineExpansion(volumeToMount, actualStateOfWorld, resizeOptions)
|
||||
if simpleErr != nil || detailedErr != nil {
|
||||
return simpleErr, detailedErr
|
||||
}
|
||||
@@ -1623,7 +1635,7 @@ func (og *operationGenerator) GenerateExpandVolumeFSWithoutUnmountingFunc(
|
||||
|
||||
resizeOptions.DeviceMountPath = volumeMounter.GetPath()
|
||||
resizeOptions.CSIVolumePhase = volume.CSIVolumePublished
|
||||
resizeDone, simpleErr, detailedErr = og.doOnlineExpansion(volumeToMount, actualStateOfWorld, resizeOptions, volumePlugin.GetPluginName())
|
||||
resizeDone, simpleErr, detailedErr = og.doOnlineExpansion(volumeToMount, actualStateOfWorld, resizeOptions)
|
||||
if simpleErr != nil || detailedErr != nil {
|
||||
return simpleErr, detailedErr
|
||||
}
|
||||
@@ -1651,9 +1663,8 @@ func (og *operationGenerator) GenerateExpandVolumeFSWithoutUnmountingFunc(
|
||||
|
||||
func (og *operationGenerator) doOnlineExpansion(volumeToMount VolumeToMount,
|
||||
actualStateOfWorld ActualStateOfWorldMounterUpdater,
|
||||
resizeOptions volume.NodeResizeOptions,
|
||||
pluginName string) (bool, error, error) {
|
||||
resizeDone, err := og.resizeFileSystem(volumeToMount, resizeOptions, pluginName)
|
||||
resizeOptions volume.NodeResizeOptions) (bool, error, error) {
|
||||
resizeDone, err := og.resizeFileSystem(volumeToMount, resizeOptions)
|
||||
if err != nil {
|
||||
klog.Errorf("VolumeFSResize.resizeFileSystem failed : %v", err)
|
||||
e1, e2 := volumeToMount.GenerateError("VolumeFSResize.resizeFileSystem failed", err)
|
||||
|
||||
Reference in New Issue
Block a user