kudobuilder / kuttl

KUbernetes Test TooL (kuttl)
https://kuttl.dev
Apache License 2.0
682 stars 85 forks source link

Ability to choose a shell for scripts #557

Open NickLarsenNZ opened 2 months ago

NickLarsenNZ commented 2 months ago

What would you like to be added:

The ability to choose a shell for commands in TestAssert. For example:

---
apiVersion: kuttl.dev/v1beta1
kind: TestAssert
timeout: 600
commands:
  - shell: bash # runs bash -c instead of sh -c
    script: |
      set -euo pipefail
      ...
  - shell: bash -euo pipefail # runs bash -euo pipefail -c instead of sh -c
    script: |
      ...

Why is this needed:

porridge commented 2 months ago

What's worse, the behaviour of /bin/sh depends the environment. In some cases it is simply a symlink to bash, and then the bash features work. This reduces portability of tests. 😞

A couple of thoughts:

NickLarsenNZ commented 2 months ago

What's worse, the behaviour of /bin/sh depends the environment. In some cases it is simply a symlink to bash, and then the bash features work. This reduces portability of tests. 😞

Yeah, I'm having the problem where sh is a symlink to zsh, and zsh doesn't appear to treat sh as such - so the tests passed locally for me, but fail in CI which doesn't use zsh (unsure if it uses actual sh, or a symlink to bash - which as you say, treats it like sh).

if we're going as far as allowing any shell, perhaps we should get rid of the assumption that -c is the way to pass the script to the shell, and instead rely on temporary files? 🤔

Temporary files would be fine too, as you can then write them like a script with the shebang.

porridge commented 2 months ago

Temporary files would be fine too, as you can then write them like a script with the shebang.

The only potential issue would be that some folks might have /tmp mounted -o noexec 🤔 But I guess we could keep the current sh -c ... behaviour unless the text of script starts with #!?