Skip to content

Commit

Permalink
allow runtime to be selected via CLAB_RUNTIME environment variable
Browse files Browse the repository at this point in the history
  • Loading branch information
steiler committed Jun 16, 2021
1 parent 7cb24d8 commit e0fce2d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 7 additions & 0 deletions clab/clab.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package clab
import (
"context"
"fmt"
"os"
"path"
"strings"
"sync"
Expand Down Expand Up @@ -58,6 +59,12 @@ func WithTimeout(dur time.Duration) ClabOption {

func WithRuntime(name string, d bool, dur time.Duration, gracefulShutdown bool) ClabOption {
return func(c *CLab) {
if name == "" {

This comment has been minimized.

Copy link
@hellt

hellt Jun 16, 2021

Member

This looks weird. Maybe a switch?

This comment has been minimized.

Copy link
@steiler

steiler Jun 17, 2021

Author Collaborator

That is is tiered process. Either -r is set on CLI if not validate if

		if name == "" {
        		// runtime no set via cli "-r" option
			name = os.Getenv("CLAB_RUNTIME")
			// runtime set via ENV?
			if name == "" {
				// fallback to "default" Docker runtime
				name = runtime.DockerRuntime
			}
		}

maybe

		envrt := os.Getenv("CLAB_RUNTIME")
		if name == "" && envrt != ""{
			name = envrt
		}else if name =="" && envrt ==""{
			name = runtime.DockerRuntime
		}

But I don't see that this would help much...

name = os.Getenv("CLAB_RUNTIME")
if name == "" {
name = runtime.DockerRuntime
}
}
if rInit, ok := runtime.ContainerRuntimes[name]; ok {
c.Runtime = rInit()
err := c.Runtime.Init(
Expand Down
4 changes: 1 addition & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (

log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/srl-labs/containerlab/runtime"
)

var debug bool
Expand Down Expand Up @@ -52,8 +51,7 @@ func init() {
_ = rootCmd.MarkPersistentFlagFilename("topo", "*.yaml", "*.yml")
rootCmd.PersistentFlags().StringVarP(&name, "name", "n", "", "lab name")
rootCmd.PersistentFlags().DurationVarP(&timeout, "timeout", "", 30*time.Second, "timeout for docker requests, e.g: 30s, 1m, 2m30s")
rootCmd.PersistentFlags().StringVarP(&rt, "runtime", "r", runtime.DockerRuntime, "container runtime")

rootCmd.PersistentFlags().StringVarP(&rt, "runtime", "r", "", "container runtime")
}

// returns an error if topo path is not provided
Expand Down

0 comments on commit e0fce2d

Please sign in to comment.