@@ -17,40 +17,40 @@ package mountmanager
17
17
18
18
import (
19
19
"context"
20
+ "fmt"
20
21
21
22
volumeapi "github.com/kubernetes-csi/csi-proxy/client/api/volume/v1beta1"
22
- volumeclient "github.com/kubernetes-csi/csi-proxy/client/groups/volume/v1beta1 "
23
+ "k8s.io/utils/mount "
23
24
)
24
25
25
- var _ Statter = realStatter {}
26
+ var _ Statter = & realStatter {}
26
27
27
28
type realStatter struct {
28
- VolumeClient * volumeclient. Client
29
+ mounter * mount. SafeFormatAndMount
29
30
}
30
31
31
- func NewStatter () (realStatter , error ) {
32
- volumeClient , err := volumeclient .NewClient ()
33
- if err != nil {
34
- return realStatter {}, err
35
- }
36
- return realStatter {
37
- VolumeClient : volumeClient ,
38
- }, nil
32
+ func NewStatter (mounter * mount.SafeFormatAndMount ) * realStatter {
33
+ return & realStatter {mounter : mounter }
39
34
}
40
35
41
36
// IsBlock checks if the given path is a block device
42
- func (realStatter ) IsBlockDevice (fullPath string ) (bool , error ) {
37
+ func (r * realStatter ) IsBlockDevice (fullPath string ) (bool , error ) {
43
38
return false , nil
44
39
}
45
40
46
41
// StatFS returns volume usage information
47
- func (r realStatter ) StatFS (path string ) (available , capacity , used , inodesFree , inodes , inodesUsed int64 , err error ) {
42
+ func (r * realStatter ) StatFS (path string ) (available , capacity , used , inodesFree , inodes , inodesUsed int64 , err error ) {
48
43
zero := int64 (0 )
49
44
45
+ proxy , ok := r .mounter .Interface .(* CSIProxyMounter )
46
+ if ! ok {
47
+ return zero , zero , zero , zero , zero , zero , fmt .Errorf ("could not cast to csi proxy class" )
48
+ }
49
+
50
50
idRequest := & volumeapi.VolumeIDFromMountRequest {
51
51
Mount : path ,
52
52
}
53
- idResponse , err := r .VolumeClient .GetVolumeIDFromMount (context .Background (), idRequest )
53
+ idResponse , err := proxy .VolumeClient .GetVolumeIDFromMount (context .Background (), idRequest )
54
54
if err != nil {
55
55
return zero , zero , zero , zero , zero , zero , err
56
56
}
@@ -59,7 +59,7 @@ func (r realStatter) StatFS(path string) (available, capacity, used, inodesFree,
59
59
request := & volumeapi.VolumeStatsRequest {
60
60
VolumeId : volumeId ,
61
61
}
62
- response , err := r .VolumeClient .VolumeStats (context .Background (), request )
62
+ response , err := proxy .VolumeClient .VolumeStats (context .Background (), request )
63
63
if err != nil {
64
64
return zero , zero , zero , zero , zero , zero , err
65
65
}
@@ -71,15 +71,15 @@ func (r realStatter) StatFS(path string) (available, capacity, used, inodesFree,
71
71
72
72
type fakeStatter struct {}
73
73
74
- func NewFakeStatter () fakeStatter {
75
- return fakeStatter {}
74
+ func NewFakeStatter (mounter * mount. SafeFormatAndMount ) * fakeStatter {
75
+ return & fakeStatter {}
76
76
}
77
77
78
- func (fakeStatter ) StatFS (path string ) (available , capacity , used , inodesFree , inodes , inodesUsed int64 , err error ) {
78
+ func (* fakeStatter ) StatFS (path string ) (available , capacity , used , inodesFree , inodes , inodesUsed int64 , err error ) {
79
79
// Assume the file exists and give some dummy values back
80
80
return 1 , 1 , 1 , 1 , 1 , 1 , nil
81
81
}
82
82
83
- func (fakeStatter ) IsBlockDevice (fullPath string ) (bool , error ) {
83
+ func (* fakeStatter ) IsBlockDevice (fullPath string ) (bool , error ) {
84
84
return false , nil
85
85
}
0 commit comments