{"record":{"id":"57550fb838ef7f69","repo":"kubernetes/kops","slug":"name-is-required-57550f","errorCode":null,"errorMessage":"name is required","messagePattern":"name is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/cloudup/new_cluster.go","lineNumber":222,"sourceCode":"\ntype NewClusterResult struct {\n\t// Cluster is the initialized Cluster resource.\n\tCluster *api.Cluster\n\t// InstanceGroups are the initialized InstanceGroup resources.\n\tInstanceGroups []*api.InstanceGroup\n\t// Channel is the loaded Channel object.\n\tChannel *api.Channel\n}\n\n// NewCluster initializes cluster and instance groups specifications as\n// intended for newly created clusters.\n// It is the responsibility of the caller to call cloudup.PerformAssignments() on\n// the returned cluster spec.\nfunc NewCluster(opt *NewClusterOptions, clientset simple.Clientset) (*NewClusterResult, error) {\n\tctx := context.TODO()\n\n\tif opt.ClusterName == \"\" {\n\t\treturn nil, fmt.Errorf(\"name is required\")\n\t}\n\n\tif opt.Channel == \"\" {\n\t\topt.Channel = api.DefaultChannel\n\t}\n\tchannel, err := api.LoadChannel(clientset.VFSContext(), opt.Channel)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tcluster := &api.Cluster{\n\t\tObjectMeta: v1.ObjectMeta{\n\t\t\tName: opt.ClusterName,\n\t\t},\n\t}\n\n\tcluster.Spec.Channel = opt.Channel\n\tif opt.KubernetesVersion == \"\" {","sourceCodeStart":204,"sourceCodeEnd":240,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/cloudup/new_cluster.go#L204-L240","documentation":"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.","triggerScenarios":"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.","commonSituations":"Scripted `kops create cluster` invocations missing --name; automation that builds NewClusterOptions programmatically and forgets to set ClusterName; refactors that dropped the name field.","solutions":["Pass the cluster name: `kops create cluster --name mycluster.example.com ...`","Set opt.ClusterName in NewClusterOptions before calling NewCluster","If a name was expected from a default, ensure KOPS_CLUSTER_NAME or equivalent config is set"],"exampleFix":"// before\nkops create cluster --zones us-east-1a\n// after\nkops create cluster --name mycluster.example.com --zones us-east-1a","handlingStrategy":"validation","validationCode":"if opt == nil || strings.TrimSpace(opt.ClusterName) == \"\" {\n    return fmt.Errorf(\"cluster name must be set before calling NewCluster\")\n}","typeGuard":"func hasClusterName(opt *NewClusterOptions) bool {\n    return opt != nil && strings.TrimSpace(opt.ClusterName) != \"\"\n}","tryCatchPattern":null,"preventionTips":["Always pass --name to `kops create cluster`","Default ClusterName from KOPS_CLUSTER_NAME in wrappers","Validate options structs in CLI flag parsing before business logic"],"tags":["cli","validation","missing-argument"],"backgroundTag":"missing-required-argument","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"}