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

Feature request: read from stdin as a resource #2985

Closed
torsten-liermann opened this issue Sep 15, 2020 · 7 comments
Closed

Feature request: read from stdin as a resource #2985

torsten-liermann opened this issue Sep 15, 2020 · 7 comments
Labels
help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. kind/feature Categorizes issue or PR as related to a new feature. lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. priority/awaiting-more-evidence Lowest priority. Possibly useful, but not yet enough support to actually get it done.

Comments

@torsten-liermann
Copy link

Would it be possible to have kustomize build read the resource from stdin, just like Unix pipes work?

That would simplify use cases, which at the moment include kustomize unnecessarily via wrapper scripts.

For example: helm template --post-renderer ./kustomize-wrapper.sh

kustomize-wrapper.sh:

cat> input-for-kustomize.yaml
Customize build.

It would be conceivable to have kustomize read from stdin if no resource is specified, or "-" (minus) or /dev/fd/0 for a resource path

Thanks!

@Shell32-Natsu
Copy link
Contributor

@monopole WDYT?

@Shell32-Natsu Shell32-Natsu added kind/feature Categorizes issue or PR as related to a new feature. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. priority/awaiting-more-evidence Lowest priority. Possibly useful, but not yet enough support to actually get it done. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. labels Oct 21, 2020
@monopole
Copy link
Contributor

monopole commented Oct 21, 2020

For the particular case of reading from a helm chart, we have this example. It could use some improvement - see #3128

A previously proposed interpretation of a missing resources: field was to treat it as a wildcard, e.g. a missing resources: field would be equivalent to

resources:
- *
- */*
- */*/*   (etc.)

If this implicit inclusion method were supported (i.e. if no resource manifest is specified, then read all the files in the directory tree), then kustomize would have to provide an exclusion manifest to specify the files that should not be included (like a .gitignore file). A program like kustomize must specify either inclusions or exclusions; we opted to specify inclusions (like a Makefile). Also, globbing is not supported.

The goal of these choices is to err on the side of literal declaration of the cluster's configuration. One should only have to consult a kustomization file (and the files it points to) to understand the config, and not also have to understand what was on disk at the time someone ran kustomize build.

Reading from stdin is technically possible of course. We could allow {stdin} (or something YAML friendly) in the list of resources: and use that to trigger a read from stdin.

But it breaks the notion of declaring what you use even more than globbing does. With globbing, you can maybe assume that if the kustomization file and its surroundings were maintained in source control that you have a clear declaration of configuration.

Leaving this issue open for more comment.

Would like to see #3128 done before thinking about allowing stdin, to see if that's good enough.

Meanwhile suggest try following the chartinflator example (see the unit test).

@Shell32-Natsu Shell32-Natsu added lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Oct 21, 2020
maxaudron added a commit to maxaudron/kustomize that referenced this issue Nov 28, 2020
Allow reading resources from stdin, using os.Stdin
and ioutil.ReadAll to stay platform agnostic.

This change allows specifying /dev/stdin in the "resources: {}" block to
read resources from stdin, while still processing all other resources as
normal.

This is useful for helms post render hooks

closes: kubernetes-sigs#2985
@aodinokov
Copy link
Contributor

aodinokov commented Mar 12, 2021

kustomize read from stdin if no resource is specified, or "-" (minus) or /dev/fd/0 for a resource path

Not sure it's the best option, because kustomize may call other kustomization in resources and it also may have that "-".

One more idea - to add a flag --as-transformer to kustomize build command that would read stdin and add all read yamls as like they were mentioned in kustomization.yaml resorces section located in DIR passed to kustomize build.

The underlaying kustomizations in that case won't get that resources - only the top one.
Also I think it correlates with the general idea that everything is transformer in a way that right now kustomize is rather a generator, because it can't accept and transform stdin.
But if we make it - it will be possible to put only a chain of transformers in kustomization.yaml and kustomize will apply all of them to stdin and put everything in stdout like a normal transformer... and this is great, because 'everything is transformer' even kustomize itself :) ... btw it will work more like kpt fn run

also it may allow to remove some of that separate commands in kustomize cfg, e.g.

  annotate      [Alpha] Set an annotation on Resources.
  grep          [Alpha] Search for matching Resources in a directory or from stdin

because it's possible to do them with kustomization... to be specific annotate works oob and grep may be done with patch (with target and $patch:delete).

cc: @monopole

aodinokov added a commit to aodinokov/kustomize that referenced this issue Mar 12, 2021
Adds a special flag --as-transformer
that converts kustomize behavior to something
similar to transformer because it may read
yamls from stdin, customize them and write to
stdout.

closes: kubernetes-sigs#2985
@KnVerey
Copy link
Contributor

KnVerey commented Apr 22, 2021

@monopole and I discussed this at length, and in the end we agreed that this feature should not be accepted. Although the trigger isn't CLI args or env vars in this case, it is definitely still a "build-time side effect". While it may be convenient for certain workflows built around it, facilitating dependence on build-time side-effects violates an important principle of Kustomize's approach. As @monopole commented earlier, "one should only have to consult a kustomization file (and the files it points to) to understand the config, and not also have to understand what was on disk at the time someone ran kustomize build." We will update the Eschewed Features to clarify this.

As for the Helm use case in particular, the example mentioned earlier has been replaced with / promoted to a built-in transformer, and contributions to make it better for real-world Helm use cases are appreciated.

/close

@k8s-ci-robot
Copy link
Contributor

@KnVerey: Closing this issue.

In response to this:

@monopole and I discussed this at length, and in the end we agreed that this feature should not be accepted. Although the trigger isn't CLI args or env vars in this case, it is definitely still a "build-time side effect". While it may be convenient for certain workflows built around it, facilitating dependence on build-time side-effects violates an important principle of Kustomize's approach. As @monopole commented earlier, "one should only have to consult a kustomization file (and the files it points to) to understand the config, and not also have to understand what was on disk at the time someone ran kustomize build." We will update the Eschewed Features to clarify this.

As for the Helm use case in particular, the example mentioned earlier has been replaced with / promoted to a built-in transformer, and contributions to make it better for real-world Helm use cases are appreciated.

/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@aodinokov
Copy link
Contributor

aodinokov commented Apr 22, 2021

This is a great explanation...

"one should only have to consult a kustomization file (and the files it points to) to understand the config, and not also have to understand what was on disk at the time someone ran kustomize build."

When I PoC'ed that feature with additional flag --as-transformer I had a gut feeling that it should be a different command. something like kustomize transform rather than kustomize build --as-transformer :) But this implies lots of additional use-cases. This is potentially a completely different tool that has a lot in overlap with kustomize fn run/kpt fn run :)

Thank you @KnVerey :)

wlynch added a commit to wlynch/results that referenced this issue Aug 23, 2021
This uses envsubst + kustomize to apply any overlays to resources as part of the
release process.

envsubst is used to evaluate environment variables in place before
handing off to kustomize, since kustomize does not support reading from
stdin (kubernetes-sigs/kustomize#2985).
tekton-robot pushed a commit to tektoncd/results that referenced this issue Aug 23, 2021
This uses envsubst + kustomize to apply any overlays to resources as part of the
release process.

envsubst is used to evaluate environment variables in place before
handing off to kustomize, since kustomize does not support reading from
stdin (kubernetes-sigs/kustomize#2985).
@tcurdt
Copy link

tcurdt commented May 31, 2024

Disappointing. This would be great:

cat kustomization.yaml | kustomize build - | kubectl apply -f -

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. kind/feature Categorizes issue or PR as related to a new feature. lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. priority/awaiting-more-evidence Lowest priority. Possibly useful, but not yet enough support to actually get it done.
Projects
None yet
7 participants