Skip to content

Update to use csi proxy beta #607

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
Sep 10, 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
8 changes: 4 additions & 4 deletions deploy/kubernetes/base/node_windows/node.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,19 @@ spec:
- name: plugin-dir
mountPath: C:\csi
- name: csi-proxy-disk-pipe
mountPath: \\.\pipe\csi-proxy-disk-v1alpha1
mountPath: \\.\pipe\csi-proxy-disk-v1beta1
- name: csi-proxy-volume-pipe
mountPath: \\.\pipe\csi-proxy-volume-v1alpha1
mountPath: \\.\pipe\csi-proxy-volume-v1beta1
- name: csi-proxy-filesystem-pipe
mountPath: \\.\pipe\csi-proxy-filesystem-v1alpha1
volumes:
- name: csi-proxy-disk-pipe
hostPath:
path: \\.\pipe\csi-proxy-disk-v1alpha1
path: \\.\pipe\csi-proxy-disk-v1beta1
type: ""
- name: csi-proxy-volume-pipe
hostPath:
path: \\.\pipe\csi-proxy-volume-v1alpha1
path: \\.\pipe\csi-proxy-volume-v1beta1
type: ""
- name: csi-proxy-filesystem-pipe
hostPath:
Expand Down
4 changes: 2 additions & 2 deletions deploy/kubernetes/base/node_windows/psp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ spec:
- pathPrefix: \var\lib\kubelet
- pathPrefix: \var\lib\kubelet\plugins_registry
- pathPrefix: \var\lib\kubelet\plugins\pd.csi.storage.gke.io
- pathPrefix: \\.\pipe\csi-proxy-disk-v1alpha1
- pathPrefix: \\.\pipe\csi-proxy-volume-v1alpha1
- pathPrefix: \\.\pipe\csi-proxy-disk-v1beta1
- pathPrefix: \\.\pipe\csi-proxy-volume-v1beta1
- pathPrefix: \\.\pipe\csi-proxy-filesystem-v1alpha1

7 changes: 3 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,17 @@ require (
cloud.google.com/go v0.45.1
github.com/GoogleCloudPlatform/k8s-cloud-provider v0.0.0-20190822182118-27a4ced34534
github.com/container-storage-interface/spec v1.2.0
github.com/golang/protobuf v1.3.4
github.com/golang/protobuf v1.4.1
github.com/google/uuid v1.1.1
github.com/hashicorp/go-multierror v1.0.0 // indirect
github.com/kubernetes-csi/csi-proxy/client v0.0.0-20200330215040-9eff16441b2a
github.com/kubernetes-csi/csi-proxy/client v0.2.0
github.com/kubernetes-csi/csi-test/v3 v3.0.0
github.com/onsi/ginkgo v1.11.0
github.com/onsi/gomega v1.7.1
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45
golang.org/x/sys v0.0.0-20191113165036-4c7a9d0fe056
golang.org/x/tools/gopls v0.3.3 // indirect
google.golang.org/api v0.10.0
google.golang.org/genproto v0.0.0-20191114150713-6bbd007550de
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013
google.golang.org/grpc v1.27.1
gopkg.in/gcfg.v1 v1.2.3
gopkg.in/warnings.v0 v0.1.2 // indirect
Expand Down
177 changes: 25 additions & 152 deletions go.sum

Large diffs are not rendered by default.

73 changes: 44 additions & 29 deletions pkg/mount-manager/safe-mounter_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,38 +22,40 @@ import (
"fmt"
"os"
"path/filepath"
"strings"

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

fsv1alpha1 "github.com/kubernetes-csi/csi-proxy/client/api/filesystem/v1alpha1"
fsclientv1alpha1 "github.com/kubernetes-csi/csi-proxy/client/groups/filesystem/v1alpha1"
fsapi "github.com/kubernetes-csi/csi-proxy/client/api/filesystem/v1alpha1"
fsclient "github.com/kubernetes-csi/csi-proxy/client/groups/filesystem/v1alpha1"

volumev1alpha1 "github.com/kubernetes-csi/csi-proxy/client/api/volume/v1alpha1"
volumeclientv1alpha1 "github.com/kubernetes-csi/csi-proxy/client/groups/volume/v1alpha1"
volumeapi "github.com/kubernetes-csi/csi-proxy/client/api/volume/v1beta1"
volumeclient "github.com/kubernetes-csi/csi-proxy/client/groups/volume/v1beta1"

"k8s.io/klog"
utilexec "k8s.io/utils/exec"
"k8s.io/utils/mount"
)

var _ mount.Interface = &CSIProxyMounter{}

type CSIProxyMounter struct {
FsClient *fsclientv1alpha1.Client
DiskClient *diskclientv1alpha1.Client
VolumeClient *volumeclientv1alpha1.Client
FsClient *fsclient.Client
DiskClient *diskclient.Client
VolumeClient *volumeclient.Client
}

func NewCSIProxyMounter() (*CSIProxyMounter, error) {
fsClient, err := fsclientv1alpha1.NewClient()
fsClient, err := fsclient.NewClient()
if err != nil {
return nil, err
}
diskClient, err := diskclientv1alpha1.NewClient()
diskClient, err := diskclient.NewClient()
if err != nil {
return nil, err
}
volumeClient, err := volumeclientv1alpha1.NewClient()
volumeClient, err := volumeclient.NewClient()
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -93,7 +95,7 @@ func (mounter *CSIProxyMounter) MountSensitive(source string, target string, fst
if err := os.MkdirAll(parentDir, 0755); err != nil {
return err
}
linkRequest := &fsv1alpha1.LinkPathRequest{
linkRequest := &fsapi.LinkPathRequest{
SourcePath: mount.NormalizeWindowsPath(source),
TargetPath: mount.NormalizeWindowsPath(target),
}
Expand All @@ -110,9 +112,9 @@ func (mounter *CSIProxyMounter) MountSensitive(source string, target string, fst
// Delete the given directory with Pod context. CSI proxy does a check for path prefix
// based on context
func (mounter *CSIProxyMounter) RemovePodDir(target string) error {
rmdirRequest := &fsv1alpha1.RmdirRequest{
rmdirRequest := &fsapi.RmdirRequest{
Path: mount.NormalizeWindowsPath(target),
Context: fsv1alpha1.PathContext_POD,
Context: fsapi.PathContext_POD,
Force: true,
}
_, err := mounter.FsClient.Rmdir(context.Background(), rmdirRequest)
Expand All @@ -125,9 +127,9 @@ func (mounter *CSIProxyMounter) RemovePodDir(target string) error {
// Delete the given directory with plugin context. CSI proxy does a check for path prefix
// based on context
func (mounter *CSIProxyMounter) RemovePluginDir(target string) error {
rmdirRequest := &fsv1alpha1.RmdirRequest{
rmdirRequest := &fsapi.RmdirRequest{
Path: mount.NormalizeWindowsPath(target),
Context: fsv1alpha1.PathContext_PLUGIN,
Context: fsapi.PathContext_PLUGIN,
Force: true,
}
_, err := mounter.FsClient.Rmdir(context.Background(), rmdirRequest)
Expand All @@ -142,30 +144,43 @@ func (mounter *CSIProxyMounter) Unmount(target string) error {
}

func (mounter *CSIProxyMounter) GetDevicePath(deviceName string, partition string, volumeKey string) (string, error) {
getDiskNumberRequest := &diskv1alpha1.GetDiskNumberByNameRequest{
DiskName: deviceName,
}
getDiskNumberResponse, err := mounter.DiskClient.GetDiskNumberByName(context.Background(), getDiskNumberRequest)
id := "page83"
listRequest := &diskapi.ListDiskIDsRequest{}
diskIDsResponse, err := mounter.DiskClient.ListDiskIDs(context.Background(), listRequest)
if err != nil {
return "", err
}
return getDiskNumberResponse.DiskNumber, nil
diskIDsMap := diskIDsResponse.GetDiskIDs()
for diskNum, diskInfo := range diskIDsMap {
klog.V(4).Infof("found disk number %s, disk info %v", diskNum, diskInfo)
idValue, found := diskInfo.Identifiers[id]
// The page83 id for gce pd has format of "Google pvc-xxxxxxx(the device name passed in here)"
if !found || idValue == "" {
continue
}
names := strings.Fields(idValue)
klog.V(4).Infof("get page83 id %s", idValue)
if names[len(names)-1] == deviceName {
return diskNum, nil
}
}
return "", fmt.Errorf("could not find disk number for device %s", deviceName)

}

// FormatAndMount accepts the source disk number, target path to mount, the fstype to format with and options to be used.
// After formatting, it will mount the disk to target path on the host
func (mounter *CSIProxyMounter) FormatAndMount(source string, target string, fstype string, options []string) error {
// Call PartitionDisk CSI proxy call to partition the disk and return the volume id
partionDiskRequest := &diskv1alpha1.PartitionDiskRequest{
partionDiskRequest := &diskapi.PartitionDiskRequest{
DiskID: source,
}

_, err := mounter.DiskClient.PartitionDisk(context.Background(), partionDiskRequest)
if err != nil {
return err
}
volumeIDsRequest := &volumev1alpha1.ListVolumesOnDiskRequest{
volumeIDsRequest := &volumeapi.ListVolumesOnDiskRequest{
DiskId: source,
}
volumeIdResponse, err := mounter.VolumeClient.ListVolumesOnDisk(context.Background(), volumeIDsRequest)
Expand All @@ -174,15 +189,15 @@ func (mounter *CSIProxyMounter) FormatAndMount(source string, target string, fst
}
// TODO: consider partitions and choose the right partition.
volumeID := volumeIdResponse.VolumeIds[0]
isVolumeFormattedRequest := &volumev1alpha1.IsVolumeFormattedRequest{
isVolumeFormattedRequest := &volumeapi.IsVolumeFormattedRequest{
VolumeId: volumeID,
}
isVolumeFormattedResponse, err := mounter.VolumeClient.IsVolumeFormatted(context.Background(), isVolumeFormattedRequest)
if err != nil {
return err
}
if !isVolumeFormattedResponse.Formatted {
formatVolumeRequest := &volumev1alpha1.FormatVolumeRequest{
formatVolumeRequest := &volumeapi.FormatVolumeRequest{
VolumeId: volumeID,
// TODO (jingxu97): Accept the filesystem and other options
}
Expand All @@ -192,7 +207,7 @@ func (mounter *CSIProxyMounter) FormatAndMount(source string, target string, fst
}
}
// Mount the volume by calling the CSI proxy call.
mountVolumeRequest := &volumev1alpha1.MountVolumeRequest{
mountVolumeRequest := &volumeapi.MountVolumeRequest{
VolumeId: volumeID,
Path: target,
}
Expand All @@ -208,7 +223,7 @@ func (mounter *CSIProxyMounter) GetMountRefs(pathname string) ([]string, error)
}

func (mounter *CSIProxyMounter) IsLikelyNotMountPoint(file string) (bool, error) {
isMountRequest := &fsv1alpha1.IsMountPointRequest{
isMountRequest := &fsapi.IsMountPointRequest{
Path: file,
}

Expand All @@ -231,7 +246,7 @@ func (mounter *CSIProxyMounter) IsMountPointMatch(mp mount.MountPoint, dir strin
// ExistsPath - Checks if a path exists. Unlike util ExistsPath, this call does not perform follow link.
func (mounter *CSIProxyMounter) ExistsPath(path string) (bool, error) {
isExistsResponse, err := mounter.FsClient.PathExists(context.Background(),
&fsv1alpha1.PathExistsRequest{
&fsapi.PathExistsRequest{
Path: mount.NormalizeWindowsPath(path),
})
return isExistsResponse.Exists, err
Expand Down
Loading