From 4d72109a7c257d14e6813346f8d292ffd739a593 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charles-Edouard=20Br=C3=A9t=C3=A9ch=C3=A9?= Date: Sat, 24 Feb 2024 22:18:10 +0100 Subject: [PATCH] chore: simplify kubeconfig management (#970) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Charles-Edouard Brétéché --- pkg/runner/operations/command/operation.go | 5 ++--- pkg/runner/operations/script/operation.go | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/pkg/runner/operations/command/operation.go b/pkg/runner/operations/command/operation.go index 226959077..71173b3d7 100644 --- a/pkg/runner/operations/command/operation.go +++ b/pkg/runner/operations/command/operation.go @@ -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" @@ -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 } @@ -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 diff --git a/pkg/runner/operations/script/operation.go b/pkg/runner/operations/script/operation.go index ab25d0448..f5e5167df 100644 --- a/pkg/runner/operations/script/operation.go +++ b/pkg/runner/operations/script/operation.go @@ -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" @@ -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 } @@ -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