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

Allow provider override when using config file #647

Merged
Merged
Show file tree
Hide file tree
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
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))
}