kubernetes/kops · error

--name is required

Error message

--name is required

What it means

The create keypair command's cobra Args validator resolves the cluster name via rootCommand.ClusterName(true) and rejects the invocation when it is empty. kOps needs to know which cluster's keyset to modify; without --name (or a cluster name from context/config) the operation is ambiguous.

Source

Thrown at cmd/kops/create_keypair.go:103

func rotatableKeysetFilter(name string, _ *fi.Keyset) bool {
	return name == "all" || name == "service-account" || strings.Contains(name, "-ca")
}

// NewCmdCreateKeypair returns a create keypair command.
func NewCmdCreateKeypair(f *util.Factory, out io.Writer) *cobra.Command {
	options := &CreateKeypairOptions{}

	cmd := &cobra.Command{
		Use:     "keypair {KEYSET | all}",
		Short:   createKeypairShort,
		Long:    createKeypairLong,
		Example: createKeypairExample,
		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 to add keypair to")
			}

			options.Keyset = args[0]

			if len(args) != 1 {
				return fmt.Errorf("can only add to one keyset at a time")
			}

			if options.Keyset == "all" {
				if options.CertPath != "" {
					return fmt.Errorf("cannot specify --cert with \"all\"")
				}
				if options.PrivateKeyPath != "" {
					return fmt.Errorf("cannot specify --key with \"all\"")

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Pass the cluster explicitly: `kops create keypair --name <cluster-name> <keyset>`
  2. Set KOPS_CLUSTER_NAME environment variable
  3. Ensure KOPS_STATE_STORE is set and the cluster is registered in it (`kops get clusters`)
  4. Fix typos in the --name value so rootCommand.ClusterName() resolves it

Example fix

// before
kops create keypair kubelet
// after
kops create keypair --name mycluster.k8s.local kubelet
Defensive patterns

Strategy: validation

Validate before calling

[ -n "${KOPS_CLUSTER_NAME:-$CLUSTER_NAME}" ] || { echo "set --name or KOPS_CLUSTER_NAME" >&2; exit 2; }

Prevention

When it happens

Trigger: Running `kops create keypair <keyset>` with no --name flag, no cluster name argument context, and no cluster configured in KOPS_STATE_STORE/kops config — so options.ClusterName resolves to "".

Common situations: Forgetting --name in scripts; KOPS_STATE_STORE set but no default cluster registered; env var KOPS_CLUSTER_NAME unset; running from a directory without a kops cluster context.

Related errors


AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05). Data as JSON: /api/errors/a385bf7ccde884bc. Report an issue: GitHub.