mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-10 13:42:02 +00:00
cmd/*: fail on unrecognized flags/arguments for component CLI
In case a malformed flag is passed to k8s components such as "–foo", where "–" is not an ASCII dash character, the components currently silently ignore the flag and treat it as a positional argument. Make k8s components/commands exit with an error if a positional argument that is not empty is found. Include a custom error message for all components except kubeadm, as cobra.NoArgs is used in a lot of places already (can be fixed in a followup). The kubelet already handles this properly - e.g.: 'unknown command: "–foo"' This change affects: - cloud-controller-manager - kube-apiserver - kube-controller-manager - kube-proxy - kubeadm {alpha|config|token|version} - kubemark Signed-off-by: Monis Khan <mok@vmware.com> Signed-off-by: Lubomir I. Ivanov <lubomirivanov@vmware.com>
This commit is contained in:
committed by
Lubomir I. Ivanov
parent
60559bc919
commit
fc4f91f10b
@@ -119,6 +119,14 @@ controller, and serviceaccounts controller.`,
|
||||
os.Exit(1)
|
||||
}
|
||||
},
|
||||
Args: func(cmd *cobra.Command, args []string) error {
|
||||
for _, arg := range args {
|
||||
if len(arg) > 0 {
|
||||
return fmt.Errorf("%q does not take any arguments, got %q", cmd.CommandPath(), args)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
fs := cmd.Flags()
|
||||
|
Reference in New Issue
Block a user