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

Produce individual yaml files instead of a single one #897

Closed
yrobla opened this issue Mar 20, 2019 · 7 comments
Closed

Produce individual yaml files instead of a single one #897

yrobla opened this issue Mar 20, 2019 · 7 comments

Comments

@yrobla
Copy link

yrobla commented Mar 20, 2019

For our workflow, it would be needed to have the ability of producing the kustomize output into individual files, instead of just merging all the manifests together. So what we will need is that kustomize will take the initial list of files passed as resources, and composed the output into same matching files, having the ability to write those into a directory.
For example:
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- file_01.yaml
- file_02.yaml
kustomize build -o target_directory will produce:

  • target_directory/file_01.yaml
  • target_directory/file_02.yaml
@marcindulak
Copy link

This feature would be useful when rolling up kustomize gradually, in order to replace the old-style (sed, etc.) automation around the yaml files.

@monopole
Copy link
Contributor

monopole commented Mar 28, 2019

This is easy in the simple case you describe (which assumes a one resource per file input), but trickier in the cases of multi-layer overlays with multi- or remote bases, etc., where any file could contain N resources. Further, the direction we are going includes more resource generators - more resources that didn't start from a file artifact.

The contribution in #929 is appreciated, but it touches lots of code, handles only a simple case and doesn't handle n resources from one file, directory trees with colliding file names, and it looks like generated objects end up in a file with an empty string name.

There's no hierarchy in a k8s cluster (other than namespaces). The resources are all flat, and don't care that they came from some directory trees of from file blobs with n resources.

They do, however, have unique group-version-kind-names. So if you're OK with not trying to retain any remnant of the original dir hierarchy, and could handle file names generated from GVKN, this gets lots simpler, e.g.

target_directory/
  v1_deployment_frontend.yaml
  v1_deployment_backend.yaml
  v1_configmap_a-somehash.yaml
  v1_configmap_b-somehash.yaml

Would that work for your use case?

@monopole
Copy link
Contributor

monopole commented Apr 8, 2019

Please reopen if you'd like to clarify this.

@monopole monopole closed this as completed Apr 8, 2019
@yrobla
Copy link
Author

yrobla commented Apr 9, 2019

I need to reproduce an exact file layout as it is needed for our purposes.

@kksudo
Copy link

kksudo commented Dec 18, 2019

Can we separate with kustomize few resources from a one file to different files by kind, like helm style ?
From this one file install.yaml

apiVersion: v1
kind: ConfigMap
metadata:
  name: etc-config-1-files
  namespace: kube-system
data:
  readme: |
    Templates in this folder are packaged with an operator and available via 'useTemplate'

---
apiVersion: v1
kind: ConfigMap
metadata:
  name: etc-config-2-files
  namespace: kube-system
data:
  readme: |
    Templates in this folder are packaged with an operator and available via 'useTemplate'

---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: example-sa
  namespace: kube-system

To generate two files, like cmap.yaml and sa.yaml
cmap.yaml:

apiVersion: v1
kind: ConfigMap
metadata:
  name: etc-config-1-files
  namespace: kube-system
data:
  readme: |
    Templates in this folder are packaged with an operator and available via 'useTemplate'

---
apiVersion: v1
kind: ConfigMap
metadata:
  name: etc-config-2-files
  namespace: kube-system
data:
  readme: |
    Templates in this folder are packaged with an operator and available via 'useTemplate'

sa.yaml:

apiVersion: v1
kind: ServiceAccount
metadata:
  name: example-sa
  namespace: kube-system

@BlueEye0609
Copy link

It seems we still can only use kustomize build to create one single file which contains all merged manifests. However, how can we seperate the results which was the question?

@t-eckert
Copy link

Dropping by to share my solution to this. You can use yq to split the YAML into multiple files. I wrote up how I did this: Split up Kustomize Output with yq. Hope that helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants