From 2e9619fd58b20f14fe9f08c80eae69249d600350 Mon Sep 17 00:00:00 2001 From: Kimmo Lehto Date: Tue, 3 Oct 2023 10:47:30 +0300 Subject: [PATCH 1/2] Remove ignite backend support Signed-off-by: Kimmo Lehto --- README.md | 1 - go.mod | 1 - go.sum | 2 - pkg/cluster/cluster.go | 85 +++++---------- pkg/cluster/formatter.go | 4 +- pkg/cluster/machine.go | 114 +++------------------ pkg/cluster/runtime_network.go | 13 --- pkg/config/cluster.go | 1 - pkg/config/machine.go | 39 ------- pkg/ignite/create.go | 112 -------------------- pkg/ignite/doc.go | 1 - pkg/ignite/ignite.go | 47 --------- pkg/ignite/inspect.go | 76 -------------- pkg/ignite/rm.go | 12 --- pkg/ignite/start.go | 14 --- pkg/ignite/stop.go | 14 --- tests/test-config-get-%image.golden.output | 3 +- tests/test-show-ubuntu18.04.golden.output | 7 +- 18 files changed, 46 insertions(+), 500 deletions(-) delete mode 100644 pkg/ignite/create.go delete mode 100644 pkg/ignite/doc.go delete mode 100644 pkg/ignite/ignite.go delete mode 100644 pkg/ignite/inspect.go delete mode 100644 pkg/ignite/rm.go delete mode 100644 pkg/ignite/start.go delete mode 100644 pkg/ignite/stop.go diff --git a/README.md b/README.md index d5ef764..f699a50 100644 --- a/README.md +++ b/README.md @@ -147,7 +147,6 @@ cluster: privateKey: cluster-key machines: - count: 3 - backend: docker spec: image: quay.io/k0sproject/bootloose-debian12 name: node%d diff --git a/go.mod b/go.mod index 673c5cd..f13e2f4 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,6 @@ module github.com/k0sproject/bootloose go 1.21.0 require ( - github.com/blang/semver v3.5.1+incompatible github.com/carlmjohnson/versioninfo v0.22.5 github.com/docker/docker v24.0.6+incompatible github.com/ghodss/yaml v1.0.0 diff --git a/go.sum b/go.sum index bd5c7d7..0b4a3c3 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,3 @@ -github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ= -github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= github.com/carlmjohnson/versioninfo v0.22.5 h1:O00sjOLUAFxYQjlN/bzYTuZiS0y6fWDQjMRvwtKgwwc= github.com/carlmjohnson/versioninfo v0.22.5/go.mod h1:QT9mph3wcVfISUKd0i9sZfVrPviHuSF+cUtLjm2WSf8= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= diff --git a/pkg/cluster/cluster.go b/pkg/cluster/cluster.go index 1fcbf84..64ac318 100644 --- a/pkg/cluster/cluster.go +++ b/pkg/cluster/cluster.go @@ -9,7 +9,6 @@ import ( "fmt" "io" "os" - "path/filepath" "regexp" "strconv" "strings" @@ -20,7 +19,6 @@ import ( "github.com/k0sproject/bootloose/pkg/config" "github.com/k0sproject/bootloose/pkg/docker" "github.com/k0sproject/bootloose/pkg/exec" - "github.com/k0sproject/bootloose/pkg/ignite" "github.com/mitchellh/go-homedir" "github.com/pkg/errors" log "github.com/sirupsen/logrus" @@ -235,55 +233,40 @@ func (c *Cluster) CreateMachine(machine *Machine, i int) error { cmd = machine.spec.Cmd } - if machine.IsIgnite() { - pubKeyPath := c.spec.Cluster.PrivateKey + ".pub" - if !filepath.IsAbs(pubKeyPath) { - wd, err := os.Getwd() - if err != nil { - return err - } - pubKeyPath = filepath.Join(wd, pubKeyPath) - } - - if _, err := ignite.Create(machine.name, machine.spec, pubKeyPath); err != nil { - return err - } - } else { - runArgs := c.createMachineRunArgs(machine, name, i) - _, err := docker.Create(machine.spec.Image, - runArgs, - []string{cmd}, - ) - if err != nil { - return err - } + runArgs := c.createMachineRunArgs(machine, name, i) + _, err = docker.Create(machine.spec.Image, + runArgs, + []string{cmd}, + ) + if err != nil { + return err + } - if len(machine.spec.Networks) > 1 { - for _, network := range machine.spec.Networks[1:] { - log.Infof("Connecting %s to the %s network...", name, network) - if network == "bridge" { - if err := docker.ConnectNetwork(name, network); err != nil { - return err - } - } else { - if err := docker.ConnectNetworkWithAlias(name, network, machine.Hostname()); err != nil { - return err - } + if len(machine.spec.Networks) > 1 { + for _, network := range machine.spec.Networks[1:] { + log.Infof("Connecting %s to the %s network...", name, network) + if network == "bridge" { + if err := docker.ConnectNetwork(name, network); err != nil { + return err + } + } else { + if err := docker.ConnectNetworkWithAlias(name, network, machine.Hostname()); err != nil { + return err } } } + } - if err := docker.Start(name); err != nil { - return err - } + if err := docker.Start(name); err != nil { + return err + } - // Initial provisioning. - if err := containerRunShell(name, initScript); err != nil { - return err - } - if err := copy(name, publicKey, "/root/.ssh/authorized_keys"); err != nil { - return err - } + // Initial provisioning. + if err := containerRunShell(name, initScript); err != nil { + return err + } + if err := copy(name, publicKey, "/root/.ssh/authorized_keys"); err != nil { + return err } return nil @@ -375,11 +358,6 @@ func (c *Cluster) DeleteMachine(machine *Machine, i int) error { return nil } - if machine.IsIgnite() { - log.Infof("Deleting machine: %s ...", name) - return ignite.Remove(machine.name) - } - if machine.IsStarted() { log.Infof("Machine %s is started, stopping and deleting machine...", name) err := docker.Kill("KILL", name) @@ -453,9 +431,6 @@ func (c *Cluster) gatherMachines() (machines []*Machine, err error) { if !m.IsCreated() { continue } - if m.IsIgnite() { - continue - } var inspect types.ContainerJSON if err := docker.InspectObject(m.name, ".", &inspect); err != nil { @@ -519,10 +494,6 @@ func (c *Cluster) startMachine(machine *Machine, i int) error { } log.Infof("Starting machine: %s ...", name) - if machine.IsIgnite() { - return ignite.Start(name) - } - // Run command while sigs.k8s.io/kind/pkg/container/docker doesn't // have a start command cmd := exec.Command( diff --git a/pkg/cluster/formatter.go b/pkg/cluster/formatter.go index 9eded96..1642d6b 100644 --- a/pkg/cluster/formatter.go +++ b/pkg/cluster/formatter.go @@ -110,7 +110,7 @@ func (TableFormatter) Format(w io.Writer, machines []*Machine) error { } table := tabwriter.NewWriter(w, 0, 0, padding, ' ', 0) - wr.writeColumns(table, []string{"NAME", "HOSTNAME", "PORTS", "IP", "IMAGE", "CMD", "STATE", "BACKEND"}) + wr.writeColumns(table, []string{"NAME", "HOSTNAME", "PORTS", "IP", "IMAGE", "CMD", "STATE"}) // we bail early here if there was an error so we don't process the below loop if wr.err != nil { return wr.err @@ -128,7 +128,7 @@ func (TableFormatter) Format(w io.Writer, machines []*Machine) error { } } ps := strings.Join(ports, ",") - wr.writeColumns(table, []string{s.Container, s.Hostname, ps, s.IP, s.Image, s.Command, s.State, s.Spec.Backend}) + wr.writeColumns(table, []string{s.Container, s.Hostname, ps, s.IP, s.Image, s.Command, s.State}) } if wr.err != nil { diff --git a/pkg/cluster/machine.go b/pkg/cluster/machine.go index 594ed48..2ad6e0a 100644 --- a/pkg/cluster/machine.go +++ b/pkg/cluster/machine.go @@ -8,15 +8,11 @@ import ( "fmt" "strconv" "strings" - "syscall" "github.com/docker/docker/api/types/network" "github.com/k0sproject/bootloose/pkg/config" "github.com/k0sproject/bootloose/pkg/docker" - "github.com/k0sproject/bootloose/pkg/exec" - "github.com/k0sproject/bootloose/pkg/ignite" "github.com/pkg/errors" - log "github.com/sirupsen/logrus" ) // Machine is a single machine. @@ -40,14 +36,6 @@ type Machine struct { // ContainerName is the name of the running container corresponding to this // Machine. func (m *Machine) ContainerName() string { - if m.IsIgnite() { - filter := fmt.Sprintf(`label=ignite.name=%s`, m.name) - cid, err := exec.ExecuteCommand("docker", "ps", "-q", "-f", filter) - if err != nil || len(cid) == 0 { - return m.name - } - return cid - } return m.name } @@ -59,10 +47,6 @@ func (m *Machine) Hostname() string { // IsCreated returns if a machine is has been created. A created machine could // either be running or stopped. func (m *Machine) IsCreated() bool { - if m.IsIgnite() { - return ignite.IsCreated(m.name) - } - res, _ := docker.Inspect(m.name, "{{.Name}}") if len(res) > 0 && len(res[0]) > 0 { return true @@ -72,10 +56,6 @@ func (m *Machine) IsCreated() bool { // IsStarted returns if a machine is currently started or not. func (m *Machine) IsStarted() bool { - if m.IsIgnite() { - return ignite.IsStarted(m.name) - } - res, _ := docker.Inspect(m.name, "{{.State.Running}}") parsed, _ := strconv.ParseBool(strings.Trim(res[0], `'`)) return parsed @@ -90,41 +70,18 @@ func (m *Machine) HostPort(containerPort int) (int, error) { var hostPort int - // Handle Ignite VMs - if m.IsIgnite() { - // Retrieve the machine details - vm, err := ignite.PopulateMachineDetails(m.name) - if err != nil { - return -1, errors.Wrap(err, "failed to populate VM details") - } - - // Find the host port for the given VM port - var found = false - for _, p := range vm.Spec.Network.Ports { - if int(p.VMPort) == containerPort { - hostPort = int(p.HostPort) - found = true - break - } - } - - if !found { - return -1, fmt.Errorf("invalid VM port queried: %d", containerPort) - } - } else { - // retrieve the specific port mapping using docker inspect - lines, err := docker.Inspect(m.ContainerName(), fmt.Sprintf("{{(index (index .NetworkSettings.Ports \"%d/tcp\") 0).HostPort}}", containerPort)) - if err != nil { - return -1, errors.Wrapf(err, "hostport: failed to inspect container: %v", lines) - } - if len(lines) != 1 { - return -1, errors.Errorf("hostport: should only be one line, got %d lines", len(lines)) - } + // retrieve the specific port mapping using docker inspect + lines, err := docker.Inspect(m.ContainerName(), fmt.Sprintf("{{(index (index .NetworkSettings.Ports \"%d/tcp\") 0).HostPort}}", containerPort)) + if err != nil { + return -1, errors.Wrapf(err, "hostport: failed to inspect container: %v", lines) + } + if len(lines) != 1 { + return -1, errors.Errorf("hostport: should only be one line, got %d lines", len(lines)) + } - port := strings.Replace(lines[0], "'", "", -1) - if hostPort, err = strconv.Atoi(port); err != nil { - return -1, errors.Wrap(err, "hostport: failed to parse string to int") - } + port := strings.Replace(lines[0], "'", "", -1) + if hostPort, err = strconv.Atoi(port); err != nil { + return -1, errors.Wrap(err, "hostport: failed to parse string to int") } if m.ports == nil { @@ -149,30 +106,6 @@ func (m *Machine) networks() ([]*RuntimeNetwork, error) { return m.runtimeNetworks, nil } -func (m *Machine) igniteStatus(s *MachineStatus) error { - vm, err := ignite.PopulateMachineDetails(m.name) - if err != nil { - return err - } - - // Set Ports - var ports []port - for _, p := range vm.Spec.Network.Ports { - ports = append(ports, port{ - Host: int(p.HostPort), - Guest: int(p.VMPort), - }) - } - s.Ports = ports - if vm.Status.IpAddresses != nil && len(vm.Status.IpAddresses) > 0 { - m.ip = vm.Status.IpAddresses[0] - } - - s.RuntimeNetworks = NewIgniteRuntimeNetwork(&vm.Status) - - return nil -} - func (m *Machine) dockerStatus(s *MachineStatus) error { var ports []port if m.IsCreated() { @@ -219,30 +152,7 @@ func (m *Machine) Status() *MachineStatus { } s.State = state - if m.IsIgnite() { - _ = m.igniteStatus(&s) - } else { - _ = m.dockerStatus(&s) - } + _ = m.dockerStatus(&s) return &s } - -// Only check for Ignite prerequisites once -var igniteChecked bool - -// IsIgnite returns if the backend is Ignite -func (m *Machine) IsIgnite() (b bool) { - b = m.spec.Backend == ignite.BackendName - - if !igniteChecked && b { - if syscall.Getuid() != 0 { - log.Fatalf("bootloose needs to run as root to use the %q backend", ignite.BackendName) - } - - ignite.CheckVersion() - igniteChecked = true - } - - return -} diff --git a/pkg/cluster/runtime_network.go b/pkg/cluster/runtime_network.go index 550cba2..872187b 100644 --- a/pkg/cluster/runtime_network.go +++ b/pkg/cluster/runtime_network.go @@ -8,7 +8,6 @@ import ( "net" "github.com/docker/docker/api/types/network" - "github.com/k0sproject/bootloose/pkg/ignite" ) const ( @@ -32,18 +31,6 @@ func NewRuntimeNetworks(networks map[string]*network.EndpointSettings) []*Runtim return rnList } -// NewIgniteRuntimeNetwork creates reports network status for the ignite backend. -func NewIgniteRuntimeNetwork(status *ignite.Status) []*RuntimeNetwork { - networks := make([]*RuntimeNetwork, 0, len(status.IpAddresses)) - for _, ip := range status.IpAddresses { - networks = append(networks, &RuntimeNetwork{ - IP: ip, - }) - } - - return networks -} - // RuntimeNetwork contains information about the network type RuntimeNetwork struct { // Name of the network diff --git a/pkg/config/cluster.go b/pkg/config/cluster.go index 2c0373a..7ffdb30 100644 --- a/pkg/config/cluster.go +++ b/pkg/config/cluster.go @@ -91,7 +91,6 @@ func DefaultConfig() Config { PortMappings: []PortMapping{ {ContainerPort: 22}, }, - Backend: "docker", }, }, }, diff --git a/pkg/config/machine.go b/pkg/config/machine.go index 0ceabdc..449f978 100644 --- a/pkg/config/machine.go +++ b/pkg/config/machine.go @@ -72,45 +72,6 @@ type Machine struct { // PublicKey is the name of the public key to upload onto the machine for root // SSH access. PublicKey string `json:"publicKey,omitempty"` - - // Backend specifies the runtime backend for this machine - Backend string `json:"backend,omitempty"` - // Ignite specifies ignite-specific options - Ignite *Ignite `json:"ignite,omitempty"` -} - -func (m *Machine) IgniteConfig() Ignite { - i := Ignite{} - if m.Ignite != nil { - i = *m.Ignite - } - if i.CPUs == 0 { - i.CPUs = 2 - } - if len(i.Memory) == 0 { - i.Memory = "1GB" - } - if len(i.DiskSize) == 0 { - i.DiskSize = "4GB" - } - if len(i.Kernel) == 0 { - i.Kernel = "weaveworks/ignite-kernel:4.19.47" - } - return i -} - -// Ignite holds the ignite-specific configuration -type Ignite struct { - // CPUs specify the number of vCPUs to use. Default: 2 - CPUs uint64 `json:"cpus,omitempty"` - // Memory specifies the amount of RAM the VM should have. Default: 1GB - Memory string `json:"memory,omitempty"` - // DiskSize specifies the amount of disk space the VM should have. Default: 4GB - DiskSize string `json:"diskSize,omitempty"` - // Kernel specifies an OCI image to use for the kernel overlay - Kernel string `json:"kernel,omitempty"` - // Files to copy to the VM - CopyFiles map[string]string `json:"copyFiles,omitempty"` } // validate checks basic rules for Machine's fields diff --git a/pkg/ignite/create.go b/pkg/ignite/create.go deleted file mode 100644 index a2d0d8b..0000000 --- a/pkg/ignite/create.go +++ /dev/null @@ -1,112 +0,0 @@ -// SPDX-FileCopyrightText: 2019 Weaveworks Ltd. -// SPDX-FileCopyrightText: 2023 bootloose authors -// SPDX-License-Identifier: Apache-2.0 - -package ignite - -import ( - "fmt" - "net" - "path/filepath" - - "github.com/k0sproject/bootloose/pkg/config" - "github.com/k0sproject/bootloose/pkg/exec" -) - -const ( - BackendName = "ignite" -) - -// This offset is incremented for each port so we avoid -// duplicate port bindings (and hopefully port collisions) -var portOffset uint16 - -// Create creates an Ignite VM using "ignite run", it doesn't return a container ID -func Create(name string, spec *config.Machine, pubKeyPath string) (id string, err error) { - runArgs := []string{ - "run", - spec.Image, - fmt.Sprintf("--name=%s", name), - fmt.Sprintf("--cpus=%d", spec.IgniteConfig().CPUs), - fmt.Sprintf("--memory=%s", spec.IgniteConfig().Memory), - fmt.Sprintf("--size=%s", spec.IgniteConfig().DiskSize), - fmt.Sprintf("--kernel-image=%s", spec.IgniteConfig().Kernel), - fmt.Sprintf("--ssh=%s", pubKeyPath), - } - - if copyFiles := spec.IgniteConfig().CopyFiles; copyFiles != nil { - runArgs = append(runArgs, setupCopyFiles(copyFiles)...) - } - - for _, mapping := range spec.PortMappings { - if mapping.HostPort == 0 { - // If not defined, set the host port to a random free ephemeral port - var err error - if mapping.HostPort, err = freePort(); err != nil { - return "", err - } - } else { - // If defined, apply an offset so all VMs won't use the same port - mapping.HostPort += portOffset - } - - runArgs = append(runArgs, fmt.Sprintf("--ports=%d:%d", int(mapping.HostPort), mapping.ContainerPort)) - } - - // Increment portOffset per-machine - portOffset++ - - _, err = exec.ExecuteCommand(execName, runArgs...) - return "", err -} - -// setupCopyFiles formats the files to copy over to Ignite flags -func setupCopyFiles(copyFiles map[string]string) []string { - ret := make([]string, 0, len(copyFiles)) - for k, v := range copyFiles { - ret = append(ret, fmt.Sprintf("--copy-files=%s:%s", toAbs(k), v)) - } - - return ret -} - -func toAbs(p string) string { - if ap, err := filepath.Abs(p); err == nil { - return ap - } - - // If Abs reports an error, just return the given path as-is - return p -} - -// IsCreated checks if the VM with the given name is created -func IsCreated(name string) bool { - return exec.Command(execName, "inspect", "vm", name).Run() == nil -} - -// IsStarted checks if the VM with the given name is running -func IsStarted(name string) bool { - vm, err := PopulateMachineDetails(name) - if err != nil { - return false - } - - return vm.Status.Running -} - -// freePort requests a free/open ephemeral port from the kernel -// Heavily inspired by https://github.com/phayes/freeport/blob/master/freeport.go -func freePort() (uint16, error) { - addr, err := net.ResolveTCPAddr("tcp", "localhost:0") - if err != nil { - return 0, err - } - - l, err := net.ListenTCP("tcp", addr) - if err != nil { - return 0, err - } - defer l.Close() - - return uint16(l.Addr().(*net.TCPAddr).Port), nil -} diff --git a/pkg/ignite/doc.go b/pkg/ignite/doc.go deleted file mode 100644 index 4bb10d8..0000000 --- a/pkg/ignite/doc.go +++ /dev/null @@ -1 +0,0 @@ -package ignite diff --git a/pkg/ignite/ignite.go b/pkg/ignite/ignite.go deleted file mode 100644 index 082d78b..0000000 --- a/pkg/ignite/ignite.go +++ /dev/null @@ -1,47 +0,0 @@ -// SPDX-FileCopyrightText: 2019 Weaveworks Ltd. -// SPDX-FileCopyrightText: 2023 bootloose authors -// SPDX-License-Identifier: Apache-2.0 - -package ignite - -import ( - "fmt" - - "github.com/blang/semver" - log "github.com/sirupsen/logrus" - "github.com/k0sproject/bootloose/pkg/exec" -) - -const execName = "ignite" - -var minVersion = semver.MustParse("0.5.2") // Require v0.5.2 or higher - -func CheckVersion() { - - lines, err := exec.CombinedOutputLines(exec.Command(execName, "version", "-o", "short")) - if err == nil && len(lines) == 0 { - err = fmt.Errorf("no output") - } - - if err != nil { - verParseFail(err) - } - - // Use ParseTolerant as Ignite's version has a leading "v" - version, err := semver.ParseTolerant(lines[0]) - if err != nil { - verParseFail(err) - } - - if minVersion.Compare(version) > 0 { - verParseFail(fmt.Errorf("minimum version is v%s, detected older v%s", minVersion, version)) - } - - if len(version.Build) > 0 { - log.Warnf("Continuing with a dirty build of Ignite (v%s), here be dragons", version) - } -} - -func verParseFail(err error) { - log.Fatalf("Failed to verify Ignite version: %v", err) -} diff --git a/pkg/ignite/inspect.go b/pkg/ignite/inspect.go deleted file mode 100644 index 145796d..0000000 --- a/pkg/ignite/inspect.go +++ /dev/null @@ -1,76 +0,0 @@ -// SPDX-FileCopyrightText: 2019 Weaveworks Ltd. -// SPDX-FileCopyrightText: 2023 bootloose authors -// SPDX-License-Identifier: Apache-2.0 - -package ignite - -import ( - "encoding/json" - "strings" - - log "github.com/sirupsen/logrus" - "github.com/k0sproject/bootloose/pkg/exec" -) - -type Metadata struct { - Name string - UID string - Created string -} - -type Port struct { - HostPort uint16 - VMPort uint16 - Protocol string -} - -type Network struct { - Ports []Port -} - -type Spec struct { - Network Network - Cpus uint - Memory string - DiskSize string -} - -type Status struct { - Running bool - StartTime string - IpAddresses []string -} - -type VM struct { - Metadata Metadata - Spec Spec - Status Status -} - -// PopulateMachineDetails returns the details of the VM identified by the given name -func PopulateMachineDetails(name string) (*VM, error) { - cmd := exec.Command(execName, "inspect", "vm", name) - lines, err := exec.CombinedOutputLines(cmd) - if err != nil { - log.Errorf("Ignite.IsStarted error: %v\n", err) - return nil, err - } - - var sb strings.Builder - for _, s := range lines { - sb.WriteString(s) - } - - return toVM([]byte(sb.String())) -} - -// toVM unmarshals the given data to a VM object -func toVM(data []byte) (*VM, error) { - obj := &VM{} - if err := json.Unmarshal(data, obj); err != nil { - log.Errorf("Ignite.toVM error: %v\n", err) - return nil, err - } - - return obj, nil -} diff --git a/pkg/ignite/rm.go b/pkg/ignite/rm.go deleted file mode 100644 index f09ff0c..0000000 --- a/pkg/ignite/rm.go +++ /dev/null @@ -1,12 +0,0 @@ -// SPDX-FileCopyrightText: 2019 Weaveworks Ltd. -// SPDX-FileCopyrightText: 2023 bootloose authors -// SPDX-License-Identifier: Apache-2.0 - -package ignite - -import "github.com/k0sproject/bootloose/pkg/exec" - -// Remove removes an Ignite VM -func Remove(name string) error { - return exec.CommandWithLogging(execName, "rm", "-f", name) -} diff --git a/pkg/ignite/start.go b/pkg/ignite/start.go deleted file mode 100644 index 5720a07..0000000 --- a/pkg/ignite/start.go +++ /dev/null @@ -1,14 +0,0 @@ -// SPDX-FileCopyrightText: 2019 Weaveworks Ltd. -// SPDX-FileCopyrightText: 2023 bootloose authors -// SPDX-License-Identifier: Apache-2.0 - -package ignite - -import ( - "github.com/k0sproject/bootloose/pkg/exec" -) - -// Start starts an Ignite VM -func Start(name string) error { - return exec.CommandWithLogging(execName, "start", name) -} diff --git a/pkg/ignite/stop.go b/pkg/ignite/stop.go deleted file mode 100644 index e650981..0000000 --- a/pkg/ignite/stop.go +++ /dev/null @@ -1,14 +0,0 @@ -// SPDX-FileCopyrightText: 2019 Weaveworks Ltd. -// SPDX-FileCopyrightText: 2023 bootloose authors -// SPDX-License-Identifier: Apache-2.0 - -package ignite - -import ( - "github.com/k0sproject/bootloose/pkg/exec" -) - -// Stop stops an Ignite VM -func Stop(name string) error { - return exec.CommandWithLogging(execName, "stop", name) -} diff --git a/tests/test-config-get-%image.golden.output b/tests/test-config-get-%image.golden.output index 06d1159..fda9128 100644 --- a/tests/test-config-get-%image.golden.output +++ b/tests/test-config-get-%image.golden.output @@ -4,6 +4,5 @@ "networks": [ "net1", "net2" - ], - "backend": "docker" + ] } diff --git a/tests/test-show-ubuntu18.04.golden.output b/tests/test-show-ubuntu18.04.golden.output index 64fe8c9..0d566ff 100644 --- a/tests/test-show-ubuntu18.04.golden.output +++ b/tests/test-show-ubuntu18.04.golden.output @@ -1,5 +1,5 @@ -NAME HOSTNAME PORTS IP IMAGE CMD STATE BACKEND -test-show-ubuntu18.04-node0 node0 0->{22 0} ubuntu18.04 Not created docker +NAME HOSTNAME PORTS IP IMAGE CMD STATE +test-show-ubuntu18.04-node0 node0 0->{22 0} ubuntu18.04 Not created { "machines": [ { @@ -12,8 +12,7 @@ test-show-ubuntu18.04-node0 node0 0->{22 0} ubuntu18.04 No { "containerPort": 22 } - ], - "backend": "docker" + ] }, "ports": [ { From 0a567a12b318a1a2a80a53ac5ba710bcaaa957bc Mon Sep 17 00:00:00 2001 From: Kimmo Lehto Date: Tue, 3 Oct 2023 12:55:39 +0300 Subject: [PATCH 2/2] Better errors when machine not started/created Signed-off-by: Kimmo Lehto --- pkg/cluster/machine.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pkg/cluster/machine.go b/pkg/cluster/machine.go index 2ad6e0a..a772464 100644 --- a/pkg/cluster/machine.go +++ b/pkg/cluster/machine.go @@ -63,6 +63,14 @@ func (m *Machine) IsStarted() bool { // HostPort returns the host port corresponding to the given container port. func (m *Machine) HostPort(containerPort int) (int, error) { + if !m.IsCreated() { + return -1, errors.Errorf("hostport: container %s is not created", m.name) + } + + if !m.IsStarted() { + return -1, errors.Errorf("hostport: container %s is not started", m.name) + } + // Use the cached version first if hostPort, ok := m.ports[containerPort]; ok { return hostPort, nil