{"record":{"id":"85e03f71d8f4ed03","repo":"kubernetes/kops","slug":"name-is-required-85e03f","errorCode":null,"errorMessage":"name is required","messagePattern":"name is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/commands/toolbox/clusterapi/generate_machinedeployment.go","lineNumber":101,"sourceCode":"\tcmd.Flags().StringVar(&options.ClusterName, \"cluster\", options.ClusterName, \"Name of cluster to join\")\n\tcmd.Flags().StringVar(&options.Name, \"name\", options.Name, \"Name of MachineDeployment (and other objects) to create\")\n\tcmd.Flags().StringVar(&options.Namespace, \"namespace\", options.Namespace, \"Namespace for objects\")\n\tcmd.Flags().IntVar(&options.Replicas, \"replicas\", options.Replicas, \"Number of replicas for MachineDeployment\")\n\tcmd.Flags().StringArrayVar(&options.Zones, \"zones\", options.Zones, \"Zones for the MachineDeployment (if not specified, will be deployed to all discovered zones in the cluster)\")\n\tcmd.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)\")\n\tcmd.Flags().StringVar(&options.Subnet, \"subnet\", options.Subnet, \"Subnet for the MachineDeployment (if not specified, an arbitrary subnet from the instance groups will be used)\")\n\tcmd.Flags().StringVar(&options.Image, \"image\", options.Image, \"Image for the MachineDeployment (if not specified, an arbitrary image from the instance groups will be used)\")\n\treturn cmd\n}\n\nfunc RunGenerateMachineDeployment(ctx context.Context, f commandutils.Factory, out io.Writer, options *GenerateMachineDeploymentOptions) error {\n\tlog := klog.FromContext(ctx)\n\n\tif options.ClusterName == \"\" {\n\t\treturn fmt.Errorf(\"cluster is required\")\n\t}\n\tif options.Name == \"\" {\n\t\treturn fmt.Errorf(\"name is required\")\n\t}\n\n\tclientset, err := f.KopsClient()\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tcluster, err := clientset.GetCluster(ctx, options.ClusterName)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\t// TODO: Sync with LinkToSubnet and support ID\n\tsubnet := options.Subnet\n\tif subnet == \"\" {\n\t\tsubnets := sets.New[string]()\n\t\tfor _, subnet := range cluster.Spec.Networking.Subnets {\n\t\t\tsubnets.Insert(subnet.Name)","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/commands/toolbox/clusterapi/generate_machinedeployment.go#L83-L119","documentation":"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.","triggerScenarios":"Running the toolbox clusterapi generate machinedeployment command without --name, or constructing GenerateMachineDeploymentOptions without setting Name.","commonSituations":"Omitting --name in CI automation; assuming the name is derived from the cluster; copying command examples that predate the required --name flag.","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}\"."],"exampleFix":"// before\nopts := &GenerateMachineDeploymentOptions{ClusterName: \"c1.k8s.local\"}\nRunGenerateMachineDeployment(ctx, f, out, opts) // name is required\n// after\nopts := &GenerateMachineDeploymentOptions{ClusterName: \"c1.k8s.local\", Name: \"workers\"}\nRunGenerateMachineDeployment(ctx, f, out, opts)","handlingStrategy":"validation","validationCode":"if options == nil || options.Name == \"\" {\n\treturn fmt.Errorf(\"name is required: pass --name <machinedeployment-name>\")\n}","typeGuard":"func optsReady(o *GenerateMachineDeploymentOptions) bool {\n\treturn o != nil && o.ClusterName != \"\" && o.Name != \"\"\n}","tryCatchPattern":"if err := RunGenerateMachineDeployment(ctx, f, out, options); err != nil {\n\tif err.Error() == \"name is required\" {\n\t\treturn fmt.Errorf(\"--name is required: %w\", err)\n\t}\n\treturn err\n}","preventionTips":["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."],"tags":["kops","cluster-api","cli-validation"],"backgroundTag":"missing-required-flag","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T07:17:12.445Z"}