{"record":{"id":"a385bf7ccde884bc","repo":"kubernetes/kops","slug":"name-is-required-a385bf","errorCode":null,"errorMessage":"--name is required","messagePattern":"--name is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kops/create_keypair.go","lineNumber":103,"sourceCode":"\nfunc rotatableKeysetFilter(name string, _ *fi.Keyset) bool {\n\treturn name == \"all\" || name == \"service-account\" || strings.Contains(name, \"-ca\")\n}\n\n// NewCmdCreateKeypair returns a create keypair command.\nfunc NewCmdCreateKeypair(f *util.Factory, out io.Writer) *cobra.Command {\n\toptions := &CreateKeypairOptions{}\n\n\tcmd := &cobra.Command{\n\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\\\"\")","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/cmd/kops/create_keypair.go#L85-L121","documentation":"The create keypair command's cobra Args validator resolves the cluster name via rootCommand.ClusterName(true) and rejects the invocation when it is empty. kOps needs to know which cluster's keyset to modify; without --name (or a cluster name from context/config) the operation is ambiguous.","triggerScenarios":"Running `kops create keypair <keyset>` with no --name flag, no cluster name argument context, and no cluster configured in KOPS_STATE_STORE/kops config — so options.ClusterName resolves to \"\".","commonSituations":"Forgetting --name in scripts; KOPS_STATE_STORE set but no default cluster registered; env var KOPS_CLUSTER_NAME unset; running from a directory without a kops cluster context.","solutions":["Pass the cluster explicitly: `kops create keypair --name <cluster-name> <keyset>`","Set KOPS_CLUSTER_NAME environment variable","Ensure KOPS_STATE_STORE is set and the cluster is registered in it (`kops get clusters`)","Fix typos in the --name value so rootCommand.ClusterName() resolves it"],"exampleFix":"// before\nkops create keypair kubelet\n// after\nkops create keypair --name mycluster.k8s.local kubelet","handlingStrategy":"validation","validationCode":"[ -n \"${KOPS_CLUSTER_NAME:-$CLUSTER_NAME}\" ] || { echo \"set --name or KOPS_CLUSTER_NAME\" >&2; exit 2; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass --name in scripts","Export KOPS_CLUSTER_NAME in shell profiles for a default cluster","Confirm with `kops get clusters` that the cluster resolves"],"tags":["cli","flags","validation"],"backgroundTag":"missing-cluster-name","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T07:17:12.445Z"}