Skip to content
This repository has been archived by the owner on Dec 7, 2023. It is now read-only.

Commit

Permalink
Allow provisioner override when using config file
Browse files Browse the repository at this point in the history
When using ignite configuration file, the global flags --runtime and
--network-plugin were ignored. This enables the overrides to work.

The default runtime and network-plugin name assignment is moved from
providers into NewIgniteCommand and the defaults are set only when the
values are empty after applying config files and flag overrides.
  • Loading branch information
darkowlzz committed Jul 19, 2020
1 parent 5030ccb commit c49e317
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
18 changes: 15 additions & 3 deletions cmd/ignite/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ import (
"github.com/weaveworks/ignite/pkg/constants"
"github.com/weaveworks/ignite/pkg/logs"
logflag "github.com/weaveworks/ignite/pkg/logs/flag"
"github.com/weaveworks/ignite/pkg/network"
networkflag "github.com/weaveworks/ignite/pkg/network/flag"
"github.com/weaveworks/ignite/pkg/providers"
"github.com/weaveworks/ignite/pkg/providers/ignite"
"github.com/weaveworks/ignite/pkg/runtime"
runtimeflag "github.com/weaveworks/ignite/pkg/runtime/flag"
"github.com/weaveworks/ignite/pkg/util"
versioncmd "github.com/weaveworks/ignite/pkg/version/cmd"
Expand Down Expand Up @@ -80,17 +82,27 @@ func NewIgniteCommand(in io.Reader, out, err io.Writer) *cobra.Command {
log.Fatal(err)
}

// Set providers runtime and network plugin if found in config.
if providers.ComponentConfig.Spec.Runtime != "" {
// Set providers runtime and network plugin if found in config
// and not set explicitly via flags.
if providers.ComponentConfig.Spec.Runtime != "" && providers.RuntimeName == "" {
providers.RuntimeName = providers.ComponentConfig.Spec.Runtime
}
if providers.ComponentConfig.Spec.NetworkPlugin != "" {
if providers.ComponentConfig.Spec.NetworkPlugin != "" && providers.NetworkPluginName == "" {
providers.NetworkPluginName = providers.ComponentConfig.Spec.NetworkPlugin
}
} else {
log.Debugln("Using ignite default configurations")
}

// Set the default runtime and network-plugin if it's not set by
// now.
if providers.RuntimeName == "" {
providers.RuntimeName = runtime.RuntimeContainerd
}
if providers.NetworkPluginName == "" {
providers.NetworkPluginName = network.PluginCNI
}

// Populate the providers after flags have been parsed
if err := providers.Populate(ignite.Providers); err != nil {
log.Fatal(err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/network/flag/networkflag.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ func (nf *NetworkPluginFlag) Type() string {
var _ pflag.Value = &NetworkPluginFlag{}

func NetworkPluginVar(fs *pflag.FlagSet, ptr *network.PluginName) {
fs.Var(&NetworkPluginFlag{value: ptr}, "network-plugin", fmt.Sprintf("Network plugin to use. Available options are: %v", plugins))
fs.Var(&NetworkPluginFlag{value: ptr}, "network-plugin", fmt.Sprintf("Network plugin to use. Available options are: %v (default %v)", plugins, network.PluginCNI))
}
4 changes: 2 additions & 2 deletions pkg/providers/providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import (

// NetworkPluginName binds to the global flag to select the network plugin
// The default network plugin is "cni"
var NetworkPluginName = network.PluginCNI
var NetworkPluginName network.PluginName

// NetworkPlugin provides the chosen network plugin that should be used
// This should be set after parsing user input on what network plugin to use
var NetworkPlugin network.Plugin

// RuntimeName binds to the global flag to select the container runtime
// The default runtime is "containerd"
var RuntimeName = runtime.RuntimeContainerd
var RuntimeName runtime.Name

// Runtime provides the chosen container runtime for retrieving OCI images and running VM containers
// This should be set after parsing user input on what runtime to use
Expand Down
2 changes: 1 addition & 1 deletion pkg/runtime/flag/runtimeflag.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ func (nf *RuntimeFlag) Type() string {
var _ pflag.Value = &RuntimeFlag{}

func RuntimeVar(fs *pflag.FlagSet, ptr *runtime.Name) {
fs.Var(&RuntimeFlag{value: ptr}, "runtime", fmt.Sprintf("Container runtime to use. Available options are: %v", runtimes))
fs.Var(&RuntimeFlag{value: ptr}, "runtime", fmt.Sprintf("Container runtime to use. Available options are: %v (default %v)", runtimes, runtime.RuntimeContainerd))
}

0 comments on commit c49e317

Please sign in to comment.