Skip to content

Commit

Permalink
pull GetCNIBinaryPath into utils package
Browse files Browse the repository at this point in the history
  • Loading branch information
steiler committed Jun 16, 2021
1 parent 71553aa commit d55245c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
18 changes: 5 additions & 13 deletions runtime/containerd/containerd.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,11 @@ import (

const (
containerdNamespace = "clab"

cniBin = "/opt/cni/bin"
cniCache = "/opt/cni/cache"

dockerRuntimeName = "containerd"
defaultTimeout = 30 * time.Second
cniCache = "/opt/cni/cache"
dockerRuntimeName = "containerd"
defaultTimeout = 30 * time.Second
)

var cniPath string

func init() {
runtime.Register(dockerRuntimeName, func() runtime.ContainerRuntime {
return &ContainerdRuntime{
Expand All @@ -51,14 +46,11 @@ func init() {

func (c *ContainerdRuntime) Init(opts ...runtime.RuntimeOption) error {
var err error
var ok bool
c.client, err = containerd.New("/run/containerd/containerd.sock")
if err != nil {
return err
}
if cniPath, ok = os.LookupEnv("CNI_BIN"); !ok {
cniPath = cniBin
}
cniPath := utils.GetCNIBinaryPath()
binaries := []string{"tuning", "bridge", "host-local"}
for _, binary := range binaries {
binary = path.Join(cniPath, binary)
Expand Down Expand Up @@ -318,7 +310,7 @@ func (c *ContainerdRuntime) CreateContainer(ctx context.Context, node *types.Nod
func cniInit(cId, ifName string, mgmtNet *types.MgmtNet) (*libcni.CNIConfig, *libcni.NetworkConfigList, *libcni.RuntimeConf, error) {
// allow overwriting cni plugin binary path via ENV var

cnic := libcni.NewCNIConfigWithCacheDir([]string{cniPath}, cniCache, nil)
cnic := libcni.NewCNIConfigWithCacheDir([]string{utils.GetCNIBinaryPath()}, cniCache, nil)

cniConfig := fmt.Sprintf(`
{
Expand Down
18 changes: 17 additions & 1 deletion utils/containers.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
package utils

import "strings"
import (
"os"
"strings"
)

const (
cniBin = "/opt/cni/bin"
)

// produces a canonical image name.
// returns the canonical image name including the tag
Expand Down Expand Up @@ -34,3 +41,12 @@ func GetCanonicalImageName(imageName string) string {

return canonicalImageName
}

func GetCNIBinaryPath() string {
var cniPath string
var ok bool
if cniPath, ok = os.LookupEnv("CNI_BIN"); !ok {
cniPath = cniBin
}
return cniPath
}

0 comments on commit d55245c

Please sign in to comment.