kubernetes/kops · error
--name is required
Error message
--name is required
What it means
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.
Source
Thrown at cmd/kops/root.go:240
rootCommand.RegistryPath = viper.GetString("KOPS_STATE_STORE")
// Tolerate multiple slashes at end
rootCommand.RegistryPath = strings.TrimSuffix(rootCommand.RegistryPath, "/")
}
func (c *RootCmd) AddCommand(cmd *cobra.Command) {
c.cobraCommand.AddCommand(cmd)
}
func (c *RootCmd) clusterNameArgs(clusterName *string) func(cmd *cobra.Command, args []string) error {
return func(cmd *cobra.Command, args []string) error {
if err := c.ProcessArgs(args); err != nil {
return err
}
*clusterName = c.ClusterName(true)
if *clusterName == "" {
return fmt.Errorf("--name is required")
}
return nil
}
}
func (c *RootCmd) clusterNameArgsNoKubeconfig(clusterName *string) func(cmd *cobra.Command, args []string) error {
return func(cmd *cobra.Command, args []string) error {
if err := c.ProcessArgs(args); err != nil {
return err
}
*clusterName = c.clusterName
if *clusterName == "" {
return fmt.Errorf("--name is required")
}
return nilView on GitHub (pinned to 4c8573c808)
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
Example fix
// before kops get instancegroups // error: --name is required // after kops get instancegroups --name mycluster.k8s.local
Defensive patterns
Strategy: validation
Validate before calling
// resolve cluster name the way kops does before invoking
name := flagName // --name value
if name == "" {
name = currentContextFromKubeconfig() // kubectl config current-context
}
if name == "" {
return errors.New("cluster name required: pass --name or set a kubeconfig context")
} Prevention
- 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
When it happens
Trigger: The subcommand was invoked with neither --name, a positional <clustername>, nor a usable current-context in kubeconfig (ClusterName(true) returns "").
Common situations: 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.
Understand the failure class
Background: "--flag is required" and "must specify" CLI errors: how missing-required-flag validation works and how to fix it — this error's family across 20 libraries.
Related errors
- clientset bound to cluster %q, got cluster %q
- InstanceGroup %q not found
- invalid instance group role %q
- cannot specify cluster via --name and positional argument
- expected a single <clustername> to be passed as an argument
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/5142efd9a6e7ba43.
Report an issue: GitHub.