k0s exits with status code 0 when encountering unknown subcommands
Before creating an issue, make sure you've checked the following:
- [X] You are running the latest released version of k0s
- [X] Make sure you've searched for existing issues, both open and closed
- [X] Make sure you've searched for PRs too, a fix might've been merged already
- [X] You're looking at docs for the released version, "main" branch docs are usually ahead of released versions.
Version
v1.23.3+k0s.1
Platform
No LSB modules are available.
Distributor ID: NixOS
Description: NixOS 21.11 (Porcupine)
Release: 21.11
Codename: porcupine
What happened?
Unknown subcommands are ignored by the k0s CLI and treated as if they haven't been given at all. This may get in the way when invoking k0s from scripts and other automation tools.
Steps to reproduce
Test case:
run_test() {
for cmd in \
airgap \
api \
backup \
completion \
config \
controller \
ctr \
docs \
etcd \
help \
install \
kubeconfig \
kubectl \
reset \
restore \
start \
status \
stop \
sysinfo \
token \
version \
worker; do
echo Executing k0s "$cmd" i_certainly_dont_exist ... 1>&2
if ./k0s-v1.23.3+k0s.1-amd64 "$cmd" i_certainly_dont_exist 2>/dev/null; then
echo k0s "$cmd" i_certainly_dont_exist succeeded unexpectedly ... 1>&2
fi
done
}
run_test 2>&1 | grep 'succeeded unexpectedly'
gives
k0s airgap i_certainly_dont_exist succeeded unexpectedly ...
k0s config i_certainly_dont_exist succeeded unexpectedly ...
k0s etcd i_certainly_dont_exist succeeded unexpectedly ...
k0s help i_certainly_dont_exist succeeded unexpectedly ...
k0s install i_certainly_dont_exist succeeded unexpectedly ...
k0s kubeconfig i_certainly_dont_exist succeeded unexpectedly ...
k0s sysinfo i_certainly_dont_exist succeeded unexpectedly ...
k0s token i_certainly_dont_exist succeeded unexpectedly ...
k0s version i_certainly_dont_exist succeeded unexpectedly ...
Expected behavior
Unknown subcommands result in a non-zero exit code, and the help text is written to stderr.
Actual behavior
The general CLI help text is written to stdout and k0s exits with a zero exit code.
Screenshots and logs
No response
Additional context
No response
k0sctl relies on using the --help of subcommands to figure out if the k0s version has that subcommand or not.
The issue is marked as stale since no activity has been recorded in 30 days
The issue is marked as stale since no activity has been recorded in 30 days
The issue is marked as stale since no activity has been recorded in 30 days
The issue is marked as stale since no activity has been recorded in 30 days
The issue is marked as stale since no activity has been recorded in 30 days
How hard do we want this? It seems to be limitation in the cobra lib (example, https://github.com/spf13/cobra/issues/706) or even part of design.
I expected something like that :-/. Closing, since it's just a small inconvenience, compared to the effort that seems to be required to fix it.