kubernetes/kops · error
name is required
Error message
name is required
What it means
A required-argument check in the toolbox clusterapi generate-machinedeployment command: the --name flag (which names the MachineDeployment and related objects) was left empty, so no object names can be derived.
Source
Thrown at pkg/commands/toolbox/clusterapi/generate_machinedeployment.go:101
cmd.Flags().StringVar(&options.ClusterName, "cluster", options.ClusterName, "Name of cluster to join")
cmd.Flags().StringVar(&options.Name, "name", options.Name, "Name of MachineDeployment (and other objects) to create")
cmd.Flags().StringVar(&options.Namespace, "namespace", options.Namespace, "Namespace for objects")
cmd.Flags().IntVar(&options.Replicas, "replicas", options.Replicas, "Number of replicas for MachineDeployment")
cmd.Flags().StringArrayVar(&options.Zones, "zones", options.Zones, "Zones for the MachineDeployment (if not specified, will be deployed to all discovered zones in the cluster)")
cmd.Flags().StringVar(&options.InstanceType, "instance-type", options.InstanceType, "Instance type for the MachineDeployment (if not specified, an arbitrary instance type from the instance groups will be used)")
cmd.Flags().StringVar(&options.Subnet, "subnet", options.Subnet, "Subnet for the MachineDeployment (if not specified, an arbitrary subnet from the instance groups will be used)")
cmd.Flags().StringVar(&options.Image, "image", options.Image, "Image for the MachineDeployment (if not specified, an arbitrary image from the instance groups will be used)")
return cmd
}
func RunGenerateMachineDeployment(ctx context.Context, f commandutils.Factory, out io.Writer, options *GenerateMachineDeploymentOptions) error {
log := klog.FromContext(ctx)
if options.ClusterName == "" {
return fmt.Errorf("cluster is required")
}
if options.Name == "" {
return fmt.Errorf("name is required")
}
clientset, err := f.KopsClient()
if err != nil {
return err
}
cluster, err := clientset.GetCluster(ctx, options.ClusterName)
if err != nil {
return err
}
// TODO: Sync with LinkToSubnet and support ID
subnet := options.Subnet
if subnet == "" {
subnets := sets.New[string]()
for _, subnet := range cluster.Spec.Networking.Subnets {
subnets.Insert(subnet.Name)View on GitHub (pinned to 4c8573c808)
Solutions
- Pass --name <machinedeployment-name> to the command.
- Set options.Name explicitly when invoking programmatically.
- Default the name in scripts, e.g. NAME="${NAME:-workers}".
Example fix
// before
opts := &GenerateMachineDeploymentOptions{ClusterName: "c1.k8s.local"}
RunGenerateMachineDeployment(ctx, f, out, opts) // name is required
// after
opts := &GenerateMachineDeploymentOptions{ClusterName: "c1.k8s.local", Name: "workers"}
RunGenerateMachineDeployment(ctx, f, out, opts) Defensive patterns
Strategy: validation
Validate before calling
if options == nil || options.Name == "" {
return fmt.Errorf("name is required: pass --name <machinedeployment-name>")
} Type guard
func optsReady(o *GenerateMachineDeploymentOptions) bool {
return o != nil && o.ClusterName != "" && o.Name != ""
} Try / catch
if err := RunGenerateMachineDeployment(ctx, f, out, options); err != nil {
if err.Error() == "name is required" {
return fmt.Errorf("--name is required: %w", err)
}
return err
} Prevention
- Mark --name as required at the cobra command level so the CLI enforces it before Run.
- Default names in CI pipelines but verify they are non-empty.
- Pre-validate GenerateMachineDeploymentOptions in wrappers around the exported function.
When it happens
Trigger: Running the toolbox clusterapi generate machinedeployment command without --name, or constructing GenerateMachineDeploymentOptions without setting Name.
Common situations: Omitting --name in CI automation; assuming the name is derived from the cluster; copying command examples that predate the required --name flag.
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
- cluster is required
- error creating kops config template: %w
- error creating gcp machine template: %w
- error building machine deployments: %w
- no subnets found in cluster %q
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/85e03f71d8f4ed03.
Report an issue: GitHub.