Skip to content

Commit

Permalink
chore: simplify kubeconfig management (#970)
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 24, 2024
1 parent 6e0768f commit 4d72109
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
5 changes: 2 additions & 3 deletions pkg/runner/operations/command/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"os"
"os/exec"
"path/filepath"

"github.com/jmespath-community/go-jmespath/pkg/binding"
"github.com/kyverno/chainsaw/pkg/apis/v1alpha1"
Expand Down Expand Up @@ -73,7 +72,7 @@ func (o *operation) createCommand(ctx context.Context, bindings binding.Bindings
env = append(env, fmt.Sprintf("PATH=%s/bin/:%s", cwd, os.Getenv("PATH")))
var cancel context.CancelFunc
if o.cfg != nil {
f, err := os.CreateTemp(o.basePath, "chainsaw-kubeconfig-")
f, err := os.CreateTemp("", "chainsaw-kubeconfig-")
if err != nil {
return nil, nil, err
}
Expand All @@ -89,7 +88,7 @@ func (o *operation) createCommand(ctx context.Context, bindings binding.Bindings
if err := restutils.Save(o.cfg, f); err != nil {
return nil, cancel, err
}
env = append(env, fmt.Sprintf("KUBECONFIG=%s", filepath.Join(cwd, path)))
env = append(env, fmt.Sprintf("KUBECONFIG=%s", path))
}
args := environment.Expand(maps, o.command.Args...)
cmd := exec.CommandContext(ctx, o.command.Entrypoint, args...) //nolint:gosec
Expand Down
5 changes: 2 additions & 3 deletions pkg/runner/operations/script/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"os"
"os/exec"
"path/filepath"

"github.com/jmespath-community/go-jmespath/pkg/binding"
"github.com/kyverno/chainsaw/pkg/apis/v1alpha1"
Expand Down Expand Up @@ -72,7 +71,7 @@ func (o *operation) createCommand(ctx context.Context, bindings binding.Bindings
env = append(env, fmt.Sprintf("PATH=%s/bin/:%s", cwd, os.Getenv("PATH")))
var cancel context.CancelFunc
if o.cfg != nil {
f, err := os.CreateTemp(o.basePath, "chainsaw-kubeconfig-")
f, err := os.CreateTemp("", "chainsaw-kubeconfig-")
if err != nil {
return nil, nil, err
}
Expand All @@ -88,7 +87,7 @@ func (o *operation) createCommand(ctx context.Context, bindings binding.Bindings
if err := restutils.Save(o.cfg, f); err != nil {
return nil, cancel, err
}
env = append(env, fmt.Sprintf("KUBECONFIG=%s", filepath.Join(cwd, path)))
env = append(env, fmt.Sprintf("KUBECONFIG=%s", path))
}
cmd := exec.CommandContext(ctx, "sh", "-c", o.script.Content) //nolint:gosec
cmd.Env = env
Expand Down

0 comments on commit 4d72109

Please sign in to comment.