@@ -136,13 +136,15 @@ func (v *pvc) inContainer(ctx context.Context, fn containerCb) (interface{}, err
136
136
if err != nil {
137
137
return nil , err
138
138
}
139
+ cleanup = func () {
140
+ // Use a background context to ensure deletion happens even if context was cancelled.
141
+ activity .Record (ctx , "Deleted temporary pod %v: %v" , tempPod , tempPod .delete (context .Background ()))
142
+ }
139
143
if err := tempPod .waitOnCreation (ctx ); err != nil {
144
+ cleanup ()
140
145
return nil , err
141
146
}
142
147
execContainer .pod = tempPod .pod
143
- cleanup = func () {
144
- activity .Record (ctx , "Deleted temporary pod %v: %v" , tempPod , tempPod .delete (ctx ))
145
- }
146
148
} else {
147
149
mount := v .getMountInfo (mountingPod , volumeName )
148
150
execContainer .pod = mount .pod
@@ -168,15 +170,18 @@ func (v *pvc) exec(ctx context.Context, buildCmd cmdBuilder, stdin io.Reader) ([
168
170
streamOpts := remotecommand.StreamOptions {Stdout : & stdout , Stderr : & stderr , Stdin : stdin }
169
171
executor , err := c .newExecutor (ctx , cmd [0 ], cmd [1 :], streamOpts )
170
172
if err != nil {
171
- return [] byte {} , err
173
+ return nil , err
172
174
}
173
175
174
176
err = executor .Stream ()
175
177
activity .Record (ctx , "stdout: %v" , stdout .String ())
176
178
activity .Record (ctx , "stderr: %v" , stderr .String ())
177
179
return stdout .Bytes (), err
178
180
})
179
- return obj .([]byte ), err
181
+ if err != nil {
182
+ return nil , err
183
+ }
184
+ return obj .([]byte ), nil
180
185
}
181
186
182
187
func (v * pvc ) VolumeList (ctx context.Context , path string ) (volume.DirMap , error ) {
@@ -226,7 +231,10 @@ func (v *pvc) VolumeStream(ctx context.Context, path string) (io.ReadCloser, err
226
231
cleanup ()
227
232
}}, nil
228
233
})
229
- return obj .(io.ReadCloser ), err
234
+ if err != nil {
235
+ return nil , err
236
+ }
237
+ return obj .(io.ReadCloser ), nil
230
238
}
231
239
232
240
func (v * pvc ) VolumeWrite (ctx context.Context , path string , b []byte , _ os.FileMode ) error {
0 commit comments