Skip to content

Commit 79ab43e

Browse files
authored
Merge pull request #2680 from lizardruss/ENG-1731
fix: create /usr/local/bin for proxycommands if it doesn't exist in t…
2 parents 49e5f6b + e463b33 commit 79ab43e

3 files changed

Lines changed: 95 additions & 4 deletions

File tree

e2e/tests/proxycommands/proxycommands.go

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import (
44
"bytes"
55
"context"
66
"fmt"
7-
"github.com/onsi/ginkgo/v2"
87
"os"
98
"os/exec"
109
"time"
1110

11+
"github.com/onsi/ginkgo/v2"
12+
1213
"github.com/loft-sh/devspace/cmd"
1314
"github.com/loft-sh/devspace/cmd/flags"
1415
"github.com/loft-sh/devspace/e2e/framework"
@@ -95,4 +96,49 @@ var _ = DevSpaceDescribe("proxyCommands", func() {
9596
err = <-done
9697
framework.ExpectNoError(err)
9798
})
99+
100+
ginkgo.It("devspace dev should proxy commands to host machine without /usr/local/bin", func() {
101+
tempDir, err := framework.CopyToTempDir("tests/proxycommands/testdata/proxycommands-no-usr-local")
102+
framework.ExpectNoError(err)
103+
defer framework.CleanupTempDir(initialDir, tempDir)
104+
105+
ns, err := kubeClient.CreateNamespace("no-usr-local")
106+
framework.ExpectNoError(err)
107+
defer framework.ExpectDeleteNamespace(kubeClient, ns)
108+
109+
// create a new dev command and start it
110+
done := make(chan error)
111+
cancelCtx, cancel := context.WithCancel(context.Background())
112+
defer cancel()
113+
114+
go func() {
115+
defer ginkgo.GinkgoRecover()
116+
117+
devCmd := &cmd.RunPipelineCmd{
118+
GlobalFlags: &flags.GlobalFlags{
119+
NoWarn: true,
120+
Namespace: ns,
121+
},
122+
Pipeline: "dev",
123+
Ctx: cancelCtx,
124+
}
125+
126+
done <- devCmd.RunDefault(f)
127+
}()
128+
129+
// Check that the command is proxied to the host.
130+
var stdout, stderr bytes.Buffer
131+
cmd := exec.Command("helm", "version")
132+
cmd.Stdout = &stdout
133+
cmd.Stderr = &stderr
134+
err = cmd.Run()
135+
framework.ExpectNoError(err)
136+
137+
framework.ExpectRemoteFileContents("busybox", ns, "helm-version.out", stdout.String())
138+
139+
cancel()
140+
141+
err = <-done
142+
framework.ExpectNoError(err)
143+
})
98144
})
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
version: v2beta1
2+
3+
name: no-usr-local
4+
5+
vars:
6+
IMAGE: busybox
7+
8+
deployments:
9+
test:
10+
helm:
11+
chart:
12+
name: component-chart
13+
repo: https://charts.devspace.sh
14+
values:
15+
containers:
16+
- image: ${IMAGE}
17+
command: ["sleep"]
18+
args: ["infinity"]
19+
20+
dev:
21+
test:
22+
imageSelector: ${IMAGE}
23+
proxyCommands:
24+
- command: helm
25+
26+
pipelines:
27+
dev:
28+
run: |
29+
run_default_pipeline dev
30+
exec_container --image-selector ${IMAGE} -- sh -c 'helm version > helm-version.out'

helper/cmd/proxycommands/configure.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ package proxycommands
33
import (
44
"encoding/base64"
55
"fmt"
6-
"github.com/mitchellh/go-homedir"
76
"os"
87
"path/filepath"
98
"strconv"
109
"strings"
1110

11+
"github.com/mitchellh/go-homedir"
12+
1213
"github.com/loft-sh/devspace/helper/util/stderrlog"
1314
"github.com/pkg/errors"
1415
"github.com/spf13/cobra"
@@ -63,10 +64,24 @@ func (cmd *ConfigureCmd) Run(_ *cobra.Command, _ []string) error {
6364

6465
// first configure the commands
6566
for _, c := range cmd.Commands {
66-
filePath := "/usr/local/bin/" + c
67+
fileDir := "/usr/local/bin/"
68+
filePath := fileDir + c
69+
70+
_, err := os.Stat(fileDir)
71+
if err != nil {
72+
if !os.IsNotExist(err) {
73+
return fmt.Errorf("error checking for command path '%s': %v", fileDir, err)
74+
}
75+
76+
err := os.MkdirAll(fileDir, 0755)
77+
if err != nil {
78+
return fmt.Errorf("error creating command path '%s': %v", fileDir, err)
79+
}
80+
}
81+
6782
executeCommand := fmt.Sprintf(`#!/bin/sh
6883
/tmp/devspacehelper proxy-commands run %s "$@"`, c)
69-
err := os.WriteFile(filePath, []byte(executeCommand), 0777)
84+
err = os.WriteFile(filePath, []byte(executeCommand), 0777)
7085
if err != nil {
7186
return fmt.Errorf("error writing command '%s': %v", filePath, err)
7287
}

0 commit comments

Comments
 (0)