{"record":{"id":"d7924ee9c9de9057","repo":"kubernetes/kops","slug":"can-only-add-to-one-keyset-at-a-time","errorCode":null,"errorMessage":"can only add to one keyset at a time","messagePattern":"can only add to one keyset at a time","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kops/create_keypair.go","lineNumber":113,"sourceCode":"\t\tUse:     \"keypair {KEYSET | all}\",\n\t\tShort:   createKeypairShort,\n\t\tLong:    createKeypairLong,\n\t\tExample: createKeypairExample,\n\t\tArgs: func(cmd *cobra.Command, args []string) error {\n\t\t\toptions.ClusterName = rootCommand.ClusterName(true)\n\n\t\t\tif options.ClusterName == \"\" {\n\t\t\t\treturn fmt.Errorf(\"--name is required\")\n\t\t\t}\n\n\t\t\tif len(args) == 0 {\n\t\t\t\treturn fmt.Errorf(\"must specify name of keyset to add keypair to\")\n\t\t\t}\n\n\t\t\toptions.Keyset = args[0]\n\n\t\t\tif len(args) != 1 {\n\t\t\t\treturn fmt.Errorf(\"can only add to one keyset at a time\")\n\t\t\t}\n\n\t\t\tif options.Keyset == \"all\" {\n\t\t\t\tif options.CertPath != \"\" {\n\t\t\t\t\treturn fmt.Errorf(\"cannot specify --cert with \\\"all\\\"\")\n\t\t\t\t}\n\t\t\t\tif options.PrivateKeyPath != \"\" {\n\t\t\t\t\treturn fmt.Errorf(\"cannot specify --key with \\\"all\\\"\")\n\t\t\t\t}\n\t\t\t\tif options.Primary {\n\t\t\t\t\treturn fmt.Errorf(\"cannot specify --primary with \\\"all\\\"\")\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn nil\n\t\t},\n\t\tValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {\n\t\t\treturn completeCreateKeypair(cmd.Context(), f, options, args, toComplete)","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/cmd/kops/create_keypair.go#L95-L131","documentation":"To keep argument handling simple, the command accepts only one keyset per invocation. If more than one positional argument is supplied, the validator rejects the call with this message rather than guessing.","triggerScenarios":"Running `kops create keypair --name <cluster> apiserver kubelet` — two keyset names in a single command.","commonSituations":"Assuming multiple keysets can be batched like other bulk kubectl operations; shell glob expansion matching several names (e.g. `kops create keypair *`); accidentally leaving an extra token from a copied command line.","solutions":["Run the command once per keyset instead of passing several names","Quote or disable globs if shell expansion added extra arguments","Verify with `kops create keypair --help` that only a single KEYSET argument is accepted"],"exampleFix":"// before\nkops create keypair --name c.k8s.local apiserver kubelet\n// after\nkops create keypair --name c.k8s.local apiserver\nkops create keypair --name c.k8s.local kubelet","handlingStrategy":"validation","validationCode":"[ $# -eq 1 ] || { echo \"pass exactly one keyset; loop over keysets instead\" >&2; exit 2; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Loop over keysets in bash: for ks in ...; do kops create keypair ... \"$ks\"; done","Quote globs or set -f to prevent multi-match expansion","Validate argument count with $# in wrapper scripts"],"tags":["cli","args","validation"],"backgroundTag":"too-many-arguments","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}