kubernetes / kubeadm

Aggregator for issues filed against kubeadm
Apache License 2.0
3.76k stars 716 forks source link

wrong error message when using kubeadm with unknown phase sub commands #3093

Closed akhilerm closed 2 months ago

akhilerm commented 3 months ago

What happened?

When executing the below kubeadm join command

akhil@akhilerm:/t/t/k/n/bin $ ./kubeadm join phase control-plane-join update-status --config=/run/kubeadm/kubeadm-join-config.yaml
unknown flag: --config
To see the stack trace of this error execute with --v=5 or higher

it gives the unknown flag error even though its a subcommand error.

What did you expect to happen?

Executing ./kubeadm join phase control-plane-join update-status --config=/run/kubeadm/kubeadm-join-config.yaml should also give the unknown command error

How can we reproduce it (as minimally and precisely as possible)?

  1. Checkout to the master branch of k/k
  2. make WHAT=cmd/kubeadm
  3. _output/bin/kubeadm join phase control-plain-join update-status --config=/run/kubeadm/kubeadm-join-config.yaml

Anything else we need to know?

update-status was removed in https://github.com/kubernetes/kubernetes/pull/124373

Kubernetes version

```console akhil@akhilerm:~/g/s/g/k/kubernetes (master)$ _output/bin/kubeadm version kubeadm version: &version.Info{Major:"1", Minor:"32+", GitVersion:"v1.32.0-alpha.0.18+00236ae0d73d24", GitCommit:"00236ae0d73d2455a2470469ed1005674f8ed61f", GitTreeState:"clean", BuildDate:"2024-08-05T12:11:11Z", GoVersion:"go1.22.5", Compiler:"gc", Platform:"linux/amd64"} ```

Cloud provider

OS version

```console # On Linux: $ cat /etc/os-release PRETTY_NAME="Ubuntu 22.04.4 LTS" NAME="Ubuntu" VERSION_ID="22.04" VERSION="22.04.4 LTS (Jammy Jellyfish)" VERSION_CODENAME=jammy ID=ubuntu ID_LIKE=debian HOME_URL="https://www.ubuntu.com/" SUPPORT_URL="https://help.ubuntu.com/" BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/" PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy" UBUNTU_CODENAME=jammy $ uname -a Linux sjc-ubu-eng-106 5.15.0-117-generic kubernetes/kubernetes#127-Ubuntu SMP Fri Jul 5 20:13:28 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux ```

Install tools

Container runtime (CRI) and version (if applicable)

Related plugins (CNI, CSI, ...) and versions (if applicable)

k8s-ci-robot commented 3 months ago

There are no sig labels on this issue. Please add an appropriate label by using one of the following commands:

Please see the group list for a listing of the SIGs, working groups, and committees available.

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes-sigs/prow](https://github.com/kubernetes-sigs/prow/issues/new?title=Prow%20issue:) repository.
k8s-ci-robot commented 3 months ago

This issue is currently awaiting triage.

If a SIG or subproject determines this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes-sigs/prow](https://github.com/kubernetes-sigs/prow/issues/new?title=Prow%20issue:) repository.
akhilerm commented 3 months ago

@neolit123 Wanted to know if this is relevant enough to be fixed in the kubeadm side, or has more to do with how the flags are parsed.

neolit123 commented 3 months ago

/transfer kubeadm

neolit123 commented 3 months ago

Executing ./kubeadm join phase control-plane-join update-status --config=/run/kubeadm/kubeadm-join-config.yaml should also give the unknown command error

i don't know if that is an easy fix. PRs welcome.

pacoxu commented 3 months ago

This seems to a general issue with many subcommands.

[root@node ~]# kubeadm config images  list --v1
unknown flag: --v1
To see the stack trace of this error execute with --v=5 or higher
[root@node ~]# kubeadm config images  list2 --v1
unknown flag: --v1
To see the stack trace of this error execute with --v=5 or higher
neolit123 commented 3 months ago

/retitle wrong error message when using kubeadm with unknown phase sub commands

neolit123 commented 2 months ago

did some investigation and this seems to be standard cobra behavior. flags are processed before sub-commands and arguments of a parent command.

to illustrate:

$ kubeadm init foo --bar
unknown flag: --bar
To see the stack trace of this error execute with --v=5 or higher

$ kubeadm init foo
unknown command "foo" for "kubeadm init"
To see the stack trace of this error execute with --v=5 or higher

the unknown flag --bar is processed first and if the invalid flag is removed the unknown command is then detected. i.e. this is not something caused by the kubeadm phase logic, which is a bit complicated.

i think it's fine for us to acknowledge this issue, but i don't think we need to make any fixes for it in kubeadm or cobra.

neolit123 commented 2 months ago

something that we should probably fix is the following:

$ kubeadm init phase foo && echo ok

...

ok

i.e. the unknown command returns exit code 0.

i will send a PR for that.