{"record":{"id":"01eb1ceb5ca87bdc","repo":"kubernetes/kops","slug":"name-is-required-01eb1c","errorCode":null,"errorMessage":"--name is required","messagePattern":"--name is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kops/get_keypairs.go","lineNumber":68,"sourceCode":"type GetKeypairsOptions struct {\n\t*GetOptions\n\tKeysetNames []string\n\tDistrusted  bool\n}\n\nfunc NewCmdGetKeypairs(f *util.Factory, out io.Writer, getOptions *GetOptions) *cobra.Command {\n\toptions := &GetKeypairsOptions{\n\t\tGetOptions: getOptions,\n\t}\n\tcmd := &cobra.Command{\n\t\tUse:     \"keypairs [KEYSET]...\",\n\t\tAliases: []string{\"keypair\"},\n\t\tShort:   getKeypairShort,\n\t\tExample: getKeypairExample,\n\t\tArgs: func(cmd *cobra.Command, args []string) error {\n\t\t\toptions.ClusterName = rootCommand.ClusterName(true)\n\t\t\tif options.ClusterName == \"\" {\n\t\t\t\treturn fmt.Errorf(\"--name is required\")\n\t\t\t}\n\n\t\t\toptions.KeysetNames = args\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 completeGetKeypairs(cmd.Context(), f, options, args, toComplete)\n\t\t},\n\t\tRunE: func(cmd *cobra.Command, args []string) error {\n\t\t\treturn RunGetKeypairs(cmd.Context(), f, out, options)\n\t\t},\n\t}\n\n\tcmd.Flags().BoolVar(&options.Distrusted, \"distrusted\", options.Distrusted, \"Include distrusted keypairs\")\n\n\treturn cmd\n}\n","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/cmd/kops/get_keypairs.go#L50-L86","documentation":"The `kops get keypair(s)` command requires a cluster name. In the command's Args validator, options.ClusterName is taken from rootCommand.ClusterName(true); if it is empty (no --name flag, no KOPS_CLUSTER_NAME, and no cluster state in the current directory), the command aborts with \"--name is required\" before doing any work.","triggerScenarios":"Running `kops get keypair` (or `kops get keypairs`) outside a cluster directory without passing `--name <cluster>` and without the KOPS_CLUSTER_NAME environment variable set.","commonSituations":"Running from a directory that is not a kOps cluster root after a `cd`; forgetting to export KOPS_CLUSTER_NAME in CI; new team members following docs that assume the in-cluster context.","solutions":["Add the flag: `kops get keypairs --name <cluster.k8s.local>`.","Set the environment variable: `export KOPS_CLUSTER_NAME=<cluster.k8s.local>`.","Run the command from the cluster's state directory so the cluster name can be detected.","Verify the cluster name with `kops get clusters` and use the exact name."],"exampleFix":"// before\nkops get keypair ca\n// after\nkops get keypair ca --name mycluster.k8s.local","handlingStrategy":"validation","validationCode":"CLUSTER=\"${KOPS_CLUSTER_NAME:-mycluster.k8s.local}\"\n[ -n \"$CLUSTER\" ] || { echo \"set --name or KOPS_CLUSTER_NAME\" >&2; exit 2; }\nkops get keypairs --name \"$CLUSTER\"","typeGuard":null,"tryCatchPattern":"if err := runKops(\"get\", \"keypairs\", \"--name\", cluster); err != nil {\n\tif strings.Contains(err.Error(), \"--name is required\") {\n\t\treturn fmt.Errorf(\"cluster name missing: pass --name or set KOPS_CLUSTER_NAME\")\n\t}\n\treturn err\n}","preventionTips":["Always pass --name explicitly in scripts instead of relying on cwd detection.","Export KOPS_CLUSTER_NAME in shell profiles and CI environments.","Run `kops get clusters` to confirm the exact cluster name first.","Execute keypair commands from the intended cluster directory or with absolute flags."],"tags":["cli","input-validation","cluster-name","missing-argument"],"backgroundTag":"missing-required-flag","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"}