{"record":{"id":"4f035d05bccebba7","repo":"kubernetes/kops","slug":"clustername-is-missing","errorCode":null,"errorMessage":"ClusterName is missing","messagePattern":"ClusterName is missing","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/commands/toolbox_enroll.go","lineNumber":652,"sourceCode":"\t\treturn nil, err\n\t}\n\n\tinstanceGroupList, err := clientset.InstanceGroupsFor(cluster).List(ctx, metav1.ListOptions{})\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"reading instance groups: %w\", err)\n\t}\n\n\tb.instanceGroups = instanceGroupList\n\treturn instanceGroupList, nil\n}\n\nfunc (b *ConfigBuilder) GetCluster(ctx context.Context) (*kops.Cluster, error) {\n\tif b.Cluster != nil {\n\t\treturn b.Cluster, nil\n\t}\n\n\tif b.ClusterName == \"\" {\n\t\treturn nil, fmt.Errorf(\"ClusterName is missing\")\n\t}\n\n\tclientset, err := b.GetClientset(ctx)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tcluster, err := clientset.GetCluster(ctx, b.ClusterName)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif cluster == nil {\n\t\treturn nil, fmt.Errorf(\"cluster %q not found\", b.ClusterName)\n\t}\n\tb.Cluster = cluster\n\treturn cluster, nil\n}\n\nfunc (b *ConfigBuilder) GetAssetBuilder(ctx context.Context) (*assets.AssetBuilder, error) {","sourceCodeStart":634,"sourceCodeEnd":670,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/commands/toolbox_enroll.go#L634-L670","documentation":"GetCluster fetches the kops.Cluster from the state store, but first requires b.ClusterName. If the builder has no cached Cluster and ClusterName is empty, this sentinel error is returned — the builder cannot know which cluster to read.","triggerScenarios":"Calling GetCluster (or anything downstream: GetCloud, GetFullCluster, GetInstanceGroups, GetAssetBuilder) on a ConfigBuilder with Cluster == nil and ClusterName == \"\".","commonSituations":"Omitting --name on `kops toolbox enroll`; programmatic builder use without setting ClusterName; refactors dropping the flag-to-builder wiring.","solutions":["Set ClusterName on the ConfigBuilder (or pass --name on the CLI)","Check for a cached b.Cluster if you expected the pre-set object to be used","Add an early guard that surfaces the missing cluster name as a usage error"],"exampleFix":"// before\nb := ConfigBuilder{Clientset: cs}\ncluster, err := b.GetCluster(ctx) // \"ClusterName is missing\"\n// after\nb := ConfigBuilder{Clientset: cs, ClusterName: \"c1.example.com\"}","handlingStrategy":"validation","validationCode":"if b.ClusterName == \"\" && b.Cluster == nil {\n    return errors.New(\"--name (cluster name) is required\")\n}","typeGuard":"func (b *ConfigBuilder) HasClusterRef() bool { return b.Cluster != nil || b.ClusterName != \"\" }","tryCatchPattern":null,"preventionTips":["Always pass --name on CLI invocations","Validate required builder fields before calling Get* methods","Default ClusterName from config/context where appropriate"],"tags":["configuration","cluster","validation"],"backgroundTag":"missing-required-config","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"}