{"record":{"id":"5ffa52c7c6d13e89","repo":"kubernetes/kops","slug":"name-is-required-5ffa52","errorCode":null,"errorMessage":"--name is required","messagePattern":"--name is required","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kops/trust_keypair.go","lineNumber":67,"sourceCode":"\ntype TrustKeypairOptions struct {\n\tClusterName string\n\tKeyset      string\n\tKeypairIDs  []string\n}\n\nfunc NewCmdTrustKeypair(f *util.Factory, out io.Writer) *cobra.Command {\n\toptions := &TrustKeypairOptions{}\n\n\tcmd := &cobra.Command{\n\t\tUse:     \"keypair KEYSET ID...\",\n\t\tShort:   trustKeypairShort,\n\t\tLong:    trustKeypairLong,\n\t\tExample: trustKeypairExample,\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\tif len(args) == 0 {\n\t\t\t\treturn fmt.Errorf(\"must specify name of keyset to trust keypair in\")\n\t\t\t}\n\t\t\toptions.Keyset = args[0]\n\n\t\t\tif len(args) == 1 {\n\t\t\t\treturn fmt.Errorf(\"must specify names of keypairs to trust keypair in\")\n\t\t\t}\n\t\t\toptions.KeypairIDs = args[1:]\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 completeTrustKeyset(cmd.Context(), f, options, args, toComplete)\n\t\t},\n\t\tRunE: func(cmd *cobra.Command, args []string) error {","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/cmd/kops/trust_keypair.go#L49-L85","documentation":"The `kops trust keypair` command requires a cluster name. It takes it from rootCommand.ClusterName(true), which resolves the --name flag; if empty, the Args validator rejects the invocation with this error before any cluster access.","triggerScenarios":"Running `kops trust keypair <keyset> <keypair-ids...>` without --name and without KOPS_CLUSTER_NAME or a kops-context set cluster.","commonSituations":"Running from a directory with no cluster context; forgetting --name when scripting; environment variable not exported in CI.","solutions":["Add `--name <cluster-name>` to the command.","Set KOPS_CLUSTER_NAME environment variable for the shell/session.","Run `kops set cluster <cluster-name>` to set the default cluster context."],"exampleFix":"// before\nkops trust keypair kubelet 2026-01-01\n// after\nkops trust keypair --name mycluster.example.com kubelet 2026-01-01","handlingStrategy":"validation","validationCode":"cluster := os.Getenv(\"KOPS_CLUSTER_NAME\")\nif cluster == \"\" { return errors.New(\"set --name or KOPS_CLUSTER_NAME before running kops trust keypair\") }","typeGuard":null,"tryCatchPattern":"out, err := exec.Command(\"kops\", \"trust\", \"keypair\", \"--name\", cluster, args...).CombinedOutput()\nif strings.Contains(string(out), \"--name is required\") { prompt for / resolve cluster name and retry }","preventionTips":["Always pass --name in scripts","Export KOPS_CLUSTER_NAME in CI environments","Use `kops set cluster` to persist a default cluster context"],"tags":["cli","validation","arguments"],"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"}