@@ -137,101 +137,103 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
137
137
return nil , err
138
138
}
139
139
log .Infof ("skipping calling provider as it's mock" )
140
- } else {
141
- // ensure it's read-only
142
- if ! req .GetReadonly () {
143
- return nil , status .Error (codes .InvalidArgument , "Readonly is not true in request" )
144
- }
145
- // get provider volume path
146
- providerVolumePath := ns .providerVolumePath
147
- if providerVolumePath == "" {
148
- return nil , fmt .Errorf ("Providers volume path not found. Set PROVIDERS_VOLUME_PATH for pod: %s, ns: %s" , podUID , podNamespace )
149
- }
140
+ return & csi.NodePublishVolumeResponse {}, nil
141
+ }
142
+ // ensure it's read-only
143
+ if ! req .GetReadonly () {
144
+ return nil , status .Error (codes .InvalidArgument , "Readonly is not true in request" )
145
+ }
146
+ // get provider volume path
147
+ providerVolumePath := ns .providerVolumePath
148
+ if providerVolumePath == "" {
149
+ return nil , fmt .Errorf ("Providers volume path not found. Set PROVIDERS_VOLUME_PATH for pod: %s, ns: %s" , podUID , podNamespace )
150
+ }
150
151
151
- providerBinary := ns .getProviderPath (runtime .GOOS , providerName )
152
- if _ , err := os .Stat (providerBinary ); err != nil {
153
- log .Errorf ("failed to find provider %s, err: %v for pod: %s, ns: %s" , providerName , err , podUID , podNamespace )
154
- return nil , err
155
- }
152
+ providerBinary := ns .getProviderPath (runtime .GOOS , providerName )
153
+ if _ , err := os .Stat (providerBinary ); err != nil {
154
+ log .Errorf ("failed to find provider %s, err: %v for pod: %s, ns: %s" , providerName , err , podUID , podNamespace )
155
+ return nil , err
156
+ }
156
157
157
- parametersStr , err := json .Marshal (parameters )
158
- if err != nil {
159
- log .Errorf ("failed to marshal parameters, err: %v for pod: %s, ns: %s" , err , podUID , podNamespace )
160
- return nil , err
161
- }
162
- secretStr , err := json .Marshal (secrets )
163
- if err != nil {
164
- log .Errorf ("failed to marshal secrets, err: %v for pod: %s, ns: %s" , err , podUID , podNamespace )
165
- return nil , err
166
- }
167
- permissionStr , err := json .Marshal (permission )
168
- if err != nil {
169
- log .Errorf ("failed to marshal file permission, err: %v for pod: %s, ns: %s" , err , podUID , podNamespace )
170
- return nil , err
171
- }
158
+ parametersStr , err := json .Marshal (parameters )
159
+ if err != nil {
160
+ log .Errorf ("failed to marshal parameters, err: %v for pod: %s, ns: %s" , err , podUID , podNamespace )
161
+ return nil , err
162
+ }
163
+ secretStr , err := json .Marshal (secrets )
164
+ if err != nil {
165
+ log .Errorf ("failed to marshal secrets, err: %v for pod: %s, ns: %s" , err , podUID , podNamespace )
166
+ return nil , err
167
+ }
168
+ permissionStr , err := json .Marshal (permission )
169
+ if err != nil {
170
+ log .Errorf ("failed to marshal file permission, err: %v for pod: %s, ns: %s" , err , podUID , podNamespace )
171
+ return nil , err
172
+ }
173
+
174
+ // mount before providers can write content to it
175
+ // In linux Mount tmpfs mounts tmpfs to targetPath
176
+ // In windows Mount tmpfs checks if the targetPath exists and if not, will create the target path
177
+ // https://github.com/kubernetes/utils/blob/master/mount/mount_windows.go#L68-L71
178
+ err = ns .mounter .Mount ("tmpfs" , targetPath , "tmpfs" , []string {})
179
+ if err != nil {
180
+ log .Errorf ("mount err: %v" , err )
181
+ return nil , err
182
+ }
172
183
173
- // mount before providers can write content to it
174
- err = ns .mounter .Mount ("tmpfs" , targetPath , "tmpfs" , []string {})
184
+ log .Debugf ("Calling provider: %s for pod: %s, ns: %s" , providerName , podUID , podNamespace )
185
+
186
+ // check if minimum compatible provider version with current driver version is set
187
+ // if minimum version is not provided, skip check
188
+ if _ , exists := ns .minProviderVersions [providerName ]; ! exists {
189
+ log .Warningf ("minimum compatible %s provider version not set for pod: %s, ns: %s" , providerName , podUID , podNamespace )
190
+ } else {
191
+ // check if provider is compatible with driver
192
+ providerCompatible , err := version .IsProviderCompatible (providerBinary , ns .minProviderVersions [providerName ])
175
193
if err != nil {
176
- log .Errorf ("mount err: %v" , err )
177
194
return nil , err
178
195
}
179
-
180
- log .Debugf ("Calling provider: %s for pod: %s, ns: %s" , providerName , podUID , podNamespace )
181
-
182
- // check if minimum compatible provider version with current driver version is set
183
- // if minimum version is not provided, skip check
184
- if _ , exists := ns .minProviderVersions [providerName ]; ! exists {
185
- log .Warningf ("minimum compatible %s provider version not set for pod: %s, ns: %s" , providerName , podUID , podNamespace )
186
- } else {
187
- // check if provider is compatible with driver
188
- providerCompatible , err := version .IsProviderCompatible (providerBinary , ns .minProviderVersions [providerName ])
189
- if err != nil {
190
- return nil , err
191
- }
192
- if ! providerCompatible {
193
- return nil , fmt .Errorf ("Minimum supported %s provider version with current driver is %s" , providerName , ns .minProviderVersions [providerName ])
194
- }
196
+ if ! providerCompatible {
197
+ return nil , fmt .Errorf ("Minimum supported %s provider version with current driver is %s" , providerName , ns .minProviderVersions [providerName ])
195
198
}
199
+ }
196
200
197
- args := []string {
198
- "--attributes" , string (parametersStr ),
199
- "--secrets" , string (secretStr ),
200
- "--targetPath" , string (targetPath ),
201
- "--permission" , string (permissionStr ),
202
- }
201
+ args := []string {
202
+ "--attributes" , string (parametersStr ),
203
+ "--secrets" , string (secretStr ),
204
+ "--targetPath" , string (targetPath ),
205
+ "--permission" , string (permissionStr ),
206
+ }
203
207
204
- log .Infof ("provider command invoked: %s %s %v" , providerBinary ,
205
- "--attributes [REDACTED] --secrets [REDACTED]" , args [4 :])
208
+ log .Infof ("provider command invoked: %s %s %v" , providerBinary ,
209
+ "--attributes [REDACTED] --secrets [REDACTED]" , args [4 :])
206
210
207
- cmd := exec .Command (
208
- providerBinary ,
209
- args ... ,
210
- )
211
+ cmd := exec .Command (
212
+ providerBinary ,
213
+ args ... ,
214
+ )
211
215
212
- stdout := & bytes.Buffer {}
213
- stderr := & bytes.Buffer {}
214
- cmd .Stderr , cmd .Stdout = stderr , stdout
216
+ stdout := & bytes.Buffer {}
217
+ stderr := & bytes.Buffer {}
218
+ cmd .Stderr , cmd .Stdout = stderr , stdout
215
219
216
- err = cmd .Run ()
220
+ err = cmd .Run ()
217
221
218
- log .Infof (string (stdout .String ()))
222
+ log .Infof (string (stdout .String ()))
223
+ if err != nil {
224
+ ns .mounter .Unmount (targetPath )
225
+ log .Errorf ("error invoking provider, err: %v, output: %v for pod: %s, ns: %s" , err , stderr .String (), podUID , podNamespace )
226
+ return nil , fmt .Errorf ("error mounting secret %v for pod: %s, ns: %s" , stderr .String (), podUID , podNamespace )
227
+ }
228
+ // create/update secrets with mounted file content
229
+ // add pod info to the secretProviderClass obj's byPod status field
230
+ if syncK8sSecret {
231
+ log .Debugf ("[NodePublishVolume] syncK8sSecret is enabled for pod: %s, ns: %s" , podUID , podNamespace )
232
+ err := syncK8sObjects (ctx , targetPath , podUID , podNamespace , secretProviderClass , secretObjects )
219
233
if err != nil {
220
- ns .mounter .Unmount (targetPath )
221
- log .Errorf ("error invoking provider, err: %v, output: %v for pod: %s, ns: %s" , err , stderr .String (), podUID , podNamespace )
222
- return nil , fmt .Errorf ("error mounting secret %v for pod: %s, ns: %s" , stderr .String (), podUID , podNamespace )
223
- }
224
- // create/update secrets with mounted file content
225
- // add pod info to the secretProviderClass obj's byPod status field
226
- if syncK8sSecret {
227
- log .Debugf ("[NodePublishVolume] syncK8sSecret is enabled for pod: %s, ns: %s" , podUID , podNamespace )
228
- err := syncK8sObjects (ctx , targetPath , podUID , podNamespace , secretProviderClass , secretObjects )
229
- if err != nil {
230
- log .Errorf ("syncK8sObjects err: %v for pod: %s, ns: %s" , err , podUID , podNamespace )
231
- return nil , err
232
- }
234
+ log .Errorf ("syncK8sObjects err: %v for pod: %s, ns: %s" , err , podUID , podNamespace )
235
+ return nil , err
233
236
}
234
-
235
237
}
236
238
237
239
return & csi.NodePublishVolumeResponse {}, nil
0 commit comments