@@ -41,8 +41,8 @@ const (
41
41
resizerSecretNamespaceKey = "csi.storage.k8s.io/resizer-secret-namespace"
42
42
)
43
43
44
- // NewCSIResizer creates a new resizer responsible for resizing CSI volumes.
45
- func NewCSIResizer (
44
+ // NewResizer creates a new resizer responsible for resizing CSI volumes.
45
+ func NewResizer (
46
46
address string , timeout time.Duration ,
47
47
k8sClient kubernetes.Interface , informerFactory informers.SharedInformerFactory ) (Resizer , error ) {
48
48
csiClient , err := csi .New (address , timeout )
@@ -55,22 +55,30 @@ func NewCSIResizer(
55
55
return nil , fmt .Errorf ("get driver name failed: %v" , err )
56
56
}
57
57
58
- supports , err := supportsPluginControllerService (csiClient , timeout )
58
+ supportControllerService , err := supportsPluginControllerService (csiClient , timeout )
59
59
if err != nil {
60
60
return nil , fmt .Errorf ("failed to check if plugin supports controller service: %v" , err )
61
61
}
62
62
63
- if ! supports {
63
+ if ! supportControllerService {
64
64
return nil , errors .New ("CSI driver does not support controller service" )
65
65
}
66
66
67
- supports , err = supportsControllerResize (csiClient , timeout )
67
+ supportControllerResize , err : = supportsControllerResize (csiClient , timeout )
68
68
if err != nil {
69
69
return nil , fmt .Errorf ("failed to check if plugin supports controller resize: %v" , err )
70
70
}
71
71
72
- if ! supports {
73
- return nil , fmt .Errorf ("CSI driver does not support controller resize" )
72
+ if ! supportControllerResize {
73
+ supportsNodeResize , err := supportsNodeResize (csiClient , timeout )
74
+ if err != nil {
75
+ return nil , fmt .Errorf ("failed to check if plugin supports node resize: %v" , err )
76
+ }
77
+ if supportsNodeResize {
78
+ klog .Info ("The CSI driver supports node resize only, using trivial resizer to handle resize requests" )
79
+ return newTrivialResizer (driverName ), nil
80
+ }
81
+ return nil , fmt .Errorf ("CSI driver neither supports controller resize nor node resize" )
74
82
}
75
83
76
84
return & csiResizer {
@@ -166,6 +174,12 @@ func supportsControllerResize(client csi.Client, timeout time.Duration) (bool, e
166
174
return client .SupportsControllerResize (ctx )
167
175
}
168
176
177
+ func supportsNodeResize (client csi.Client , timeout time.Duration ) (bool , error ) {
178
+ ctx , cancel := timeoutCtx (timeout )
179
+ defer cancel ()
180
+ return client .SupportsNodeResize (ctx )
181
+ }
182
+
169
183
func timeoutCtx (timeout time.Duration ) (context.Context , context.CancelFunc ) {
170
184
return context .WithTimeout (context .Background (), timeout )
171
185
}
0 commit comments