kubernetes/kops · error

name is required

Error message

name is required

What it means

NewCluster validates that opt.ClusterName is a non-empty string before doing anything else. Without a cluster name, kOps cannot build the cluster spec, locate the config store, or register the cluster in the registry, so it aborts immediately with this error.

Source

Thrown at upup/pkg/fi/cloudup/new_cluster.go:222

type NewClusterResult struct {
	// Cluster is the initialized Cluster resource.
	Cluster *api.Cluster
	// InstanceGroups are the initialized InstanceGroup resources.
	InstanceGroups []*api.InstanceGroup
	// Channel is the loaded Channel object.
	Channel *api.Channel
}

// NewCluster initializes cluster and instance groups specifications as
// intended for newly created clusters.
// It is the responsibility of the caller to call cloudup.PerformAssignments() on
// the returned cluster spec.
func NewCluster(opt *NewClusterOptions, clientset simple.Clientset) (*NewClusterResult, error) {
	ctx := context.TODO()

	if opt.ClusterName == "" {
		return nil, fmt.Errorf("name is required")
	}

	if opt.Channel == "" {
		opt.Channel = api.DefaultChannel
	}
	channel, err := api.LoadChannel(clientset.VFSContext(), opt.Channel)
	if err != nil {
		return nil, err
	}

	cluster := &api.Cluster{
		ObjectMeta: v1.ObjectMeta{
			Name: opt.ClusterName,
		},
	}

	cluster.Spec.Channel = opt.Channel
	if opt.KubernetesVersion == "" {

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Pass the cluster name: `kops create cluster --name mycluster.example.com ...`
  2. Set opt.ClusterName in NewClusterOptions before calling NewCluster
  3. If a name was expected from a default, ensure KOPS_CLUSTER_NAME or equivalent config is set

Example fix

// before
kops create cluster --zones us-east-1a
// after
kops create cluster --name mycluster.example.com --zones us-east-1a
Defensive patterns

Strategy: validation

Validate before calling

if opt == nil || strings.TrimSpace(opt.ClusterName) == "" {
    return fmt.Errorf("cluster name must be set before calling NewCluster")
}

Type guard

func hasClusterName(opt *NewClusterOptions) bool {
    return opt != nil && strings.TrimSpace(opt.ClusterName) != ""
}

Prevention

When it happens

Trigger: Calling NewCluster (or RunCreateCluster / `kops create cluster`) with NewClusterOptions.ClusterName left as the empty string, e.g. the --name flag was not passed and no default was applied.

Common situations: Scripted `kops create cluster` invocations missing --name; automation that builds NewClusterOptions programmatically and forgets to set ClusterName; refactors that dropped the name field.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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