Skip to content

Add disk online/offline into Stage/Unstage volumes #661

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions deploy/kubernetes/base/node_windows/node.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,5 @@ spec:
hostPath:
path: \var\lib\kubelet\plugins\pd.csi.storage.gke.io
type: DirectoryOrCreate
tolerations:
- operator: Exists
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/golang/protobuf v1.4.2
github.com/google/uuid v1.1.1
github.com/hashicorp/go-multierror v1.0.0 // indirect
github.com/kubernetes-csi/csi-proxy/client v0.2.1
github.com/kubernetes-csi/csi-proxy/client v0.2.2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you update the README as well to indicate we have a newer csi proxy dependency?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I will have another PR to update it.

github.com/kubernetes-csi/csi-test/v3 v3.0.0
github.com/onsi/ginkgo v1.11.0
github.com/onsi/gomega v1.7.1
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,11 @@ github.com/kr/pty v1.1.3/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/pty v1.1.5/go.mod h1:9r2w37qlBe7rQ6e1fg1S/9xpWHSnaqNdHD3WcMdbPDA=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kubernetes-csi/csi-proxy v0.2.2 h1:LqablYFEGw7FYBjwoh5TeXFzlcx8C+YQjKfGy6fFWJs=
github.com/kubernetes-csi/csi-proxy/client v0.2.1 h1:n21d2U9HvgQ6jfJayafRv8kXXtLvnRNEqoD0mQNucKc=
github.com/kubernetes-csi/csi-proxy/client v0.2.1/go.mod h1:6ptQQmti5QHwBxSsh8Cy00oGdogj0JXewFnu8FFjgOs=
github.com/kubernetes-csi/csi-proxy/client v0.2.2 h1:VpMddHnbYA1oBeU5nrisdyrpOAAT0HqME7fsTi6BG2w=
github.com/kubernetes-csi/csi-proxy/client v0.2.2/go.mod h1:6ptQQmti5QHwBxSsh8Cy00oGdogj0JXewFnu8FFjgOs=
github.com/kubernetes-csi/csi-test/v3 v3.0.0 h1:mVsfA4J67uNm8fdF/Pr84oMqL92qjIhjWbEUH8zv1fU=
github.com/kubernetes-csi/csi-test/v3 v3.0.0/go.mod h1:VdIKGnDZHOjg4M5yd0OZICtsoEzdn64d0K33N6dm35Q=
github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k=
Expand Down
35 changes: 33 additions & 2 deletions pkg/mount-manager/safe-mounter_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ import (
"fmt"
"os"
"path/filepath"
"strconv"
"strings"

diskapi "github.com/kubernetes-csi/csi-proxy/client/api/disk/v1beta1"
diskclient "github.com/kubernetes-csi/csi-proxy/client/groups/disk/v1beta1"
diskapi "github.com/kubernetes-csi/csi-proxy/client/api/disk/v1beta2"
diskclient "github.com/kubernetes-csi/csi-proxy/client/groups/disk/v1beta2"

fsapi "github.com/kubernetes-csi/csi-proxy/client/api/filesystem/v1beta1"
fsclient "github.com/kubernetes-csi/csi-proxy/client/groups/filesystem/v1beta1"
Expand Down Expand Up @@ -159,6 +160,25 @@ func (mounter *CSIProxyMounter) UnmountDevice(target string) error {
if err != nil {
return err
}

// Set disk to offline mode to have a clean state
getDiskNumberRequest := &volumeapi.VolumeDiskNumberRequest{
VolumeId: volumeId,
}
id, err := mounter.VolumeClient.GetVolumeDiskNumber(context.Background(), getDiskNumberRequest)
if err != nil {
return err
}
diskId := id.GetDiskNumber()
klog.V(4).Infof("get disk number %d from volume %s", diskId, volumeId)
setDiskRequest := &diskapi.SetAttachStateRequest{
DiskID: strconv.FormatInt(diskId, 10),
IsOnline: false,
}
if _, err = mounter.DiskClient.SetAttachState(context.Background(), setDiskRequest); err != nil {
return err
}

return nil
}

Expand Down Expand Up @@ -203,6 +223,17 @@ func (mounter *CSIProxyMounter) FormatAndMount(source string, target string, fst
if err != nil {
return err
}

// make sure disk is online. if disk is already online, this call should also succeed.
setDiskRequest := &diskapi.SetAttachStateRequest{
DiskID: source,
IsOnline: true,
}
_, err = mounter.DiskClient.SetAttachState(context.Background(), setDiskRequest)
if err != nil {
return err
}

volumeIDsRequest := &volumeapi.ListVolumesOnDiskRequest{
DiskId: source,
}
Expand Down
Loading