{"record":{"id":"5142efd9a6e7ba43","repo":"kubernetes/kops","slug":"name-is-required-5142ef","errorCode":null,"errorMessage":"--name is required","messagePattern":"--name is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kops/root.go","lineNumber":240,"sourceCode":"\trootCommand.RegistryPath = viper.GetString(\"KOPS_STATE_STORE\")\n\n\t// Tolerate multiple slashes at end\n\trootCommand.RegistryPath = strings.TrimSuffix(rootCommand.RegistryPath, \"/\")\n}\n\nfunc (c *RootCmd) AddCommand(cmd *cobra.Command) {\n\tc.cobraCommand.AddCommand(cmd)\n}\n\nfunc (c *RootCmd) clusterNameArgs(clusterName *string) func(cmd *cobra.Command, args []string) error {\n\treturn func(cmd *cobra.Command, args []string) error {\n\t\tif err := c.ProcessArgs(args); err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\t*clusterName = c.ClusterName(true)\n\t\tif *clusterName == \"\" {\n\t\t\treturn fmt.Errorf(\"--name is required\")\n\t\t}\n\n\t\treturn nil\n\t}\n}\n\nfunc (c *RootCmd) clusterNameArgsNoKubeconfig(clusterName *string) func(cmd *cobra.Command, args []string) error {\n\treturn func(cmd *cobra.Command, args []string) error {\n\t\tif err := c.ProcessArgs(args); err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\t*clusterName = c.clusterName\n\t\tif *clusterName == \"\" {\n\t\t\treturn fmt.Errorf(\"--name is required\")\n\t\t}\n\n\t\treturn nil","sourceCodeStart":222,"sourceCodeEnd":258,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/cmd/kops/root.go#L222-L258","documentation":"clusterNameArgs is a cobra Args/PreRun validator used by commands that require a cluster name. After ProcessArgs, it calls c.ClusterName(true), which falls back to the kubeconfig's current context if the flag/arg was not given; if the resolved name is still empty, it returns \"--name is required\". The command cannot proceed without knowing which cluster to operate on.","triggerScenarios":"The subcommand was invoked with neither --name, a positional <clustername>, nor a usable current-context in kubeconfig (ClusterName(true) returns \"\").","commonSituations":"Running a kops subcommand from CI or a fresh machine with no kubeconfig and forgetting --name; typing a command like `kops get instancegroups` without arguments; KUBECONFIG pointing at an empty file.","solutions":["Pass the cluster explicitly: --name <cluster> or as a positional argument","Set a current context: kubectl config use-context <context> so ClusterName can fall back to kubeconfig","Run `kops export kubeconfig <cluster>` first on machines without kubeconfig","Verify KUBECONFIG env var points at a populated config file"],"exampleFix":"// before\nkops get instancegroups\n// error: --name is required\n// after\nkops get instancegroups --name mycluster.k8s.local","handlingStrategy":"validation","validationCode":"// resolve cluster name the way kops does before invoking\nname := flagName // --name value\nif name == \"\" {\n    name = currentContextFromKubeconfig() // kubectl config current-context\n}\nif name == \"\" {\n    return errors.New(\"cluster name required: pass --name or set a kubeconfig context\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass --name explicitly in scripts and CI","Run kops export kubeconfig on fresh machines before kops commands","Avoid relying on implicit kubeconfig current-context resolution","Pin KUBECONFIG env var per environment"],"tags":["cli-flags","validation","cluster-name"],"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"}