From 7940040e2fabf760c0de9b2157374f75e1d38086 Mon Sep 17 00:00:00 2001 From: Nick Kubala Date: Mon, 3 May 2021 16:23:15 -0700 Subject: [PATCH 1/2] Use default deployer in 'skaffold apply' --- examples/helm-deployment/render.yaml | 22 ++++++++++++++++++++++ integration/apply_test.go | 22 ++++++++++++++++++++++ pkg/skaffold/runner/v1/new.go | 4 ++++ pkg/skaffold/runner/v1/new_test.go | 25 +++++++++++++++++++++++++ 4 files changed, 73 insertions(+) create mode 100644 examples/helm-deployment/render.yaml diff --git a/examples/helm-deployment/render.yaml b/examples/helm-deployment/render.yaml new file mode 100644 index 00000000000..b365626b7c6 --- /dev/null +++ b/examples/helm-deployment/render.yaml @@ -0,0 +1,22 @@ +--- +# Source: skaffold-helm/templates/deployment.yaml +apiVersion: apps/v1 +kind: Deployment +metadata: + name: skaffold-helm + labels: + app: skaffold-helm +spec: + selector: + matchLabels: + app: skaffold-helm + replicas: 2 + template: + metadata: + labels: + app: skaffold-helm + spec: + containers: + - name: skaffold-helm + image: skaffold-helm:a4d4c31e69acdaffc9a008a4adfd4abbe6c8100e8c847113e7579359f108617a + diff --git a/integration/apply_test.go b/integration/apply_test.go index 87835ef37d9..602cd6d46d3 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("--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, From 9dc311ea9661068a867b32d9decd7168c1e127b5 Mon Sep 17 00:00:00 2001 From: Nick Kubala Date: Wed, 5 May 2021 11:24:54 -0700 Subject: [PATCH 2/2] remove file and fix test --- examples/helm-deployment/render.yaml | 22 ---------------------- integration/apply_test.go | 2 +- 2 files changed, 1 insertion(+), 23 deletions(-) delete mode 100644 examples/helm-deployment/render.yaml diff --git a/examples/helm-deployment/render.yaml b/examples/helm-deployment/render.yaml deleted file mode 100644 index b365626b7c6..00000000000 --- a/examples/helm-deployment/render.yaml +++ /dev/null @@ -1,22 +0,0 @@ ---- -# Source: skaffold-helm/templates/deployment.yaml -apiVersion: apps/v1 -kind: Deployment -metadata: - name: skaffold-helm - labels: - app: skaffold-helm -spec: - selector: - matchLabels: - app: skaffold-helm - replicas: 2 - template: - metadata: - labels: - app: skaffold-helm - spec: - containers: - - name: skaffold-helm - image: skaffold-helm:a4d4c31e69acdaffc9a008a4adfd4abbe6c8100e8c847113e7579359f108617a - diff --git a/integration/apply_test.go b/integration/apply_test.go index 602cd6d46d3..e51ba3aca77 100644 --- a/integration/apply_test.go +++ b/integration/apply_test.go @@ -66,7 +66,7 @@ func TestRenderApplyHelmDeployment(t *testing.T) { tmpDir.Write("skaffold-diagnose.yaml", string(out)) - out = skaffold.Render("--add-skaffold-labels=false", "-f", "skaffold-diagnose.yaml").InNs(ns.Name).RunOrFailOutput(t.T) + 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)