Skip to content

kustomize build args part 1 #2870

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

Merged
merged 1 commit into from
Sep 12, 2019
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: 21 additions & 1 deletion pkg/skaffold/deploy/kustomize.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"os"
"os/exec"
"path/filepath"
"strings"

"github.com/pkg/errors"
yaml "gopkg.in/yaml.v2"
Expand Down Expand Up @@ -71,6 +72,7 @@ type KustomizeDeployer struct {
kubectl deploy.CLI
defaultRepo string
insecureRegistries map[string]bool
BuildArgs []string
}

func NewKustomizeDeployer(runCtx *runcontext.RunContext) *KustomizeDeployer {
Expand Down Expand Up @@ -248,7 +250,7 @@ func pathExistsLocally(filename string, workingDir string) (bool, os.FileMode) {
}

func (k *KustomizeDeployer) readManifests(ctx context.Context) (deploy.ManifestList, error) {
cmd := exec.CommandContext(ctx, "kustomize", "build", k.KustomizePath)
cmd := exec.CommandContext(ctx, "kustomize", buildCommandArgs(k.BuildArgs, k.KustomizePath)...)
out, err := util.RunCmdOut(cmd)
if err != nil {
return nil, errors.Wrap(err, "kustomize build")
Expand All @@ -262,3 +264,21 @@ func (k *KustomizeDeployer) readManifests(ctx context.Context) (deploy.ManifestL
manifests.Append(out)
return manifests, nil
}

func buildCommandArgs(buildArgs []string, kustomizePath string) []string {
var args []string
args = append(args, "build")

if len(buildArgs) > 0 {
for _, v := range buildArgs {
parts := strings.Split(v, " ")
args = append(args, parts...)
}
}

if len(kustomizePath) > 0 {
args = append(args, kustomizePath)
}

return args
}
65 changes: 65 additions & 0 deletions pkg/skaffold/deploy/kustomize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,3 +328,68 @@ func TestDependenciesForKustomization(t *testing.T) {
})
}
}

func TestKustomizeBuildCommandArgs(t *testing.T) {
tests := []struct {
description string
buildArgs []string
kustomizePath string
expectedArgs []string
}{
{
description: "no BuildArgs, empty KustomizePath ",
buildArgs: []string{},
kustomizePath: "",
expectedArgs: []string{"build"},
},
{
description: "One BuildArg, empty KustomizePath",
buildArgs: []string{"--foo"},
kustomizePath: "",
expectedArgs: []string{"build", "--foo"},
},
{
description: "no BuildArgs, non-empty KustomizePath",
buildArgs: []string{},
kustomizePath: "foo",
expectedArgs: []string{"build", "foo"},
},
{
description: "One BuildArg, non-empty KustomizePath",
buildArgs: []string{"--foo"},
kustomizePath: "bar",
expectedArgs: []string{"build", "--foo", "bar"},
},
{
description: "Multiple BuildArg, empty KustomizePath",
buildArgs: []string{"--foo", "--bar"},
kustomizePath: "",
expectedArgs: []string{"build", "--foo", "--bar"},
},
{
description: "Multiple BuildArg with spaces, empty KustomizePath",
buildArgs: []string{"--foo bar", "--baz"},
kustomizePath: "",
expectedArgs: []string{"build", "--foo", "bar", "--baz"},
},
{
description: "Multiple BuildArg with spaces, non-empty KustomizePath",
buildArgs: []string{"--foo bar", "--baz"},
kustomizePath: "barfoo",
expectedArgs: []string{"build", "--foo", "bar", "--baz", "barfoo"},
},
{
description: "Multiple BuildArg no spaces, non-empty KustomizePath",
buildArgs: []string{"--foo", "bar", "--baz"},
kustomizePath: "barfoo",
expectedArgs: []string{"build", "--foo", "bar", "--baz", "barfoo"},
},
}

for _, test := range tests {
testutil.Run(t, test.description, func(t *testutil.T) {
args := buildCommandArgs(test.buildArgs, test.kustomizePath)
t.CheckDeepEqual(test.expectedArgs, args)
})
}
}