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

Fix VM name generation when not specified #698

Merged
merged 2 commits into from
Oct 5, 2020
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
5 changes: 5 additions & 0 deletions cmd/ignite/run/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ func (cf *CreateFlags) NewCreateOptions(args []string, fs *flag.FlagSet) (*Creat
baseVM.Spec.Image.OCI = ociRef
}

// Generate a VM name and UID if not set yet.
if err := metadata.SetNameAndUID(baseVM, providers.Client); err != nil {
return nil, err
}

// Apply the VM config on the base VM, if a VM config is given.
if len(cf.ConfigFile) != 0 {
if err := applyVMConfigFile(baseVM, cf.ConfigFile); err != nil {
Expand Down
33 changes: 33 additions & 0 deletions e2e/run_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package e2e

import (
"fmt"
"os"
"path"
"strings"
"testing"

"gotest.tools/assert"
Expand Down Expand Up @@ -114,3 +116,34 @@ func TestCurlWithContainerdAndCNI(t *testing.T) {
"cni",
)
}

func TestRunWithoutName(t *testing.T) {
assert.Assert(t, e2eHome != "", "IGNITE_E2E_HOME should be set")

igniteCmd := util.NewCommand(t, igniteBin)

labelKey := "testName"
labelVal := t.Name()

// Create VM with label to be able to identify the created VM without name.
igniteCmd.New().
With("run").
With(util.DefaultVMImage).
With("--label", fmt.Sprintf("%s=%s", labelKey, labelVal)).
Run()

// List the VM with label and get the VM name.
psCmd := igniteCmd.New().
With("ps").
With("--filter={{.ObjectMeta.Labels}}=~" + labelKey + ":" + labelVal).
With("--template={{.ObjectMeta.Name}}")
psOut, psErr := psCmd.Cmd.CombinedOutput()
assert.Check(t, psErr, fmt.Sprintf("ps: \n%q\n%s", psCmd.Cmd, psOut))
vmName := strings.TrimSpace(string(psOut))

// Delete the VM.
igniteCmd.New().
With("rm", "-f").
With(vmName).
Run()
}