Skip to content

Commit

Permalink
Change interface of SetUp function
Browse files Browse the repository at this point in the history
  • Loading branch information
gnufied committed Dec 2, 2019
1 parent db9ac38 commit cdbd3ba
Show file tree
Hide file tree
Showing 60 changed files with 159 additions and 282 deletions.
1 change: 0 additions & 1 deletion hack/.staticcheck_failures
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ pkg/volume/flexvolume
pkg/volume/flocker
pkg/volume/hostpath
pkg/volume/iscsi
pkg/volume/local
pkg/volume/portworx
pkg/volume/quobyte
pkg/volume/rbd
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ func (attacher *testPluginAttacher) GetDeviceMountPath(spec *volume.Spec) (strin
return "", nil
}

func (attacher *testPluginAttacher) MountDevice(spec *volume.Spec, devicePath string, deviceMountPath string) error {
func (attacher *testPluginAttacher) MountDevice(spec *volume.Spec, devicePath string, deviceMountPath string) (volumetypes.OperationStatus, error) {
attacher.pluginLock.Lock()
defer attacher.pluginLock.Unlock()
if spec == nil {
Expand Down
8 changes: 2 additions & 6 deletions pkg/kubelet/kubelet_volumes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -531,18 +531,14 @@ func (f *stubVolume) CanMount() error {
return nil
}

func (f *stubVolume) SetUp(mounterArgs volume.MounterArgs) error {
return nil
func (f *stubVolume) SetUp(mounterArgs volume.MounterArgs) (volumetypes.OperationStatus, error) {
return volumetypes.OperationFinished, nil
}

func (f *stubVolume) SetUpAt(dir string, mounterArgs volume.MounterArgs) error {
return nil
}

func (f *stubVolume) SetUpWithStatusTracking(mountArgs volume.MounterArgs) (volumetypes.OperationStatus, error) {
return volumetypes.OperationFinished, nil
}

type stubBlockVolume struct {
dirPath string
volName string
Expand Down
3 changes: 2 additions & 1 deletion pkg/kubelet/volumemanager/cache/actual_state_of_world.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ type AttachedVolume struct {
DeviceMountState operationexecutor.DeviceMountState
}

// DeviceMayBeMounted returns true if device may be mounted in global path.
// DeviceMayBeMounted returns true if device is mounted in global path or is in
// uncertain state.
func (av AttachedVolume) DeviceMayBeMounted() bool {
return av.DeviceMountState == operationexecutor.DeviceGloballyMounted ||
av.DeviceMountState == operationexecutor.DeviceMountUncertain
Expand Down
9 changes: 2 additions & 7 deletions pkg/volume/awsebs/aws_ebs.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,13 +366,8 @@ func (b *awsElasticBlockStoreMounter) CanMount() error {
}

// SetUp attaches the disk and bind mounts to the volume path.
func (b *awsElasticBlockStoreMounter) SetUp(mounterArgs volume.MounterArgs) error {
return b.SetUpAt(b.GetPath(), mounterArgs)
}

// SetupWithStatusTracking attaches the disk and bind mounts to the volume path.
func (b *awsElasticBlockStoreMounter) SetUpWithStatusTracking(mounterArgs volume.MounterArgs) (volumetypes.OperationStatus, error) {
err := b.SetUp(mounterArgs)
func (b *awsElasticBlockStoreMounter) SetUp(mounterArgs volume.MounterArgs) (volumetypes.OperationStatus, error) {
err := b.SetUpAt(b.GetPath(), mounterArgs)
return volumetypes.OperationFinished, err
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/volume/awsebs/aws_ebs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func TestPlugin(t *testing.T) {
t.Errorf("Got unexpected path: %s", path)
}

if err := mounter.SetUp(volume.MounterArgs{}); err != nil {
if _, err := mounter.SetUp(volume.MounterArgs{}); err != nil {
t.Errorf("Expected success, got: %v", err)
}
if _, err := os.Stat(path); err != nil {
Expand Down Expand Up @@ -372,7 +372,7 @@ func TestMountOptions(t *testing.T) {
t.Errorf("Got a nil Mounter")
}

if err := mounter.SetUp(volume.MounterArgs{}); err != nil {
if _, err := mounter.SetUp(volume.MounterArgs{}); err != nil {
t.Errorf("Expected success, got: %v", err)
}
mountOptions := fakeMounter.MountPoints[0].Opts
Expand Down
8 changes: 2 additions & 6 deletions pkg/volume/azure_dd/azure_mounter.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,8 @@ func (m *azureDiskMounter) CanMount() error {
return nil
}

func (m *azureDiskMounter) SetUp(mounterArgs volume.MounterArgs) error {
return m.SetUpAt(m.GetPath(), mounterArgs)
}

func (m *azureDiskMounter) SetUpWithStatusTracking(mounterArgs volume.MounterArgs) (volumetypes.OperationStatus, error) {
err := m.SetUp(mounterArgs)
func (m *azureDiskMounter) SetUp(mounterArgs volume.MounterArgs) (volumetypes.OperationStatus, error) {
err := m.SetUpAt(m.GetPath(), mounterArgs)
return volumetypes.OperationFinished, err
}

Expand Down
9 changes: 2 additions & 7 deletions pkg/volume/azure_file/azure_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,8 @@ func (b *azureFileMounter) CanMount() error {
}

// SetUp attaches the disk and bind mounts to the volume path.
func (b *azureFileMounter) SetUp(mounterArgs volume.MounterArgs) error {
return b.SetUpAt(b.GetPath(), mounterArgs)
}

// SetUp attaches the disk and bind mounts to the volume path.
func (b *azureFileMounter) SetUpWithStatusTracking(mounterArgs volume.MounterArgs) (volumetypes.OperationStatus, error) {
err := b.SetUp(mounterArgs)
func (b *azureFileMounter) SetUp(mounterArgs volume.MounterArgs) (volumetypes.OperationStatus, error) {
err := b.SetUpAt(b.GetPath(), mounterArgs)
return volumetypes.OperationFinished, err
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/volume/azure_file/azure_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func testPlugin(t *testing.T, tmpDir string, volumeHost volume.VolumeHost) {
t.Errorf("Got unexpected path: %s", path)
}

if err := mounter.SetUp(volume.MounterArgs{}); err != nil {
if _, err := mounter.SetUp(volume.MounterArgs{}); err != nil {
t.Errorf("Expected success, got: %v", err)
}
if _, err := os.Stat(path); err != nil {
Expand Down
9 changes: 2 additions & 7 deletions pkg/volume/cephfs/cephfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,8 @@ func (cephfsVolume *cephfsMounter) CanMount() error {
}

// SetUp attaches the disk and bind mounts to the volume path.
func (cephfsVolume *cephfsMounter) SetUp(mounterArgs volume.MounterArgs) error {
return cephfsVolume.SetUpAt(cephfsVolume.GetPath(), mounterArgs)
}

// SetUp attaches the disk and bind mounts to the volume path.
func (cephfsVolume *cephfsMounter) SetUpWithStatusTracking(mounterArgs volume.MounterArgs) (volumetypes.OperationStatus, error) {
err := cephfsVolume.SetUp(mounterArgs)
func (cephfsVolume *cephfsMounter) SetUp(mounterArgs volume.MounterArgs) (volumetypes.OperationStatus, error) {
err := cephfsVolume.SetUpAt(cephfsVolume.GetPath(), mounterArgs)
return volumetypes.OperationFinished, err
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/volume/cephfs/cephfs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func TestPlugin(t *testing.T) {
if volumePath != volpath {
t.Errorf("Got unexpected path: %s", volumePath)
}
if err := mounter.SetUp(volume.MounterArgs{}); err != nil {
if _, err := mounter.SetUp(volume.MounterArgs{}); err != nil {
t.Errorf("Expected success, got: %v", err)
}
if _, err := os.Stat(volumePath); err != nil {
Expand Down
8 changes: 2 additions & 6 deletions pkg/volume/cinder/cinder.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,12 +390,8 @@ func (b *cinderVolumeMounter) CanMount() error {
return nil
}

func (b *cinderVolumeMounter) SetUp(mounterArgs volume.MounterArgs) error {
return b.SetUpAt(b.GetPath(), mounterArgs)
}

func (b *cinderVolumeMounter) SetUpWithStatusTracking(mounterArgs volume.MounterArgs) (volumetypes.OperationStatus, error) {
err := b.SetUp(mounterArgs)
func (b *cinderVolumeMounter) SetUp(mounterArgs volume.MounterArgs) (volumetypes.OperationStatus, error) {
err := b.SetUpAt(b.GetPath(), mounterArgs)
return volumetypes.OperationFinished, err
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/volume/cinder/cinder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func TestPlugin(t *testing.T) {
t.Errorf("Got unexpected path: %s", path)
}

if err := mounter.SetUp(volume.MounterArgs{}); err != nil {
if _, err := mounter.SetUp(volume.MounterArgs{}); err != nil {
t.Errorf("Expected success, got: %v", err)
}
if _, err := os.Stat(path); err != nil {
Expand Down
8 changes: 2 additions & 6 deletions pkg/volume/configmap/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,8 @@ func (b *configMapVolumeMounter) CanMount() error {
return nil
}

func (b *configMapVolumeMounter) SetUp(mounterArgs volume.MounterArgs) error {
return b.SetUpAt(b.GetPath(), mounterArgs)
}

func (b *configMapVolumeMounter) SetUpWithStatusTracking(mounterArgs volume.MounterArgs) (volumetypes.OperationStatus, error) {
err := b.SetUp(mounterArgs)
func (b *configMapVolumeMounter) SetUp(mounterArgs volume.MounterArgs) (volumetypes.OperationStatus, error) {
err := b.SetUpAt(b.GetPath(), mounterArgs)
return volumetypes.OperationFinished, err
}

Expand Down
10 changes: 5 additions & 5 deletions pkg/volume/configmap/configmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ func TestPlugin(t *testing.T) {
var mounterArgs volume.MounterArgs
group := int64(1001)
mounterArgs.FsGroup = &group
err = mounter.SetUp(mounterArgs)
_, err = mounter.SetUp(mounterArgs)
if err != nil {
t.Errorf("Failed to setup volume: %v", err)
}
Expand Down Expand Up @@ -428,7 +428,7 @@ func TestPluginReboot(t *testing.T) {
var mounterArgs volume.MounterArgs
group := int64(1001)
mounterArgs.FsGroup = &group
err = mounter.SetUp(mounterArgs)
_, err = mounter.SetUp(mounterArgs)
if err != nil {
t.Errorf("Failed to setup volume: %v", err)
}
Expand Down Expand Up @@ -492,7 +492,7 @@ func TestPluginOptional(t *testing.T) {
var mounterArgs volume.MounterArgs
group := int64(1001)
mounterArgs.FsGroup = &group
err = mounter.SetUp(mounterArgs)
_, err = mounter.SetUp(mounterArgs)
if err != nil {
t.Errorf("Failed to setup volume: %v", err)
}
Expand Down Expand Up @@ -591,7 +591,7 @@ func TestPluginKeysOptional(t *testing.T) {
var mounterArgs volume.MounterArgs
group := int64(1001)
mounterArgs.FsGroup = &group
err = mounter.SetUp(mounterArgs)
_, err = mounter.SetUp(mounterArgs)
if err != nil {
t.Errorf("Failed to setup volume: %v", err)
}
Expand Down Expand Up @@ -671,7 +671,7 @@ func TestInvalidConfigMapSetup(t *testing.T) {
var mounterArgs volume.MounterArgs
group := int64(1001)
mounterArgs.FsGroup = &group
err = mounter.SetUp(mounterArgs)
_, err = mounter.SetUp(mounterArgs)
if err == nil {
t.Errorf("Expected setup to fail")
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/volume/csi/csi_attacher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1199,7 +1199,7 @@ func TestAttacherMountDevice(t *testing.T) {
}

// Run
exitStatus, err := csiAttacher.MountDeviceWithStatusTracking(tc.spec, tc.devicePath, tc.deviceMountPath)
exitStatus, err := csiAttacher.MountDevice(tc.spec, tc.devicePath, tc.deviceMountPath)

// Verify
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions pkg/volume/csi/csi_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -632,18 +632,18 @@ func isFinalError(err error) bool {
if !ok {
// This is not gRPC error. The operation must have failed before gRPC
// method was called, otherwise we would get gRPC error.
// We don't know if any previous CreateVolume is in progress, be on the safe side.
// We don't know if any previous volume operation is in progress, be on the safe side.
return false
}
switch st.Code() {
case codes.Canceled, // gRPC: Client Application cancelled the request
codes.DeadlineExceeded, // gRPC: Timeout
codes.Unavailable, // gRPC: Server shutting down, TCP connection broken - previous CreateVolume() may be still in progress.
codes.ResourceExhausted, // gRPC: Server temporarily out of resources - previous Publish operation may be still in progress.
codes.Unavailable, // gRPC: Server shutting down, TCP connection broken - previous volume operation may be still in progress.
codes.ResourceExhausted, // gRPC: Server temporarily out of resources - previous volume operation may be still in progress.
codes.Aborted: // CSI: Operation pending for volume
return false
}
// All other errors mean that provisioning either did not
// All other errors mean that operation either did not
// even start or failed. It is for sure not in progress.
return true
}
6 changes: 1 addition & 5 deletions pkg/volume/csi/csi_mounter.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,7 @@ func (c *csiMountMgr) CanMount() error {
return nil
}

func (c *csiMountMgr) SetUp(mounterArgs volume.MounterArgs) error {
return c.SetUpAt(c.GetPath(), mounterArgs)
}

func (c *csiMountMgr) SetUpWithStatusTracking(mounterArgs volume.MounterArgs) (volumetypes.OperationStatus, error) {
func (c *csiMountMgr) SetUp(mounterArgs volume.MounterArgs) (volumetypes.OperationStatus, error) {
opExitStatus, err := c.setupUtil(c.GetPath(), mounterArgs)
return opExitStatus, err
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/volume/csi/csi_mounter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func MounterSetUpTests(t *testing.T, podInfoEnabled bool) {
var mounterArgs volume.MounterArgs
fsGroup := int64(2000)
mounterArgs.FsGroup = &fsGroup
if err := csiMounter.SetUp(mounterArgs); err != nil {
if _, err := csiMounter.SetUp(mounterArgs); err != nil {
t.Fatalf("mounter.Setup failed: %v", err)
}

Expand Down Expand Up @@ -361,7 +361,7 @@ func TestMounterSetUpSimple(t *testing.T) {
}

// Mounter.SetUp()
if err := csiMounter.SetUp(volume.MounterArgs{}); err != nil {
if _, err := csiMounter.SetUp(volume.MounterArgs{}); err != nil {
t.Fatalf("mounter.Setup failed: %v", err)
}

Expand Down Expand Up @@ -488,7 +488,7 @@ func TestMounterSetupWithStatusTracking(t *testing.T) {
}
}

opExistStatus, err := csiMounter.SetUpWithStatusTracking(volume.MounterArgs{})
opExistStatus, err := csiMounter.SetUp(volume.MounterArgs{})

if opExistStatus != tc.exitStatus {
t.Fatalf("expected exitStatus: %v but got %v", tc.exitStatus, opExistStatus)
Expand Down Expand Up @@ -604,7 +604,7 @@ func TestMounterSetUpWithInline(t *testing.T) {
}

// Mounter.SetUp()
if err := csiMounter.SetUp(volume.MounterArgs{}); err != nil {
if _, err := csiMounter.SetUp(volume.MounterArgs{}); err != nil {
t.Fatalf("mounter.Setup failed: %v", err)
}

Expand Down Expand Up @@ -757,7 +757,7 @@ func TestMounterSetUpWithFSGroup(t *testing.T) {
fsGroupPtr = &fsGroup
}
mounterArgs.FsGroup = fsGroupPtr
if err := csiMounter.SetUp(mounterArgs); err != nil {
if _, err := csiMounter.SetUp(mounterArgs); err != nil {
t.Fatalf("mounter.Setup failed: %v", err)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/volume/csi/csi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ func TestCSI_VolumeAll(t *testing.T) {
csiMounter.csiClient = csiClient
var mounterArgs volume.MounterArgs
mounterArgs.FsGroup = fsGroup
if err := csiMounter.SetUp(mounterArgs); err != nil {
if _, err := csiMounter.SetUp(mounterArgs); err != nil {
t.Fatalf("csiTest.VolumeAll mounter.Setup(fsGroup) failed: %s", err)
}
t.Log("csiTest.VolumeAll mounter.Setup(fsGroup) done OK")
Expand Down
8 changes: 2 additions & 6 deletions pkg/volume/downwardapi/downwardapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,8 @@ func (b *downwardAPIVolumeMounter) CanMount() error {
// This function is not idempotent by design. We want the data to be refreshed periodically.
// The internal sync interval of kubelet will drive the refresh of data.
// TODO: Add volume specific ticker and refresh loop
func (b *downwardAPIVolumeMounter) SetUp(mounterArgs volume.MounterArgs) error {
return b.SetUpAt(b.GetPath(), mounterArgs)
}

func (b *downwardAPIVolumeMounter) SetUpWithStatusTracking(mounterArgs volume.MounterArgs) (volumetypes.OperationStatus, error) {
err := b.SetUp(mounterArgs)
func (b *downwardAPIVolumeMounter) SetUp(mounterArgs volume.MounterArgs) (volumetypes.OperationStatus, error) {
err := b.SetUpAt(b.GetPath(), mounterArgs)
return volumetypes.OperationFinished, err
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/volume/downwardapi/downwardapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ func newDownwardAPITest(t *testing.T, name string, volumeFiles, podLabels, podAn

volumePath := mounter.GetPath()

err = mounter.SetUp(volume.MounterArgs{})
_, err = mounter.SetUp(volume.MounterArgs{})
if err != nil {
t.Errorf("Failed to setup volume: %v", err)
}
Expand Down Expand Up @@ -380,7 +380,7 @@ func (step reSetUp) run(test *downwardAPITest) {
}

// now re-run Setup
if err = test.mounter.SetUp(volume.MounterArgs{}); err != nil {
if _, err = test.mounter.SetUp(volume.MounterArgs{}); err != nil {
test.t.Errorf("Failed to re-setup volume: %v", err)
}

Expand Down
8 changes: 2 additions & 6 deletions pkg/volume/emptydir/empty_dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,8 @@ func (ed *emptyDir) CanMount() error {
}

// SetUp creates new directory.
func (ed *emptyDir) SetUp(mounterArgs volume.MounterArgs) error {
return ed.SetUpAt(ed.GetPath(), mounterArgs)
}

func (ed *emptyDir) SetUpWithStatusTracking(mounterArgs volume.MounterArgs) (volumetypes.OperationStatus, error) {
err := ed.SetUp(mounterArgs)
func (ed *emptyDir) SetUp(mounterArgs volume.MounterArgs) (volumetypes.OperationStatus, error) {
err := ed.SetUpAt(ed.GetPath(), mounterArgs)
return volumetypes.OperationFinished, err
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/volume/emptydir/empty_dir_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func doTestPlugin(t *testing.T, config pluginTestConfig) {
t.Errorf("Got unexpected path: %s", volPath)
}

if err := mounter.SetUp(volume.MounterArgs{}); err != nil {
if _, err := mounter.SetUp(volume.MounterArgs{}); err != nil {
t.Errorf("Expected success, got: %v", err)
}

Expand Down
Loading

0 comments on commit cdbd3ba

Please sign in to comment.