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

Commit

Permalink
Merge pull request #669 from darkowlzz/non-global-providers
Browse files Browse the repository at this point in the history
  • Loading branch information
stealthybox committed Sep 9, 2020
2 parents 9560a71 + c77052e commit 6037e0f
Show file tree
Hide file tree
Showing 55 changed files with 384 additions and 216 deletions.
2 changes: 1 addition & 1 deletion cmd/ignite-spawn/ignite-spawn.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,6 @@ func patchStopped(vm *api.VM) error {
vm.status.startTime = nil
*/

patch := []byte(`{"status":{"running":false,"ipAddresses":null,"runtime":null,"startTime":null}}`)
patch := []byte(`{"status":{"running":false,"network":null,"runtime":null,"startTime":null}}`)
return patchutil.NewPatcher(scheme.Serializer).ApplyOnFile(constants.IGNITE_SPAWN_VM_FILE_PATH, patch, vm.GroupVersionKind())
}
10 changes: 10 additions & 0 deletions cmd/ignite/cmd/imgcmd/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ import (

"github.com/lithammer/dedent"
"github.com/spf13/cobra"
"github.com/spf13/pflag"

"github.com/weaveworks/ignite/cmd/ignite/cmd/cmdutil"
"github.com/weaveworks/ignite/cmd/ignite/run"
"github.com/weaveworks/ignite/pkg/providers"
runtimeflag "github.com/weaveworks/ignite/pkg/runtime/flag"
)

// NewCmdImport imports a new VM image
Expand All @@ -27,5 +31,11 @@ func NewCmdImport(out io.Writer) *cobra.Command {
}())
},
}

addImportFlags(cmd.Flags())
return cmd
}

func addImportFlags(fs *pflag.FlagSet) {
runtimeflag.RuntimeVar(fs, &providers.RuntimeName)
}
10 changes: 10 additions & 0 deletions cmd/ignite/cmd/kerncmd/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ import (

"github.com/lithammer/dedent"
"github.com/spf13/cobra"
"github.com/spf13/pflag"

"github.com/weaveworks/ignite/cmd/ignite/cmd/cmdutil"
"github.com/weaveworks/ignite/cmd/ignite/run"
"github.com/weaveworks/ignite/pkg/providers"
runtimeflag "github.com/weaveworks/ignite/pkg/runtime/flag"
)

// NewCmdImport imports a new kernel image
Expand All @@ -27,5 +31,11 @@ func NewCmdImport(out io.Writer) *cobra.Command {
}())
},
}

addImportFlags(cmd.Flags())
return cmd
}

func addImportFlags(fs *pflag.FlagSet) {
runtimeflag.RuntimeVar(fs, &providers.RuntimeName)
}
4 changes: 0 additions & 4 deletions cmd/ignite/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ import (
"github.com/weaveworks/ignite/pkg/config"
"github.com/weaveworks/ignite/pkg/logs"
logflag "github.com/weaveworks/ignite/pkg/logs/flag"
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"
"github.com/weaveworks/ignite/pkg/util"
versioncmd "github.com/weaveworks/ignite/pkg/version/cmd"
)
Expand Down Expand Up @@ -133,8 +131,6 @@ func isNonRootCommand(cmd string, parentCmd string) bool {
func addGlobalFlags(fs *pflag.FlagSet) {
AddQuietFlag(fs)
logflag.LogLevelFlagVar(fs, &logLevel)
runtimeflag.RuntimeVar(fs, &providers.RuntimeName)
networkflag.NetworkPluginVar(fs, &providers.NetworkPluginName)
fs.StringVar(&configPath, "ignite-config", "", "Ignite configuration path; refer to the 'Ignite Configuration' docs for more details")
}

Expand Down
7 changes: 7 additions & 0 deletions cmd/ignite/cmd/vmcmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ import (
"github.com/lithammer/dedent"
"github.com/spf13/cobra"
"github.com/spf13/pflag"

"github.com/weaveworks/ignite/cmd/ignite/cmd/cmdutil"
"github.com/weaveworks/ignite/cmd/ignite/run"
networkflag "github.com/weaveworks/ignite/pkg/network/flag"
"github.com/weaveworks/ignite/pkg/providers"
runtimeflag "github.com/weaveworks/ignite/pkg/runtime/flag"
"github.com/weaveworks/ignite/pkg/version"
)

Expand Down Expand Up @@ -80,4 +84,7 @@ func addCreateFlags(fs *pflag.FlagSet, cf *run.CreateFlags) {
cmdutil.OCIImageRefVar(fs, &cf.VM.Spec.Sandbox.OCI, "sandbox-image", "Specify an OCI image for the VM sandbox")
cmdutil.SSHVar(fs, &cf.SSH)
cmdutil.VolumeVarP(fs, &cf.VM.Spec.Storage, "volumes", "v", "Expose block devices from the host inside the VM")

runtimeflag.RuntimeVar(fs, &providers.RuntimeName)
networkflag.NetworkPluginVar(fs, &providers.NetworkPluginName)
}
10 changes: 10 additions & 0 deletions cmd/ignite/cmd/vmcmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import (
"github.com/spf13/pflag"
"github.com/weaveworks/ignite/cmd/ignite/cmd/cmdutil"
"github.com/weaveworks/ignite/cmd/ignite/run"
networkflag "github.com/weaveworks/ignite/pkg/network/flag"
"github.com/weaveworks/ignite/pkg/providers"
runtimeflag "github.com/weaveworks/ignite/pkg/runtime/flag"
)

// NewCmdStart starts a VM
Expand Down Expand Up @@ -36,6 +39,13 @@ func NewCmdStart(out io.Writer) *cobra.Command {
}

addStartFlags(cmd.Flags(), sf)

// NOTE: Since the run command combines the create and start command flags,
// to avoid redefining runtime and network flag in run command, they are
// defined separately here.
runtimeflag.RuntimeVar(cmd.Flags(), &providers.RuntimeName)
networkflag.NetworkPluginVar(cmd.Flags(), &providers.NetworkPluginName)

return cmd
}

Expand Down
6 changes: 6 additions & 0 deletions cmd/ignite/run/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"

api "github.com/weaveworks/ignite/pkg/apis/ignite"
"github.com/weaveworks/ignite/pkg/config"
"github.com/weaveworks/ignite/pkg/providers"
"github.com/weaveworks/ignite/pkg/util"
)
Expand All @@ -27,6 +28,11 @@ func Attach(ao *AttachOptions) error {
return fmt.Errorf("VM %q is not running", ao.vm.GetUID())
}

// Set the runtime and network-plugin providers from the VM status.
if err := config.SetAndPopulateProviders(ao.vm.Status.Runtime.Name, ao.vm.Status.Network.Plugin); err != nil {
return err
}

// Print the ID before attaching
fmt.Println(ao.vm.GetUID())

Expand Down
10 changes: 10 additions & 0 deletions cmd/ignite/run/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/weaveworks/ignite/pkg/apis/ignite/scheme"
"github.com/weaveworks/ignite/pkg/apis/ignite/validation"
meta "github.com/weaveworks/ignite/pkg/apis/meta/v1alpha1"
"github.com/weaveworks/ignite/pkg/config"
"github.com/weaveworks/ignite/pkg/dmlegacy"
"github.com/weaveworks/ignite/pkg/metadata"
"github.com/weaveworks/ignite/pkg/operations"
Expand Down Expand Up @@ -57,6 +58,15 @@ func (cf *CreateFlags) NewCreateOptions(args []string, fs *flag.FlagSet) (*Creat
baseVM.Spec = providers.ComponentConfig.Spec.VMDefaults
}

// Set the runtime and network-plugin on the VM. This overrides the global
// config.
baseVM.Status.Runtime.Name = providers.RuntimeName
baseVM.Status.Network.Plugin = providers.NetworkPluginName
// Populate the runtime and network-plugin providers.
if err := config.SetAndPopulateProviders(providers.RuntimeName, providers.NetworkPluginName); err != nil {
return nil, err
}

// Set the passed image argument on the new VM spec.
// Image is necessary while serializing the VM spec.
if len(args) == 1 {
Expand Down
11 changes: 11 additions & 0 deletions cmd/ignite/run/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@ package run
import (
api "github.com/weaveworks/ignite/pkg/apis/ignite"
meta "github.com/weaveworks/ignite/pkg/apis/meta/v1alpha1"
"github.com/weaveworks/ignite/pkg/config"
"github.com/weaveworks/ignite/pkg/metadata"
"github.com/weaveworks/ignite/pkg/operations"
"github.com/weaveworks/ignite/pkg/providers"
"github.com/weaveworks/ignite/pkg/util"
)

func ImportImage(source string) (image *api.Image, err error) {
// Populate the runtime provider.
if err := config.SetAndPopulateProviders(providers.RuntimeName, providers.NetworkPluginName); err != nil {
return nil, err
}

ociRef, err := meta.NewOCIImageRef(source)
if err != nil {
return
Expand All @@ -27,6 +33,11 @@ func ImportImage(source string) (image *api.Image, err error) {
}

func ImportKernel(source string) (kernel *api.Kernel, err error) {
// Populate the runtime provider.
if err := config.SetAndPopulateProviders(providers.RuntimeName, providers.NetworkPluginName); err != nil {
return nil, err
}

ociRef, err := meta.NewOCIImageRef(source)
if err != nil {
return
Expand Down
6 changes: 6 additions & 0 deletions cmd/ignite/run/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io/ioutil"

api "github.com/weaveworks/ignite/pkg/apis/ignite"
"github.com/weaveworks/ignite/pkg/config"
"github.com/weaveworks/ignite/pkg/providers"
"github.com/weaveworks/ignite/pkg/util"
)
Expand All @@ -25,6 +26,11 @@ func Logs(lo *LogsOptions) error {
return fmt.Errorf("VM %q is not running", lo.vm.GetUID())
}

// Set the runtime and network-plugin providers from the VM status.
if err := config.SetAndPopulateProviders(lo.vm.Status.Runtime.Name, lo.vm.Status.Network.Plugin); err != nil {
return err
}

// Fetch the VM logs
rc, err := providers.Runtime.ContainerLogs(util.NewPrefixer().Prefix(lo.vm.GetUID()))
if err != nil {
Expand Down
9 changes: 9 additions & 0 deletions cmd/ignite/run/rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

api "github.com/weaveworks/ignite/pkg/apis/ignite"
"github.com/weaveworks/ignite/pkg/apis/ignite/scheme"
"github.com/weaveworks/ignite/pkg/config"
"github.com/weaveworks/ignite/pkg/operations"
"github.com/weaveworks/ignite/pkg/providers"
)
Expand Down Expand Up @@ -60,6 +61,14 @@ func Rm(ro *RmOptions) error {
return fmt.Errorf("%s is running", vm.GetUID())
}

// Runtime and network info are present only when the VM is running.
if vm.Running() {
// Set the runtime and network-plugin providers from the VM status.
if err := config.SetAndPopulateProviders(vm.Status.Runtime.Name, vm.Status.Network.Plugin); err != nil {
return err
}
}

// This will first kill the VM container, and then remove it
if err := operations.DeleteVM(providers.Client, vm); err != nil {
return err
Expand Down
13 changes: 13 additions & 0 deletions cmd/ignite/run/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import (

log "github.com/sirupsen/logrus"
"github.com/weaveworks/ignite/pkg/apis/ignite"
"github.com/weaveworks/ignite/pkg/config"
"github.com/weaveworks/ignite/pkg/constants"
"github.com/weaveworks/ignite/pkg/operations"
"github.com/weaveworks/ignite/pkg/preflight/checkers"
"github.com/weaveworks/ignite/pkg/providers"
"github.com/weaveworks/ignite/pkg/util"
"golang.org/x/crypto/ssh"
"k8s.io/apimachinery/pkg/util/sets"
Expand Down Expand Up @@ -45,6 +47,17 @@ func Start(so *StartOptions) error {
return fmt.Errorf("VM %q is already running", so.vm.GetUID())
}

// In case the runtime and network-plugin is specified explicitly at start,
// set the runtime and network-plugin on the VM. This overrides the global
// config and config on the VM object, if any.
so.vm.Status.Runtime.Name = providers.RuntimeName
so.vm.Status.Network.Plugin = providers.NetworkPluginName

// Set the runtime and network-plugin providers from the VM status.
if err := config.SetAndPopulateProviders(so.vm.Status.Runtime.Name, so.vm.Status.Network.Plugin); err != nil {
return err
}

ignoredPreflightErrors := sets.NewString(util.ToLower(so.StartFlags.IgnoredPreflightErrors)...)
if err := checkers.StartCmdChecks(so.vm, ignoredPreflightErrors); err != nil {
return err
Expand Down
6 changes: 6 additions & 0 deletions cmd/ignite/run/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package run

import (
api "github.com/weaveworks/ignite/pkg/apis/ignite"
"github.com/weaveworks/ignite/pkg/config"
"github.com/weaveworks/ignite/pkg/operations"
)

Expand All @@ -22,6 +23,11 @@ func (sf *StopFlags) NewStopOptions(vmMatches []string) (so *StopOptions, err er

func Stop(so *StopOptions) error {
for _, vm := range so.vms {
// Set the runtime and network-plugin providers from the VM status.
if err := config.SetAndPopulateProviders(vm.Status.Runtime.Name, vm.Status.Network.Plugin); err != nil {
return err
}

// Stop the VM, and optionally kill it
if err := operations.StopVM(vm, so.Kill, false); err != nil {
return err
Expand Down
10 changes: 4 additions & 6 deletions docs/cli/ignite/ignite.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,10 @@ Example usage:
### Options

```
-h, --help help for ignite
--ignite-config string Ignite configuration path; refer to the 'Ignite Configuration' docs for more details
--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 cni)
-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 containerd)
-h, --help help for ignite
--ignite-config string Ignite configuration path; refer to the 'Ignite Configuration' docs for more details
--log-level loglevel Specify the loglevel for the program (default info)
-q, --quiet The quiet mode allows for machine-parsable output by printing only IDs
```

### SEE ALSO
Expand Down
8 changes: 3 additions & 5 deletions docs/cli/ignite/ignite_attach.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@ ignite attach <vm> [flags]
### Options inherited from parent commands

```
--ignite-config string Ignite configuration path; refer to the 'Ignite Configuration' docs for more details
--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 cni)
-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 containerd)
--ignite-config string Ignite configuration path; refer to the 'Ignite Configuration' docs for more details
--log-level loglevel Specify the loglevel for the program (default info)
-q, --quiet The quiet mode allows for machine-parsable output by printing only IDs
```

### SEE ALSO
Expand Down
8 changes: 3 additions & 5 deletions docs/cli/ignite/ignite_completion.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,9 @@ ignite completion [flags]
### Options inherited from parent commands

```
--ignite-config string Ignite configuration path; refer to the 'Ignite Configuration' docs for more details
--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 cni)
-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 containerd)
--ignite-config string Ignite configuration path; refer to the 'Ignite Configuration' docs for more details
--log-level loglevel Specify the loglevel for the program (default info)
-q, --quiet The quiet mode allows for machine-parsable output by printing only IDs
```

### SEE ALSO
Expand Down
8 changes: 3 additions & 5 deletions docs/cli/ignite/ignite_cp.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,9 @@ ignite cp <source> <dest> [flags]
### Options inherited from parent commands

```
--ignite-config string Ignite configuration path; refer to the 'Ignite Configuration' docs for more details
--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 cni)
-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 containerd)
--ignite-config string Ignite configuration path; refer to the 'Ignite Configuration' docs for more details
--log-level loglevel Specify the loglevel for the program (default info)
-q, --quiet The quiet mode allows for machine-parsable output by printing only IDs
```

### SEE ALSO
Expand Down
10 changes: 5 additions & 5 deletions docs/cli/ignite/ignite_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ ignite create <OCI image> [flags]
-l, --label stringArray Set a label (foo=bar)
--memory size Amount of RAM to allocate for the VM (default 512.0 MB)
-n, --name string Specify the name
--network-plugin plugin Network plugin to use. Available options are: [cni docker-bridge] (default cni)
-p, --ports strings Map host ports to VM ports
--require-name Require VM name to be passed, no name generation
--runtime runtime Container runtime to use. Available options are: [docker containerd] (default containerd)
--sandbox-image oci-image Specify an OCI image for the VM sandbox (default weaveworks/ignite:dev)
-s, --size size VM filesystem size, for example 5GB or 2048MB (default 4.0 GB)
--ssh[=<path>] Enable SSH for the VM. If <path> is given, it will be imported as the public key. If just '--ssh' is specified, a new keypair will be generated. (default is unset, which disables SSH access to the VM)
Expand All @@ -54,11 +56,9 @@ ignite create <OCI image> [flags]
### Options inherited from parent commands

```
--ignite-config string Ignite configuration path; refer to the 'Ignite Configuration' docs for more details
--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 cni)
-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 containerd)
--ignite-config string Ignite configuration path; refer to the 'Ignite Configuration' docs for more details
--log-level loglevel Specify the loglevel for the program (default info)
-q, --quiet The quiet mode allows for machine-parsable output by printing only IDs
```

### SEE ALSO
Expand Down
8 changes: 3 additions & 5 deletions docs/cli/ignite/ignite_exec.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,9 @@ ignite exec <vm> <command...> [flags]
### Options inherited from parent commands

```
--ignite-config string Ignite configuration path; refer to the 'Ignite Configuration' docs for more details
--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 cni)
-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 containerd)
--ignite-config string Ignite configuration path; refer to the 'Ignite Configuration' docs for more details
--log-level loglevel Specify the loglevel for the program (default info)
-q, --quiet The quiet mode allows for machine-parsable output by printing only IDs
```

### SEE ALSO
Expand Down
Loading

0 comments on commit 6037e0f

Please sign in to comment.