-
Notifications
You must be signed in to change notification settings - Fork 159
Support GCEPD driver for Windows #483
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
+610
−118
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// +build !windows | ||
|
||
/* | ||
Copyright 2020 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 gceGCEDriver | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/status" | ||
"k8s.io/utils/mount" | ||
"sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/common" | ||
) | ||
|
||
func getDevicePath(ns *GCENodeServer, volumeID, partition string) (string, error) { | ||
volumeKey, err := common.VolumeIDToKey(volumeID) | ||
if err != nil { | ||
return "", err | ||
} | ||
deviceName, err := common.GetDeviceName(volumeKey) | ||
if err != nil { | ||
return "", fmt.Errorf("error getting device name: %v", err) | ||
} | ||
devicePaths := ns.DeviceUtils.GetDiskByIdPaths(deviceName, partition) | ||
devicePath, err := ns.DeviceUtils.VerifyDevicePath(devicePaths, deviceName) | ||
if err != nil { | ||
return "", status.Error(codes.Internal, fmt.Sprintf("error verifying GCE PD (%q) is attached: %v", deviceName, err)) | ||
} | ||
if devicePath == "" { | ||
return "", status.Error(codes.Internal, fmt.Sprintf("Unable to find device path out of attempted paths: %v", devicePaths)) | ||
} | ||
return devicePath, nil | ||
} | ||
|
||
func formatAndMount(source, target, fstype string, options []string, m *mount.SafeFormatAndMount) error { | ||
return m.FormatAndMount(source, target, fstype, options) | ||
} | ||
|
||
func preparePublishPath(path string, m *mount.SafeFormatAndMount) error { | ||
return os.MkdirAll(path, 0750) | ||
} | ||
|
||
func prepareStagePath(path string, m *mount.SafeFormatAndMount) error { | ||
return os.MkdirAll(path, 0750) | ||
} | ||
|
||
func cleanupPublishPath(path string, m *mount.SafeFormatAndMount) error { | ||
return mount.CleanupMountPoint(path, m, false /* bind mount */) | ||
} | ||
|
||
func cleanupStagePath(path string, m *mount.SafeFormatAndMount) error { | ||
return cleanupPublishPath(path, m) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// +build windows | ||
|
||
/* | ||
Copyright 2020 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 gceGCEDriver | ||
|
||
import ( | ||
"fmt" | ||
"k8s.io/utils/mount" | ||
"sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/common" | ||
mounter "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/mount-manager" | ||
) | ||
|
||
func formatAndMount(source, target, fstype string, options []string, m *mount.SafeFormatAndMount) error { | ||
proxy, ok := m.Interface.(*mounter.CSIProxyMounter) | ||
if !ok { | ||
return fmt.Errorf("could not cast to csi proxy class") | ||
} | ||
return proxy.FormatAndMount(source, target, fstype, options) | ||
} | ||
|
||
// Before mounting (which means creating symlink) in Windows, the targetPath should | ||
// not exist. Currently kubelet creates the path beforehand, this is a workaround to | ||
// remove the path first. | ||
func preparePublishPath(path string, m *mount.SafeFormatAndMount) error { | ||
proxy, ok := m.Interface.(*mounter.CSIProxyMounter) | ||
if !ok { | ||
return fmt.Errorf("could not cast to csi proxy class") | ||
} | ||
exists, err := proxy.ExistsPath(path) | ||
if err != nil { | ||
return err | ||
} | ||
if exists { | ||
return proxy.RemovePodDir(path) | ||
} | ||
return nil | ||
} | ||
|
||
// Before staging (which means creating symlink) in Windows, the targetPath should | ||
// not exist. | ||
func prepareStagePath(path string, m *mount.SafeFormatAndMount) error { | ||
return nil | ||
} | ||
|
||
func cleanupPublishPath(path string, m *mount.SafeFormatAndMount) error { | ||
proxy, ok := m.Interface.(*mounter.CSIProxyMounter) | ||
if !ok { | ||
return fmt.Errorf("could not cast to csi proxy class") | ||
} | ||
return proxy.RemovePodDir(path) | ||
} | ||
|
||
func cleanupStagePath(path string, m *mount.SafeFormatAndMount) error { | ||
proxy, ok := m.Interface.(*mounter.CSIProxyMounter) | ||
if !ok { | ||
return fmt.Errorf("could not cast to csi proxy class") | ||
} | ||
return proxy.RemovePluginDir(path) | ||
} | ||
|
||
// search Windows disk number by volumeID | ||
func getDevicePath(ns *GCENodeServer, volumeID, partition string) (string, error) { | ||
volumeKey, err := common.VolumeIDToKey(volumeID) | ||
if err != nil { | ||
return "", err | ||
} | ||
deviceName, err := common.GetDeviceName(volumeKey) | ||
if err != nil { | ||
return "", fmt.Errorf("error getting device name: %v", err) | ||
} | ||
proxy, ok := ns.Mounter.Interface.(*mounter.CSIProxyMounter) | ||
if !ok { | ||
return "", fmt.Errorf("could not cast to csi proxy class") | ||
} | ||
return proxy.GetDevicePath(deviceName, partition, volumeKey.Name) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: definitely out of scope for this PR, but the convention is to avoid mixCaps: https://golang.org/doc/effective_go.html#package-names
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ack. we can do another PR for it.