k0s icon indicating copy to clipboard operation
k0s copied to clipboard

k0s exits with status code 0 when encountering unknown subcommands

Open twz123 opened this issue 3 years ago • 5 comments

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

twz123 avatar Mar 24 '22 12:03 twz123

k0sctl relies on using the --help of subcommands to figure out if the k0s version has that subcommand or not.

kke avatar Mar 24 '22 12:03 kke

The issue is marked as stale since no activity has been recorded in 30 days

github-actions[bot] avatar Apr 24 '22 23:04 github-actions[bot]

The issue is marked as stale since no activity has been recorded in 30 days

github-actions[bot] avatar May 25 '22 23:05 github-actions[bot]

The issue is marked as stale since no activity has been recorded in 30 days

github-actions[bot] avatar Jun 25 '22 23:06 github-actions[bot]

The issue is marked as stale since no activity has been recorded in 30 days

github-actions[bot] avatar Jul 27 '22 23:07 github-actions[bot]

The issue is marked as stale since no activity has been recorded in 30 days

github-actions[bot] avatar Aug 27 '22 23:08 github-actions[bot]

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.

mikhail-sakhnov avatar Aug 31 '22 09:08 mikhail-sakhnov

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.

twz123 avatar Aug 31 '22 09:08 twz123