kubernetes/kops · error
--name is required
Error message
--name is required
What it means
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.
Source
Thrown at cmd/kops/get_keypairs.go:68
type GetKeypairsOptions struct {
*GetOptions
KeysetNames []string
Distrusted bool
}
func NewCmdGetKeypairs(f *util.Factory, out io.Writer, getOptions *GetOptions) *cobra.Command {
options := &GetKeypairsOptions{
GetOptions: getOptions,
}
cmd := &cobra.Command{
Use: "keypairs [KEYSET]...",
Aliases: []string{"keypair"},
Short: getKeypairShort,
Example: getKeypairExample,
Args: func(cmd *cobra.Command, args []string) error {
options.ClusterName = rootCommand.ClusterName(true)
if options.ClusterName == "" {
return fmt.Errorf("--name is required")
}
options.KeysetNames = args
return nil
},
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return completeGetKeypairs(cmd.Context(), f, options, args, toComplete)
},
RunE: func(cmd *cobra.Command, args []string) error {
return RunGetKeypairs(cmd.Context(), f, out, options)
},
}
cmd.Flags().BoolVar(&options.Distrusted, "distrusted", options.Distrusted, "Include distrusted keypairs")
return cmd
}
View on GitHub (pinned to 4c8573c808)
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.
Example fix
// before kops get keypair ca // after kops get keypair ca --name mycluster.k8s.local
Defensive patterns
Strategy: validation
Validate before calling
CLUSTER="${KOPS_CLUSTER_NAME:-mycluster.k8s.local}"
[ -n "$CLUSTER" ] || { echo "set --name or KOPS_CLUSTER_NAME" >&2; exit 2; }
kops get keypairs --name "$CLUSTER" Try / catch
if err := runKops("get", "keypairs", "--name", cluster); err != nil {
if strings.Contains(err.Error(), "--name is required") {
return fmt.Errorf("cluster name missing: pass --name or set KOPS_CLUSTER_NAME")
}
return err
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
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
- must specify ID of instance or name of node to delete
- must specify the name of the instance group to delete
- --name is required
- cluster not found %q
- unsupported output format: %q
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/01eb1ceb5ca87bdc.
Report an issue: GitHub.