@@ -15,6 +15,7 @@ package firecracker
15
15
16
16
import (
17
17
"context"
18
+ "fmt"
18
19
"net"
19
20
"os"
20
21
"path/filepath"
@@ -267,6 +268,11 @@ type CNIConfiguration struct {
267
268
// either provide the netNSPath via the Jailer config or allow the
268
269
// netns path to be autogenerated by us.
269
270
netNSPath string
271
+
272
+ // Force allows to overwrite default behavior of the pre existing network deletion
273
+ // mostly created for different types of CNI plugins which are not expecting fail on that step.
274
+ // In case if Force was set to `True` error will be still logged, but new new network will be created anyway.
275
+ Force bool
270
276
}
271
277
272
278
func (cniConf CNIConfiguration ) validate () error {
@@ -326,13 +332,18 @@ func (cniConf CNIConfiguration) invokeCNI(ctx context.Context, logger *log.Entry
326
332
// well-behaved CNI plugins should treat this as a no-op without returning an error
327
333
// (resulting also in a nil error here).
328
334
// We can be reasonably sure any previous VM that was using this network is gone due
329
- // to earlier validation that the VM's socket path does not already exist .
335
+ // to earlier validation that the VM's socket path does not already exists .
330
336
err = delNetworkFunc ()
331
337
if err != nil {
332
- // something actually went wrong deleting the network, return an error so we don't
333
- // try to create a new network on top of a possibly half-deleted previous one.
334
- return nil , errors .Wrapf (err ,
335
- "failed to delete pre-existing CNI network %+v" , cniConf ), cleanupFuncs
338
+ errMsg := fmt .Sprintf ("failed to delete pre-existing CNI network %+v" , cniConf )
339
+ // We are checking Force parameter to choose, should we fail with error
340
+ // or continue execution with just logging error
341
+ if ! cniConf .Force {
342
+ // something actually went wrong deleting the network, return an error and Force wasn't used so we don't
343
+ // try to create a new network on top of a possibly half-deleted previous one.
344
+ return nil , errors .Wrap (err , errMsg ), cleanupFuncs
345
+ }
346
+ logger .Error (err , errMsg )
336
347
}
337
348
338
349
// Append cleanup of the network list before calling AddNetworkList to handle
0 commit comments