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

Implement runtime selection, only load necessary providers #366

Merged
merged 2 commits into from
Aug 27, 2019
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
15 changes: 10 additions & 5 deletions cmd/ignite/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,25 @@ import (

"github.com/lithammer/dedent"
"github.com/sirupsen/logrus"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/weaveworks/ignite/cmd/ignite/cmd/imgcmd"
"github.com/weaveworks/ignite/cmd/ignite/cmd/kerncmd"
"github.com/weaveworks/ignite/cmd/ignite/cmd/vmcmd"
"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"
runtimeflag "github.com/weaveworks/ignite/pkg/runtime/flag"
versioncmd "github.com/weaveworks/ignite/pkg/version/cmd"
)

var logLevel = logrus.InfoLevel

// NewIgniteCommand returns the root command for ignite
func NewIgniteCommand(in io.Reader, out, err io.Writer) *cobra.Command {

imageCmd := imgcmd.NewCmdImage(os.Stdout)
kernelCmd := kerncmd.NewCmdKernel(os.Stdout)
vmCmd := vmcmd.NewCmdVM(os.Stdout)
Expand All @@ -35,8 +36,11 @@ func NewIgniteCommand(in io.Reader, out, err io.Writer) *cobra.Command {
PersistentPreRun: func(cmd *cobra.Command, args []string) {
// Set the desired logging level, now that the flags are parsed
logs.Logger.SetLevel(logLevel)
// Set the desired network plugin
providers.NetworkPlugin = providers.NetworkPlugins[network.ActivePlugin]

// Populate the providers after flags have been parsed
if err := providers.Populate(ignite.Providers); err != nil {
log.Fatal(err)
}
},
Long: dedent.Dedent(fmt.Sprintf(`
Ignite is a containerized Firecracker microVM administration tool.
Expand Down Expand Up @@ -93,7 +97,8 @@ func NewIgniteCommand(in io.Reader, out, err io.Writer) *cobra.Command {
func addGlobalFlags(fs *pflag.FlagSet) {
AddQuietFlag(fs)
logflag.LogLevelFlagVar(fs, &logLevel)
networkflag.RegisterNetworkPluginFlag(fs)
runtimeflag.RuntimeVar(fs, &providers.RuntimeName)
networkflag.NetworkPluginVar(fs, &providers.NetworkPluginName)
}

// AddQuietFlag adds the quiet flag to a flagset
Expand Down
4 changes: 2 additions & 2 deletions cmd/ignite/ignite.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ func Run() error {
// Create the directories needed for running
util.GenericCheckErr(util.CreateDirectories())

// Populate the providers
util.GenericCheckErr(providers.Populate(ignite.Providers))
// Preload necessary providers
util.GenericCheckErr(providers.Populate(ignite.Preload))

c := cmd.NewIgniteCommand(os.Stdin, os.Stdout, os.Stderr)
return c.Execute()
Expand Down
15 changes: 10 additions & 5 deletions cmd/ignited/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,33 @@ import (

"github.com/lithammer/dedent"
"github.com/sirupsen/logrus"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"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"
runtimeflag "github.com/weaveworks/ignite/pkg/runtime/flag"
versioncmd "github.com/weaveworks/ignite/pkg/version/cmd"
)

var logLevel = logrus.InfoLevel

// NewIgnitedCommand returns the root command for ignited
func NewIgnitedCommand(in io.Reader, out, err io.Writer) *cobra.Command {

root := &cobra.Command{
Use: "ignited",
Short: "ignited: run Firecracker VMs declaratively through a manifest directory or Git",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
// Set the desired logging level, now that the flags are parsed
logs.Logger.SetLevel(logLevel)
// Set the desired network plugin
providers.NetworkPlugin = providers.NetworkPlugins[network.ActivePlugin]

// Populate the providers after flags have been parsed
if err := providers.Populate(ignite.Providers); err != nil {
log.Fatal(err)
}
},
Long: dedent.Dedent(`
Ignite is a containerized Firecracker microVM administration tool.
Expand All @@ -49,5 +53,6 @@ func NewIgnitedCommand(in io.Reader, out, err io.Writer) *cobra.Command {

func addGlobalFlags(fs *pflag.FlagSet) {
logflag.LogLevelFlagVar(fs, &logLevel)
networkflag.RegisterNetworkPluginFlag(fs)
runtimeflag.RuntimeVar(fs, &providers.RuntimeName)
networkflag.NetworkPluginVar(fs, &providers.NetworkPluginName)
}
4 changes: 2 additions & 2 deletions cmd/ignited/ignited.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ func Run() error {
// Create the directories needed for running
util.GenericCheckErr(util.CreateDirectories())

// Populate the providers
util.GenericCheckErr(providers.Populate(ignited.Providers))
// Preload necessary providers
util.GenericCheckErr(providers.Populate(ignited.Preload))

c := cmd.NewIgnitedCommand(os.Stdin, os.Stdout, os.Stderr)
return c.Execute()
Expand Down
1 change: 1 addition & 0 deletions docs/cli/ignite/ignite.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Example usage:
--log-level loglevel Specify the loglevel for the program (default info)
--network-plugin plugin Network plugin to use. Available options are: [cni docker-bridge] (default docker-bridge)
-q, --quiet The quiet mode allows for machine-parsable output by printing only IDs
--runtime runtime Container runtime to use. Available options are: [docker containerd] (default docker)
```

### SEE ALSO
Expand Down
1 change: 1 addition & 0 deletions docs/cli/ignite/ignite_attach.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ ignite attach <vm> [flags]
--log-level loglevel Specify the loglevel for the program (default info)
--network-plugin plugin Network plugin to use. Available options are: [cni docker-bridge] (default docker-bridge)
-q, --quiet The quiet mode allows for machine-parsable output by printing only IDs
--runtime runtime Container runtime to use. Available options are: [docker containerd] (default docker)
```

### SEE ALSO
Expand Down
1 change: 1 addition & 0 deletions docs/cli/ignite/ignite_completion.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ ignite completion [flags]
--log-level loglevel Specify the loglevel for the program (default info)
--network-plugin plugin Network plugin to use. Available options are: [cni docker-bridge] (default docker-bridge)
-q, --quiet The quiet mode allows for machine-parsable output by printing only IDs
--runtime runtime Container runtime to use. Available options are: [docker containerd] (default docker)
```

### SEE ALSO
Expand Down
1 change: 1 addition & 0 deletions docs/cli/ignite/ignite_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ ignite create <OCI image> [flags]
--log-level loglevel Specify the loglevel for the program (default info)
--network-plugin plugin Network plugin to use. Available options are: [cni docker-bridge] (default docker-bridge)
-q, --quiet The quiet mode allows for machine-parsable output by printing only IDs
--runtime runtime Container runtime to use. Available options are: [docker containerd] (default docker)
```

### SEE ALSO
Expand Down
1 change: 1 addition & 0 deletions docs/cli/ignite/ignite_exec.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ ignite exec <vm> <command...> [flags]
--log-level loglevel Specify the loglevel for the program (default info)
--network-plugin plugin Network plugin to use. Available options are: [cni docker-bridge] (default docker-bridge)
-q, --quiet The quiet mode allows for machine-parsable output by printing only IDs
--runtime runtime Container runtime to use. Available options are: [docker containerd] (default docker)
```

### SEE ALSO
Expand Down
1 change: 1 addition & 0 deletions docs/cli/ignite/ignite_image.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ ignite image [flags]
--log-level loglevel Specify the loglevel for the program (default info)
--network-plugin plugin Network plugin to use. Available options are: [cni docker-bridge] (default docker-bridge)
-q, --quiet The quiet mode allows for machine-parsable output by printing only IDs
--runtime runtime Container runtime to use. Available options are: [docker containerd] (default docker)
```

### SEE ALSO
Expand Down
1 change: 1 addition & 0 deletions docs/cli/ignite/ignite_image_import.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ ignite image import <OCI image> [flags]
--log-level loglevel Specify the loglevel for the program (default info)
--network-plugin plugin Network plugin to use. Available options are: [cni docker-bridge] (default docker-bridge)
-q, --quiet The quiet mode allows for machine-parsable output by printing only IDs
--runtime runtime Container runtime to use. Available options are: [docker containerd] (default docker)
```

### SEE ALSO
Expand Down
1 change: 1 addition & 0 deletions docs/cli/ignite/ignite_image_ls.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ ignite image ls [flags]
--log-level loglevel Specify the loglevel for the program (default info)
--network-plugin plugin Network plugin to use. Available options are: [cni docker-bridge] (default docker-bridge)
-q, --quiet The quiet mode allows for machine-parsable output by printing only IDs
--runtime runtime Container runtime to use. Available options are: [docker containerd] (default docker)
```

### SEE ALSO
Expand Down
1 change: 1 addition & 0 deletions docs/cli/ignite/ignite_image_rm.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ ignite image rm <image>... [flags]
--log-level loglevel Specify the loglevel for the program (default info)
--network-plugin plugin Network plugin to use. Available options are: [cni docker-bridge] (default docker-bridge)
-q, --quiet The quiet mode allows for machine-parsable output by printing only IDs
--runtime runtime Container runtime to use. Available options are: [docker containerd] (default docker)
```

### SEE ALSO
Expand Down
1 change: 1 addition & 0 deletions docs/cli/ignite/ignite_inspect.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ ignite inspect <kind> <object> [flags]
--log-level loglevel Specify the loglevel for the program (default info)
--network-plugin plugin Network plugin to use. Available options are: [cni docker-bridge] (default docker-bridge)
-q, --quiet The quiet mode allows for machine-parsable output by printing only IDs
--runtime runtime Container runtime to use. Available options are: [docker containerd] (default docker)
```

### SEE ALSO
Expand Down
1 change: 1 addition & 0 deletions docs/cli/ignite/ignite_kernel.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ ignite kernel [flags]
--log-level loglevel Specify the loglevel for the program (default info)
--network-plugin plugin Network plugin to use. Available options are: [cni docker-bridge] (default docker-bridge)
-q, --quiet The quiet mode allows for machine-parsable output by printing only IDs
--runtime runtime Container runtime to use. Available options are: [docker containerd] (default docker)
```

### SEE ALSO
Expand Down
1 change: 1 addition & 0 deletions docs/cli/ignite/ignite_kernel_import.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ ignite kernel import <OCI image> [flags]
--log-level loglevel Specify the loglevel for the program (default info)
--network-plugin plugin Network plugin to use. Available options are: [cni docker-bridge] (default docker-bridge)
-q, --quiet The quiet mode allows for machine-parsable output by printing only IDs
--runtime runtime Container runtime to use. Available options are: [docker containerd] (default docker)
```

### SEE ALSO
Expand Down
1 change: 1 addition & 0 deletions docs/cli/ignite/ignite_kernel_ls.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ ignite kernel ls [flags]
--log-level loglevel Specify the loglevel for the program (default info)
--network-plugin plugin Network plugin to use. Available options are: [cni docker-bridge] (default docker-bridge)
-q, --quiet The quiet mode allows for machine-parsable output by printing only IDs
--runtime runtime Container runtime to use. Available options are: [docker containerd] (default docker)
```

### SEE ALSO
Expand Down
1 change: 1 addition & 0 deletions docs/cli/ignite/ignite_kernel_rm.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ ignite kernel rm <kernel>... [flags]
--log-level loglevel Specify the loglevel for the program (default info)
--network-plugin plugin Network plugin to use. Available options are: [cni docker-bridge] (default docker-bridge)
-q, --quiet The quiet mode allows for machine-parsable output by printing only IDs
--runtime runtime Container runtime to use. Available options are: [docker containerd] (default docker)
```

### SEE ALSO
Expand Down
1 change: 1 addition & 0 deletions docs/cli/ignite/ignite_kill.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ ignite kill <vm>... [flags]
--log-level loglevel Specify the loglevel for the program (default info)
--network-plugin plugin Network plugin to use. Available options are: [cni docker-bridge] (default docker-bridge)
-q, --quiet The quiet mode allows for machine-parsable output by printing only IDs
--runtime runtime Container runtime to use. Available options are: [docker containerd] (default docker)
```

### SEE ALSO
Expand Down
1 change: 1 addition & 0 deletions docs/cli/ignite/ignite_logs.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ ignite logs <vm> [flags]
--log-level loglevel Specify the loglevel for the program (default info)
--network-plugin plugin Network plugin to use. Available options are: [cni docker-bridge] (default docker-bridge)
-q, --quiet The quiet mode allows for machine-parsable output by printing only IDs
--runtime runtime Container runtime to use. Available options are: [docker containerd] (default docker)
```

### SEE ALSO
Expand Down
1 change: 1 addition & 0 deletions docs/cli/ignite/ignite_ps.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ ignite ps [flags]
--log-level loglevel Specify the loglevel for the program (default info)
--network-plugin plugin Network plugin to use. Available options are: [cni docker-bridge] (default docker-bridge)
-q, --quiet The quiet mode allows for machine-parsable output by printing only IDs
--runtime runtime Container runtime to use. Available options are: [docker containerd] (default docker)
```

### SEE ALSO
Expand Down
1 change: 1 addition & 0 deletions docs/cli/ignite/ignite_rm.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ ignite rm <vm>... [flags]
--log-level loglevel Specify the loglevel for the program (default info)
--network-plugin plugin Network plugin to use. Available options are: [cni docker-bridge] (default docker-bridge)
-q, --quiet The quiet mode allows for machine-parsable output by printing only IDs
--runtime runtime Container runtime to use. Available options are: [docker containerd] (default docker)
```

### SEE ALSO
Expand Down
1 change: 1 addition & 0 deletions docs/cli/ignite/ignite_rmi.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ ignite rmi <image> [flags]
--log-level loglevel Specify the loglevel for the program (default info)
--network-plugin plugin Network plugin to use. Available options are: [cni docker-bridge] (default docker-bridge)
-q, --quiet The quiet mode allows for machine-parsable output by printing only IDs
--runtime runtime Container runtime to use. Available options are: [docker containerd] (default docker)
```

### SEE ALSO
Expand Down
1 change: 1 addition & 0 deletions docs/cli/ignite/ignite_rmk.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ ignite rmk <kernel> [flags]
--log-level loglevel Specify the loglevel for the program (default info)
--network-plugin plugin Network plugin to use. Available options are: [cni docker-bridge] (default docker-bridge)
-q, --quiet The quiet mode allows for machine-parsable output by printing only IDs
--runtime runtime Container runtime to use. Available options are: [docker containerd] (default docker)
```

### SEE ALSO
Expand Down
1 change: 1 addition & 0 deletions docs/cli/ignite/ignite_run.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ ignite run <OCI image> [flags]
--log-level loglevel Specify the loglevel for the program (default info)
--network-plugin plugin Network plugin to use. Available options are: [cni docker-bridge] (default docker-bridge)
-q, --quiet The quiet mode allows for machine-parsable output by printing only IDs
--runtime runtime Container runtime to use. Available options are: [docker containerd] (default docker)
```

### SEE ALSO
Expand Down
1 change: 1 addition & 0 deletions docs/cli/ignite/ignite_ssh.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ ignite ssh <vm> [flags]
--log-level loglevel Specify the loglevel for the program (default info)
--network-plugin plugin Network plugin to use. Available options are: [cni docker-bridge] (default docker-bridge)
-q, --quiet The quiet mode allows for machine-parsable output by printing only IDs
--runtime runtime Container runtime to use. Available options are: [docker containerd] (default docker)
```

### SEE ALSO
Expand Down
1 change: 1 addition & 0 deletions docs/cli/ignite/ignite_start.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ ignite start <vm> [flags]
--log-level loglevel Specify the loglevel for the program (default info)
--network-plugin plugin Network plugin to use. Available options are: [cni docker-bridge] (default docker-bridge)
-q, --quiet The quiet mode allows for machine-parsable output by printing only IDs
--runtime runtime Container runtime to use. Available options are: [docker containerd] (default docker)
```

### SEE ALSO
Expand Down
1 change: 1 addition & 0 deletions docs/cli/ignite/ignite_stop.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ ignite stop <vm>... [flags]
--log-level loglevel Specify the loglevel for the program (default info)
--network-plugin plugin Network plugin to use. Available options are: [cni docker-bridge] (default docker-bridge)
-q, --quiet The quiet mode allows for machine-parsable output by printing only IDs
--runtime runtime Container runtime to use. Available options are: [docker containerd] (default docker)
```

### SEE ALSO
Expand Down
1 change: 1 addition & 0 deletions docs/cli/ignite/ignite_version.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ ignite version [flags]
--log-level loglevel Specify the loglevel for the program (default info)
--network-plugin plugin Network plugin to use. Available options are: [cni docker-bridge] (default docker-bridge)
-q, --quiet The quiet mode allows for machine-parsable output by printing only IDs
--runtime runtime Container runtime to use. Available options are: [docker containerd] (default docker)
```

### SEE ALSO
Expand Down
1 change: 1 addition & 0 deletions docs/cli/ignite/ignite_vm.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ ignite vm [flags]
--log-level loglevel Specify the loglevel for the program (default info)
--network-plugin plugin Network plugin to use. Available options are: [cni docker-bridge] (default docker-bridge)
-q, --quiet The quiet mode allows for machine-parsable output by printing only IDs
--runtime runtime Container runtime to use. Available options are: [docker containerd] (default docker)
```

### SEE ALSO
Expand Down
1 change: 1 addition & 0 deletions docs/cli/ignite/ignite_vm_attach.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ ignite vm attach <vm> [flags]
--log-level loglevel Specify the loglevel for the program (default info)
--network-plugin plugin Network plugin to use. Available options are: [cni docker-bridge] (default docker-bridge)
-q, --quiet The quiet mode allows for machine-parsable output by printing only IDs
--runtime runtime Container runtime to use. Available options are: [docker containerd] (default docker)
```

### SEE ALSO
Expand Down
1 change: 1 addition & 0 deletions docs/cli/ignite/ignite_vm_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ ignite vm create <OCI image> [flags]
--log-level loglevel Specify the loglevel for the program (default info)
--network-plugin plugin Network plugin to use. Available options are: [cni docker-bridge] (default docker-bridge)
-q, --quiet The quiet mode allows for machine-parsable output by printing only IDs
--runtime runtime Container runtime to use. Available options are: [docker containerd] (default docker)
```

### SEE ALSO
Expand Down
1 change: 1 addition & 0 deletions docs/cli/ignite/ignite_vm_kill.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ ignite vm kill <vm>... [flags]
--log-level loglevel Specify the loglevel for the program (default info)
--network-plugin plugin Network plugin to use. Available options are: [cni docker-bridge] (default docker-bridge)
-q, --quiet The quiet mode allows for machine-parsable output by printing only IDs
--runtime runtime Container runtime to use. Available options are: [docker containerd] (default docker)
```

### SEE ALSO
Expand Down
1 change: 1 addition & 0 deletions docs/cli/ignite/ignite_vm_logs.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ ignite vm logs <vm> [flags]
--log-level loglevel Specify the loglevel for the program (default info)
--network-plugin plugin Network plugin to use. Available options are: [cni docker-bridge] (default docker-bridge)
-q, --quiet The quiet mode allows for machine-parsable output by printing only IDs
--runtime runtime Container runtime to use. Available options are: [docker containerd] (default docker)
```

### SEE ALSO
Expand Down
1 change: 1 addition & 0 deletions docs/cli/ignite/ignite_vm_ps.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ ignite vm ps [flags]
--log-level loglevel Specify the loglevel for the program (default info)
--network-plugin plugin Network plugin to use. Available options are: [cni docker-bridge] (default docker-bridge)
-q, --quiet The quiet mode allows for machine-parsable output by printing only IDs
--runtime runtime Container runtime to use. Available options are: [docker containerd] (default docker)
```

### SEE ALSO
Expand Down
Loading