Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Devspace command fails when cluster is not required #2649

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
7 changes: 7 additions & 0 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,13 @@ func (cmd *RunCmd) LoadCommandsConfig(f factory.Factory, configLoader loader.Con
client = nil
}

// verify client connectivity / authn / authz
_, err = client.KubeClient().Discovery().ServerVersion()
if err != nil {
log.Debugf("Unable to discover server version: %v", err)
client = nil
}

// Parse commands
commandsInterface, err := configLoader.LoadWithParser(context.Background(), localCache, client, loader.NewCommandsParser(), configOptions, log)
if err != nil {
Expand Down
23 changes: 22 additions & 1 deletion e2e/tests/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package command

import (
"bytes"
"github.com/onsi/ginkgo/v2"
"os"
"path/filepath"

"github.com/loft-sh/devspace/cmd"
"github.com/loft-sh/devspace/cmd/flags"
"github.com/loft-sh/devspace/e2e/framework"
"github.com/onsi/ginkgo/v2"
)

var _ = DevSpaceDescribe("command", func() {
Expand Down Expand Up @@ -66,4 +67,24 @@ var _ = DevSpaceDescribe("command", func() {
framework.ExpectNoError(err)
framework.ExpectEqual(stdout.String(), "test123 test456")
})

ginkgo.It("should run command without kubernetes cluster", func() {
tempDir, err := framework.CopyToTempDir("tests/command/testdata/command-without-cluster")
framework.ExpectNoError(err)
defer framework.CleanupTempDir(initialDir, tempDir)

defer os.Unsetenv("KUBECONFIG")
err = os.Setenv("KUBECONFIG", filepath.Join(tempDir, "config"))
framework.ExpectNoError(err)

stdout := &bytes.Buffer{}
runCmd := &cmd.RunCmd{
GlobalFlags: &flags.GlobalFlags{},
Stdout: stdout,
Stderr: stdout,
}
err = runCmd.RunRun(f, []string{"test"})
framework.ExpectNoError(err)
framework.ExpectEqual(stdout.String(), "Hello World")
})
})
16 changes: 16 additions & 0 deletions e2e/tests/command/testdata/command-without-cluster/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: v1
clusters:
- cluster:
server: https://127.0.0.1:52617
name: kind-kind
contexts:
- context:
cluster: kind-kind
user: kind-kind
name: kind-kind
current-context: kind-kind
kind: Config
preferences: {}
users:
- name: kind-kind
user: {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: v2beta1
name: command-without-cluster

commands:
test: |-
echo -n "Hello World"