-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresizefs_windows.go
104 lines (84 loc) · 3.07 KB
/
resizefs_windows.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
//go:build windows
// +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 resizefs
import (
"context"
"fmt"
volumeapiv1 "github.com/kubernetes-csi/csi-proxy/client/api/volume/v1"
volumeapiv1beta1 "github.com/kubernetes-csi/csi-proxy/client/api/volume/v1beta1"
"k8s.io/klog"
"k8s.io/mount-utils"
mounter "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/mount-manager"
)
var _ Resizefs = &resizeFs{}
// ResizeFs Provides support for resizing file systems
type resizeFs struct {
mounter *mount.SafeFormatAndMount
}
// NewResizeFs returns new instance of resizer
func NewResizeFs(mounter *mount.SafeFormatAndMount) *resizeFs {
return &resizeFs{mounter: mounter}
}
// resize perform resize of file system
func (resizefs *resizeFs) Resize(devicePath string, deviceMountPath string) (bool, error) {
switch resizefs.mounter.Interface.(type) {
case *mounter.CSIProxyMounterV1:
return resizefs.resizeV1(devicePath, deviceMountPath)
case *mounter.CSIProxyMounterV1Beta:
return resizefs.resizeV1Beta(devicePath, deviceMountPath)
}
return false, fmt.Errorf("resize.mounter.Interface is not valid")
}
func (resizefs *resizeFs) resizeV1(devicePath string, deviceMountPath string) (bool, error) {
klog.V(3).Infof("resizeFS.Resize - Expanding mounted volume %s", deviceMountPath)
proxy := resizefs.mounter.Interface.(*mounter.CSIProxyMounterV1)
idRequest := &volumeapiv1.GetVolumeIDFromTargetPathRequest{
TargetPath: deviceMountPath,
}
idResponse, err := proxy.VolumeClient.GetVolumeIDFromTargetPath(context.Background(), idRequest)
if err != nil {
return false, err
}
volumeId := idResponse.GetVolumeId()
request := &volumeapiv1.ResizeVolumeRequest{
VolumeId: volumeId,
}
_, err = proxy.VolumeClient.ResizeVolume(context.Background(), request)
if err != nil {
return false, err
}
return true, nil
}
// resize perform resize of file system
func (resizefs *resizeFs) resizeV1Beta(devicePath string, deviceMountPath string) (bool, error) {
klog.V(3).Infof("resizeFS.Resize - Expanding mounted volume %s", deviceMountPath)
proxy := resizefs.mounter.Interface.(*mounter.CSIProxyMounterV1Beta)
idRequest := &volumeapiv1beta1.VolumeIDFromMountRequest{
Mount: deviceMountPath,
}
idResponse, err := proxy.VolumeClient.GetVolumeIDFromMount(context.Background(), idRequest)
if err != nil {
return false, err
}
volumeId := idResponse.GetVolumeId()
request := &volumeapiv1beta1.ResizeVolumeRequest{
VolumeId: volumeId,
}
_, err = proxy.VolumeClient.ResizeVolume(context.Background(), request)
if err != nil {
return false, err
}
return true, nil
}