diff --git a/integration/apply_test.go b/integration/apply_test.go index 87835ef37d9..e51ba3aca77 100644 --- a/integration/apply_test.go +++ b/integration/apply_test.go @@ -53,3 +53,25 @@ func TestDiagnoseRenderApply(t *testing.T) { t.CheckNotNil(depWeb) }) } + +func TestRenderApplyHelmDeployment(t *testing.T) { + testutil.Run(t, "DiagnoseRenderApply", func(t *testutil.T) { + MarkIntegrationTest(t.T, NeedsGcp) + ns, client := SetupNamespace(t.T) + + out := skaffold.Diagnose("--yaml-only").InDir("examples/helm-deployment").RunOrFailOutput(t.T) + + tmpDir := testutil.NewTempDir(t.T) + tmpDir.Chdir() + + tmpDir.Write("skaffold-diagnose.yaml", string(out)) + + out = skaffold.Render("--digest-source=local", "--add-skaffold-labels=false", "-f", "skaffold-diagnose.yaml").InNs(ns.Name).RunOrFailOutput(t.T) + tmpDir.Write("render.yaml", string(out)) + + skaffold.Apply("render.yaml", "-f", "skaffold-diagnose.yaml").InNs(ns.Name).RunOrFail(t.T) + + depApp := client.GetDeployment("skaffold-helm") + t.CheckNotNil(depApp) + }) +} diff --git a/pkg/skaffold/runner/v1/new.go b/pkg/skaffold/runner/v1/new.go index 3ead7812e4e..7426aa3540a 100644 --- a/pkg/skaffold/runner/v1/new.go +++ b/pkg/skaffold/runner/v1/new.go @@ -316,6 +316,10 @@ func validateKubectlFlags(flags *latestV1.KubectlFlags, additional latestV1.Kube } func getDeployer(runCtx *runcontext.RunContext, labels map[string]string) (deploy.Deployer, error) { + if runCtx.Opts.Apply { + return getDefaultDeployer(runCtx, labels) + } + deployerCfg := runCtx.Deployers() var deployers deploy.DeployerMux diff --git a/pkg/skaffold/runner/v1/new_test.go b/pkg/skaffold/runner/v1/new_test.go index 1163c088cc7..744edaaccdf 100644 --- a/pkg/skaffold/runner/v1/new_test.go +++ b/pkg/skaffold/runner/v1/new_test.go @@ -39,6 +39,7 @@ func TestGetDeployer(tOuter *testing.T) { cfg latestV1.DeployType helmVersion string expected deploy.Deployer + apply bool shouldErr bool }{ { @@ -88,6 +89,27 @@ func TestGetDeployer(tOuter *testing.T) { kpt.NewDeployer(&runcontext.RunContext{}, nil, &latestV1.KptDeploy{}), }, }, + { + description: "apply forces creation of kubectl deployer with kpt config", + cfg: latestV1.DeployType{KptDeploy: &latestV1.KptDeploy{}}, + apply: true, + expected: t.RequireNonNilResult(kubectl.NewDeployer(&runcontext.RunContext{ + Pipelines: runcontext.NewPipelines([]latestV1.Pipeline{{}}), + }, nil, &latestV1.KubectlDeploy{ + Flags: latestV1.KubectlFlags{}, + })).(deploy.Deployer), + }, + { + description: "apply forces creation of kubectl deployer with helm config", + cfg: latestV1.DeployType{HelmDeploy: &latestV1.HelmDeploy{}}, + helmVersion: `version.BuildInfo{Version:"v3.0.0"}`, + apply: true, + expected: t.RequireNonNilResult(kubectl.NewDeployer(&runcontext.RunContext{ + Pipelines: runcontext.NewPipelines([]latestV1.Pipeline{{}}), + }, nil, &latestV1.KubectlDeploy{ + Flags: latestV1.KubectlFlags{}, + })).(deploy.Deployer), + }, { description: "multiple deployers", cfg: latestV1.DeployType{ @@ -111,6 +133,9 @@ func TestGetDeployer(tOuter *testing.T) { } deployer, err := getDeployer(&runcontext.RunContext{ + Opts: config.SkaffoldOptions{ + Apply: test.apply, + }, Pipelines: runcontext.NewPipelines([]latestV1.Pipeline{{ Deploy: latestV1.DeployConfig{ DeployType: test.cfg,