Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions network.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package firecracker

import (
"context"
"fmt"
"net"
"os"
"path/filepath"
Expand Down Expand Up @@ -267,6 +268,11 @@ type CNIConfiguration struct {
// either provide the netNSPath via the Jailer config or allow the
// netns path to be autogenerated by us.
netNSPath string

// Force allows to overwrite default behavior of the pre existing network deletion
// mostly created for different types of CNI plugins which are not expecting fail on that step.
// In case if Force was set to `True` error will be still logged, but new new network will be created anyway.
Force bool
}

func (cniConf CNIConfiguration) validate() error {
Expand Down Expand Up @@ -326,13 +332,18 @@ func (cniConf CNIConfiguration) invokeCNI(ctx context.Context, logger *log.Entry
// well-behaved CNI plugins should treat this as a no-op without returning an error
// (resulting also in a nil error here).
// We can be reasonably sure any previous VM that was using this network is gone due
// to earlier validation that the VM's socket path does not already exist.
// to earlier validation that the VM's socket path does not already exists.
err = delNetworkFunc()
if err != nil {
// something actually went wrong deleting the network, return an error so we don't
// try to create a new network on top of a possibly half-deleted previous one.
return nil, errors.Wrapf(err,
"failed to delete pre-existing CNI network %+v", cniConf), cleanupFuncs
errMsg := fmt.Sprintf("failed to delete pre-existing CNI network %+v", cniConf)
// We are checking Force parameter to choose, should we fail with error
// or continue execution with just logging error
if !cniConf.Force {
// something actually went wrong deleting the network, return an error and Force wasn't used so we don't
// try to create a new network on top of a possibly half-deleted previous one.
return nil, errors.Wrap(err, errMsg), cleanupFuncs
}
logger.Error(err, errMsg)
}

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