Change:
I'm not sure whether this is the documentation being unclear, or a bug with kubectl itself but I suspect the former. Given this help page I expected to be able to use Instead I got the following error To get the same output as defining the flag twice aka and should give the same output, or the help page shouldn't list as the parameter type for --serviceaccount No response <details</details<detailsN/A </details<details</details<details</details<detailsarchitecture: amd64 bootID: -c6dc-40bb-9485- containerRuntimeVersion: containerd://1.5.5 kernelVersion: 5.4.0-88-generic kubeProxyVersion: v1.23.1 kubeletVersion: v1.23.1 </details<details</details
/sig cli
the flag can be specified multiple times, or (I think) as a comma-separated list. agree the notation is confusing... I think that's how cobra prints the default value (which is an empty list)
Hi I have tried and confirmed that it works with multiple flags: But for the comma-separated list, doesn't work. Kubectl version: v1.23.3 and k8s version v1.23.3
The same update for rolebinding: Should we write like this(same for clusterrolebinding):
Thanks for the investigation, another approach that might help is adding an example with the comma separated service accounts in the examples section. I do wonder if there's a clearer representation that could be output by cobra, to make it clear what the behaviour should be...?
Hi, I think adding the example is good so that users who reference this document get the proper information. but there is already mention of how to this flag with create command under the usage section: What do you suggest
in the specific flag help, we can mention the flag can be repeated to add multiple subjects
+1 I will update this. /assign
This sounds good to me, might be worth doing the same for other places that use the same behaviour?
Sure I will do that.
I have fixed it here: PTAL!
/triage accepted

Discussion:
cmdutil.AddDryRunFlag(cmd) cmd.Flags().StringVar(&o.ClusterRole, "clusterrole", "", i18n.T("ClusterRole this ClusterRoleBinding should reference")) cmd.MarkFlagRequired("clusterrole") <del> cmd.Flags().StringArrayVar(&o.Users, "user", o.Users, "Usernames to bind to the clusterrole") cmd.Flags().StringArrayVar(&o.Groups, "group", o.Groups, "Groups to bind to the clusterrole") cmd.Flags().StringArrayVar(&o.ServiceAccounts, "serviceaccount", o.ServiceAccounts, "Service accounts to bind to the clusterrole, in the format <namespace>:<name>") </del> <ins> cmd.Flags().StringArrayVar(&o.Users, "user", o.Users, "Usernames to bind to the clusterrole. The flag can be repeated to add multiple users.") cmd.Flags().StringArrayVar(&o.Groups, "group", o.Groups, "Groups to bind to the clusterrole. The flag can be repeated to add multiple groups.") cmd.Flags().StringArrayVar(&o.ServiceAccounts, "serviceaccount", o.ServiceAccounts, "Service accounts to bind to the clusterrole, in the format <namespace>:<name>. The flag can be repeated to add multiple service accounts.") </ins> cmdutil.AddFieldManagerFlagVar(cmd, &o.FieldManager, "kubectl-create") // Completion for relevant flags

cmdutil.AddDryRunFlag(cmd) cmd.Flags().StringVar(&o.ClusterRole, "clusterrole", "", i18n.T("ClusterRole this RoleBinding should reference")) cmd.Flags().StringVar(&o.Role, "role", "", i18n.T("Role this RoleBinding should reference")) <del> cmd.Flags().StringArrayVar(&o.Users, "user", o.Users, "Usernames to bind to the role") cmd.Flags().StringArrayVar(&o.Groups, "group", o.Groups, "Groups to bind to the role") cmd.Flags().StringArrayVar(&o.ServiceAccounts, "serviceaccount", o.ServiceAccounts, "Service accounts to bind to the role, in the format <namespace>:<name>") </del> <ins> cmd.Flags().StringArrayVar(&o.Users, "user", o.Users, "Usernames to bind to the role. The flag can be repeated to add multiple users.") cmd.Flags().StringArrayVar(&o.Groups, "group", o.Groups, "Groups to bind to the role. The flag can be repeated to add multiple groups.") cmd.Flags().StringArrayVar(&o.ServiceAccounts, "serviceaccount", o.ServiceAccounts, "Service accounts to bind to the role, in the format <namespace>:<name>. The flag can be repeated to add multiple service accounts.") </ins> cmdutil.AddFieldManagerFlagVar(cmd, &o.FieldManager, "kubectl-create") return cmd }