1

I need an equivalent of Unix shell script:

#!/bin/bash
# save incoming YAML to file
cat > all.yaml
# modify the YAML with kustomize
kustomize build . && rm all.yaml

but for Windows. I end up with:

@echo off
type > all.yaml
kustomize build .

but it's not working - generated file is empty. I ask kindly for help.

Command cat > all.yaml takes standard output and stores it in all.yaml file. Helm operates on std in/out and Kustomize on files, so this script ensures proper communication between this tools. Script is provided to helm like: helm upgrade <release_name> <chart> --post-renderer kustomize (script is saved in file kustomize).

EDIT

Simplifing I look for Windows equivalent of Unix's:

whoami | cat > file.txt
kryski
  • 414
  • 2
  • 6
  • 18
  • And this is the error you are getting when you run that batch file: `The syntax of the command is incorrect.`. Which is coming from the `TYPE` command because you are not providing it a file to output. If you look at the help, it clearly defines that filename is NOT optional. `TYPE [drive:][path]filename`. – Squashman Oct 29 '20 at 15:55
  • 2
    What is `cat > all.yaml` supposed to do? _With no file, it would read standard input_. Are you sure it isn't at least supposed to be `cat * > all.yaml`?, _(possibly `cat *.yaml > all.yaml`)_. Then in Windows, you'd do similarly, `type * > all.yaml`, _(possibly `type *.yaml > all.yaml`)_. If your shell script is taking standard input, then in order to do the same in your batch/cmd script, you'd need to have standard input, and you clearly haven't told us what that is, or whether, in fact, there is any. – Compo Oct 29 '20 at 16:22
  • Sorry for being inaccurate. Command cat > all.yaml takes standard output and stores it in all.yaml file. Helm operates on std in/out and Kustomize on files, so this script ensures proper communication between this tools. Script is provided to helm like: helm upgrade --post-renderer kustomize (script is saved in file kustomize). I tested it on WSL Ubuntu distro and is working fine. – kryski Oct 29 '20 at 21:43
  • Are you running the script with redirected _STDIN_? like `< file.ext script.bat …`, or `program.ext | script.bat …`? – aschipfl Oct 29 '20 at 23:27
  • @aschipfl Helm runes the script as a "post renderer", but I assume it could look like: `helm template | ./kustomize` - so, the second option. – kryski Oct 30 '20 at 09:28
  • Well, this is important information, particularly for your own answer to make sense; so please incorporate this command line in your question by [edit]ing the post… – aschipfl Oct 30 '20 at 09:32
  • A little bit more about the context https://austindewey.com/2020/07/27/patch-any-helm-chart-template-using-a-kustomize-post-renderer/ – pizycki Oct 12 '22 at 12:16

1 Answers1

2

Finally have solved it! And came up with:

@echo off
more > all.yaml
kustomize build . && del all.yaml
Dharman
  • 30,962
  • 25
  • 85
  • 135
kryski
  • 414
  • 2
  • 6
  • 18
  • This seems to solve our issue as well. But I'm wondering why `cat > all.yaml` results to an empty file while `more > all.yaml` works as expected. Could you please provide some details or sources on how you came up with this solution? Thank you! – Jan Paolo Go Apr 01 '23 at 21:04
  • We're testing this in our circleci pipeline with `Ubuntu 20.04.4 LTS (Focal Fossa)` – Jan Paolo Go Apr 01 '23 at 21:14
  • It looks like it's because there is no signal to end the standard input. It might also be related to how we pass additional input to helm via `helm ... -f -`. Reading more... – Jan Paolo Go Apr 01 '23 at 21:20
  • 1
    I believe I got the information from: https://www.robvanderwoude.com/battech_redirection.php, but I'm not sure now. `more` allows to take the standard input and redirect it to file, where `type` doesn't operate on standard input, unless you force it, e.g. `type con > output.txt`. – kryski Jun 12 '23 at 13:47