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

Use default deployer in 'skaffold apply' #5776

Merged
merged 2 commits into from
May 10, 2021
Merged
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
22 changes: 22 additions & 0 deletions integration/apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
4 changes: 4 additions & 0 deletions pkg/skaffold/runner/v1/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions pkg/skaffold/runner/v1/new_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func TestGetDeployer(tOuter *testing.T) {
cfg latestV1.DeployType
helmVersion string
expected deploy.Deployer
apply bool
shouldErr bool
}{
{
Expand Down Expand Up @@ -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{
Expand All @@ -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,
Expand Down