Skip to content

Commit

Permalink
fix: temporary kubeconfig needs to be absolute (#946)
Browse files Browse the repository at this point in the history
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
  • Loading branch information
eddycharly authored Feb 21, 2024
1 parent dd0d03f commit 7a78b70
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
7 changes: 7 additions & 0 deletions .release-notes/v0.1.6.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Release notes

Release notes for `v0.1.6`.

## 🔧 Fixes 🔧

- Fix an issue with temporary KUBECONFIG not being an absolute path
10 changes: 6 additions & 4 deletions pkg/runner/operations/command/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ func (o *operation) createCommand(ctx context.Context) (*exec.Cmd, context.Cance
args := env.Expand(map[string]string{"NAMESPACE": o.namespace}, o.command.Args...)
cmd := exec.CommandContext(ctx, o.command.Entrypoint, args...) //nolint:gosec
env := os.Environ()
if cwd, err := os.Getwd(); err != nil {
cwd, err := os.Getwd()
if err != nil {
return nil, nil, fmt.Errorf("failed to get current working directory (%w)", err)
} else {
env = append(env, fmt.Sprintf("PATH=%s/bin/:%s", cwd, os.Getenv("PATH")))
}
env = append(env, fmt.Sprintf("PATH=%s/bin/:%s", cwd, os.Getenv("PATH")))
env = append(env, fmt.Sprintf("NAMESPACE=%s", o.namespace))
if o.cfg != nil {
f, err := os.CreateTemp(o.basePath, "chainsaw-kubeconfig-")
Expand All @@ -90,7 +90,9 @@ func (o *operation) createCommand(ctx context.Context) (*exec.Cmd, context.Cance
if err := restutils.Save(o.cfg, f); err != nil {
return nil, cancel, err
}
env = append(env, fmt.Sprintf("KUBECONFIG=%s", filepath.Base(path)))
fmt.Println(f.Name())
fmt.Println(o.basePath)
env = append(env, fmt.Sprintf("KUBECONFIG=%s", filepath.Join(cwd, path)))
}
cmd.Env = env
cmd.Dir = o.basePath
Expand Down
8 changes: 4 additions & 4 deletions pkg/runner/operations/script/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ func (o *operation) createCommand(ctx context.Context) (*exec.Cmd, context.Cance
var cancel context.CancelFunc
cmd := exec.CommandContext(ctx, "sh", "-c", o.script.Content) //nolint:gosec
env := os.Environ()
if cwd, err := os.Getwd(); err != nil {
cwd, err := os.Getwd()
if err != nil {
return nil, nil, fmt.Errorf("failed to get current working directory (%w)", err)
} else {
env = append(env, fmt.Sprintf("PATH=%s/bin/:%s", cwd, os.Getenv("PATH")))
}
env = append(env, fmt.Sprintf("PATH=%s/bin/:%s", cwd, os.Getenv("PATH")))
env = append(env, fmt.Sprintf("NAMESPACE=%s", o.namespace))
if o.cfg != nil {
f, err := os.CreateTemp(o.basePath, "chainsaw-kubeconfig-")
Expand All @@ -88,7 +88,7 @@ func (o *operation) createCommand(ctx context.Context) (*exec.Cmd, context.Cance
if err := restutils.Save(o.cfg, f); err != nil {
return nil, cancel, err
}
env = append(env, fmt.Sprintf("KUBECONFIG=%s", filepath.Base(path)))
env = append(env, fmt.Sprintf("KUBECONFIG=%s", filepath.Join(cwd, path)))
}
cmd.Env = env
cmd.Dir = o.basePath
Expand Down
2 changes: 1 addition & 1 deletion testdata/e2e/examples/basic/chainsaw-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ spec:
assert:
file: configmap-assert.yaml
- script:
content: kubectl get pod -A
content: cd .. && kubectl get pod -A

0 comments on commit 7a78b70

Please sign in to comment.