Skip to content

Commit

Permalink
Switch to specifying cni plugin conf directory using --cni-conf-dir flag
Browse files Browse the repository at this point in the history
Signed-off-by: Yakul Garg <2000yeshu@gmail.com>
  • Loading branch information
2000yeshu committed Mar 27, 2024
1 parent 18a03fb commit 5f05b58
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions cmd/ctr/commands/cni.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ const (

// ctr pass cni network metadata to containerd if ctr run use option of --cni
type NetworkMetaData struct {
EnableCni bool
CniConfFile string
EnableCni bool
CniConfDir string
}

func FullID(ctx context.Context, c containerd.Container) string {
Expand Down
20 changes: 10 additions & 10 deletions cmd/ctr/commands/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ var Command = cli.Command{
Usage: "Enable cni networking for the container",
},
cli.StringFlag{
Name: "cni-conf-file",
Usage: "Path to the cni conflist file",
Name: "cni-conf-dir",
Usage: "Path to the cni configuration directory",
},
}, append(platformRunFlags,
append(append(commands.SnapshotterFlags, []cli.Flag{commands.SnapshotterLabels}...),
Expand All @@ -136,12 +136,12 @@ var Command = cli.Command{
id string
ref string

rm = context.Bool("rm")
tty = context.Bool("tty")
detach = context.Bool("detach")
config = context.IsSet("config")
enableCNI = context.Bool("cni")
cniConfFile = context.String("cni-conf-file")
rm = context.Bool("rm")
tty = context.Bool("tty")
detach = context.Bool("detach")
config = context.IsSet("config")
enableCNI = context.Bool("cni")
cniConfDir = context.String("cni-conf-dir")
)

if config {
Expand Down Expand Up @@ -187,8 +187,8 @@ var Command = cli.Command{
}
var network gocni.CNI
if enableCNI {
if cniConfFile != "" {
if network, err = gocni.New(gocni.WithConfFile(cniConfFile)); err != nil {
if cniConfDir != "" {
if network, err = gocni.New(gocni.WithDefaultConf, gocni.WithPluginConfDir(cniConfDir)); err != nil {
return err
}
} else if network, err = gocni.New(gocni.WithDefaultConf); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions cmd/ctr/commands/run/run_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,8 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli

if context.Bool("cni") {
cniMeta := &commands.NetworkMetaData{EnableCni: true}
if cniConfFile := context.String("cni-conf-file"); cniConfFile != "" {
cniMeta.CniConfFile = cniConfFile
if cniConfDir := context.String("cni-conf-dir"); cniConfDir != "" {
cniMeta.CniConfDir = cniConfDir
}
cOpts = append(cOpts, containerd.WithContainerExtension(commands.CtrCniMetadataExtension, cniMeta))
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/ctr/commands/tasks/kill.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ func RemoveCniNetworkIfExist(ctx context.Context, container containerd.Container

var network gocni.CNI
if networkMetaData.EnableCni {
if networkMetaData.CniConfFile != "" {
if network, err = gocni.New(gocni.WithConfFile(networkMetaData.CniConfFile)); err != nil {
if networkMetaData.CniConfDir != "" {
if network, err = gocni.New(gocni.WithDefaultConf, gocni.WithPluginConfDir(networkMetaData.CniConfDir)); err != nil {
return err
}
} else {
Expand Down

0 comments on commit 5f05b58

Please sign in to comment.