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

move global args to be applied to version call #4171

Closed
wants to merge 4 commits into from
Closed
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
2 changes: 1 addition & 1 deletion pkg/skaffold/deploy/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,9 @@ func (h *HelmDeployer) Render(ctx context.Context, out io.Writer, builds []build

// exec executes the helm command, writing combined stdout/stderr to the provided writer
func (h *HelmDeployer) exec(ctx context.Context, out io.Writer, useSecrets bool, args ...string) error {
args = append(args, h.Flags.Global...)
ryanhagen marked this conversation as resolved.
Show resolved Hide resolved
if args[0] != "version" {
args = append([]string{"--kube-context", h.kubeContext}, args...)
args = append(args, h.Flags.Global...)

if h.kubeConfig != "" {
args = append(args, "--kubeconfig", h.kubeConfig)
Expand Down
48 changes: 48 additions & 0 deletions pkg/skaffold/deploy/helm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,54 @@ func TestHelmCleanup(t *testing.T) {
}
}

func TestHelmDeployWithGlobalArgs(t *testing.T) {
tmpDir, err := ioutil.TempDir("", "TestHelmDeploy")
if err != nil {
t.Fatalf("tempdir: %v", err)
}

globalArgs := []string{"--tiller-namespace=test-globalarg"}

tests := []struct {
description string
commands util.Command
runContext *runcontext.RunContext
builds []build.Artifact
shouldErr bool
expectedWarnings []string
}{
{
description: "deploy success",
commands: testutil.
CmdRunWithOutput("helm version --tiller-namespace=test-globalarg", version21).
AndRun("helm --kube-context kubecontext get skaffold-helm --tiller-namespace=test-globalarg --kubeconfig kubeconfig").
AndRun("helm --kube-context kubecontext dep build examples/test --tiller-namespace=test-globalarg --kubeconfig kubeconfig").
AndRun("helm --kube-context kubecontext upgrade skaffold-helm examples/test -f skaffold-overrides.yaml --set-string image=docker.io:5000/skaffold-helm:3605e7bc17cf46e53f4d81c4cbc24e5b4c495184 --set some.key=somevalue --tiller-namespace=test-globalarg --kubeconfig kubeconfig").
AndRun("helm --kube-context kubecontext get skaffold-helm --tiller-namespace=test-globalarg --kubeconfig kubeconfig"),
runContext: makeRunContext(testDeployConfig, false),
builds: testBuilds,
},
}
for _, test := range tests {
testutil.Run(t, test.description, func(t *testutil.T) {
fakeWarner := &warnings.Collect{}
t.Override(&warnings.Printf, fakeWarner.Warnf)
t.Override(&util.OSEnviron, func() []string { return []string{"FOO=FOOBAR"} })
t.Override(&util.DefaultExecCommand, test.commands)

event.InitializeState(test.runContext.Cfg, "test")

deployer := NewHelmDeployer(test.runContext)
deployer.Flags.Global = globalArgs
deployer.pkgTmpDir = tmpDir
result := deployer.Deploy(context.Background(), ioutil.Discard, test.builds, nil)

t.CheckError(test.shouldErr, result.GetError())
t.CheckDeepEqual(test.expectedWarnings, fakeWarner.Warnings)
})
}
}

func TestParseHelmRelease(t *testing.T) {
tests := []struct {
description string
Expand Down