kubernetes/kops · error
--name is required
Error message
--name is required
What it means
RunPromoteKeypair needs a target cluster. The cobra Args validator for `kops promote keypair` reads the cluster name from rootCommand.ClusterName(true); if it is empty (no --name flag and no cluster in context/kubecfg), it fails fast with this message.
Source
Thrown at cmd/kops/promote_keypair.go:82
ClusterName string
Keyset string
KeypairID string
}
// NewCmdPromoteKeypair returns a promote keypair command.
func NewCmdPromoteKeypair(f *util.Factory, out io.Writer) *cobra.Command {
options := &PromoteKeypairOptions{}
cmd := &cobra.Command{
Use: "keypair {KEYSET [ID] | all}",
Short: promoteKeypairShort,
Long: promoteKeypairLong,
Example: promoteKeypairExample,
Args: func(cmd *cobra.Command, args []string) error {
options.ClusterName = rootCommand.ClusterName(true)
if options.ClusterName == "" {
return fmt.Errorf("--name is required")
}
if len(args) == 0 {
return fmt.Errorf("must specify name of keyset promote keypair in")
}
options.Keyset = args[0]
if len(args) > 2 {
return fmt.Errorf("can only promote to one keyset at a time")
}
if len(args) > 1 {
if options.Keyset == "all" {
return fmt.Errorf("cannot specify ID with \"all\"")
}
options.KeypairID = args[1]
}View on GitHub (pinned to 4c8573c808)
Solutions
- Add --name <cluster.k8s.local> to the command
- Export KOPS_CLUSTER_NAME or ensure the cluster name is resolvable from the current kops context
- Check flag spelling (kops uses --name, not --cluster)
- Run `kops get clusters` to confirm the exact cluster name
Example fix
// before kops promote keypair all // after kops promote keypair all --name mycluster.k8s.local
Defensive patterns
Strategy: validation
Validate before calling
if [ -z "$KOPS_CLUSTER_NAME" ]; then echo "usage: kops promote keypair <keyset> --name <cluster>"; exit 1; fi
Prevention
- Always pass --name explicitly in scripts
- Set KOPS_CLUSTER_NAME in your shell profile for single-cluster workflows
- Verify with `kops get clusters` before promotion
When it happens
Trigger: Running `kops promote keypair <keyset>` without --name and without a cluster name set via KOPS_CLUSTER_NAME, context state, or the --name flag.
Common situations: Forgetting --name when scripting; running from a machine with no kops state store access so the cluster cannot be defaulted; typo in --name such that the flag parser ignored it.
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
- unsupported output type %q
- --project cannot be empty; specify a project or omit the fla
- cannot specify --key with "all"
- cannot specify --primary with "all"
- --name is required
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/bb3ea928b43d4cbb.
Report an issue: GitHub.