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

Enable multiple kustomizations in the kustomize deployer #3585

Merged
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
2 changes: 2 additions & 0 deletions docs/content/en/docs/pipeline-stages/deployers.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ The `kustomize` type offers the following options:

{{< schema root="KustomizeDeploy" >}}

Each entry in `paths` should point to a folder with a kustomization file.

`flags` section offers the following options:

{{< schema root="KubectlFlags" >}}
Expand Down
2 changes: 1 addition & 1 deletion docs/content/en/samples/deployers/kustomize.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ deploy:
# The deploy section above is equal to
# deploy:
# kustomize:
# path: "."
# paths: ["."]
9 changes: 6 additions & 3 deletions docs/content/en/schemas/v2alpha3.json
Original file line number Diff line number Diff line change
Expand Up @@ -1559,15 +1559,18 @@
"description": "additional flags passed to `kubectl`.",
"x-intellij-html-description": "additional flags passed to <code>kubectl</code>."
},
"path": {
"type": "string",
"paths": {
"items": {
"type": "string"
},
"type": "array",
"description": "path to Kustomization files.",
"x-intellij-html-description": "path to Kustomization files.",
"default": "."
}
},
"preferredOrder": [
"path",
"paths",
"flags",
"buildArgs"
],
Expand Down
3 changes: 2 additions & 1 deletion integration/testdata/deploy-multiple/skaffold.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ build:
context: ./kubectl
deploy:
kustomize:
path: ./kustomize
paths:
- ./kustomize

kubectl:
manifests:
Expand Down
2 changes: 1 addition & 1 deletion pkg/skaffold/deploy/deploy_mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (s stringSet) insert(strings ...string) {

// toList returns the sorted list of inserted strings.
func (s stringSet) toList() []string {
res := make([]string, 0, len(s))
var res []string
for item := range s {
res = append(res, item)
}
Expand Down
31 changes: 20 additions & 11 deletions pkg/skaffold/deploy/kustomize.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,15 @@ func (k *KustomizeDeployer) Cleanup(ctx context.Context, out io.Writer) error {

// Dependencies lists all the files that can change what needs to be deployed.
func (k *KustomizeDeployer) Dependencies() ([]string, error) {
return dependenciesForKustomization(k.KustomizePath)
deps := newStringSet()
for _, kustomizePath := range k.KustomizePaths {
depsForKustomization, err := dependenciesForKustomization(kustomizePath)
if err != nil {
return nil, err
}
deps.insert(depsForKustomization...)
}
return deps.toList(), nil
}

func (k *KustomizeDeployer) Render(ctx context.Context, out io.Writer, builds []build.Artifact, filepath string) error {
Expand Down Expand Up @@ -280,18 +288,19 @@ func pathExistsLocally(filename string, workingDir string) (bool, os.FileMode) {
}

func (k *KustomizeDeployer) readManifests(ctx context.Context) (deploy.ManifestList, error) {
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")
}
var manifests deploy.ManifestList
for _, kustomizePath := range k.KustomizePaths {
cmd := exec.CommandContext(ctx, "kustomize", buildCommandArgs(k.BuildArgs, kustomizePath)...)
out, err := util.RunCmdOut(cmd)
if err != nil {
return nil, errors.Wrap(err, "kustomize build")
}

if len(out) == 0 {
return nil, nil
if len(out) == 0 {
continue
}
manifests.Append(out)
}

var manifests deploy.ManifestList
manifests.Append(out)
return manifests, nil
}

Expand Down
Loading