Skip to content

Commit eec83f3

Browse files
authored
Merge pull request #161 from Zyqsempai/130-change-default-behavior-for-network-del
Added Force flag to cniConfig, added check on network remove
2 parents 43d336c + d41de9b commit eec83f3

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

network.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ package firecracker
1515

1616
import (
1717
"context"
18+
"fmt"
1819
"net"
1920
"os"
2021
"path/filepath"
@@ -267,6 +268,11 @@ type CNIConfiguration struct {
267268
// either provide the netNSPath via the Jailer config or allow the
268269
// netns path to be autogenerated by us.
269270
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
270276
}
271277

272278
func (cniConf CNIConfiguration) validate() error {
@@ -326,13 +332,18 @@ func (cniConf CNIConfiguration) invokeCNI(ctx context.Context, logger *log.Entry
326332
// well-behaved CNI plugins should treat this as a no-op without returning an error
327333
// (resulting also in a nil error here).
328334
// 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.
330336
err = delNetworkFunc()
331337
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)
336347
}
337348

338349
// Append cleanup of the network list before calling AddNetworkList to handle

0 commit comments

Comments
 (0)