{"record":{"id":"d132b488c9314cbb","repo":"kubernetes/kops","slug":"clientset-is-required","errorCode":null,"errorMessage":"clientset is required","messagePattern":"clientset is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/commands/toolbox_enroll.go","lineNumber":494,"sourceCode":"\n\t// fullCluster holds the fully-expanded cluster configuration\n\t// Use GetFullCluster to read and auto-populate.\n\tfullCluster *kops.Cluster\n\n\t// fullInstanceGroup holds the fully-expanded instance group configuration\n\t// Use GetFullIntsanceGroup to read and auto-populate.\n\tfullInstanceGroup *kops.InstanceGroup\n\n\t// bootstrapData holds the final computed bootstrap configuration.\n\t// Use GetBootstrapData to read and auto-populate.\n\tbootstrapData *BootstrapData\n}\n\nfunc (b *ConfigBuilder) GetClientset(ctx context.Context) (simple.Clientset, error) {\n\tif b.Clientset != nil {\n\t\treturn b.Clientset, nil\n\t}\n\treturn nil, fmt.Errorf(\"clientset is required\")\n}\n\nfunc (b *ConfigBuilder) GetFullCluster(ctx context.Context) (*kops.Cluster, error) {\n\tif b.fullCluster != nil {\n\t\treturn b.fullCluster, nil\n\t}\n\n\tclientset, err := b.GetClientset(ctx)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tcluster, err := b.GetCluster(ctx)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tcloud, err := b.GetCloud(ctx)","sourceCodeStart":476,"sourceCodeEnd":512,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/commands/toolbox_enroll.go#L476-L512","documentation":"ConfigBuilder.GetClientset returns the pre-configured Kubernetes clientset, or this error if none was set. Most builder methods (GetCluster, GetFullCluster, GetInstanceGroups, etc.) need API access to the cluster's state store, so they fail fast when the builder was constructed without a clientset.","triggerScenarios":"Calling GetFullCluster / GetCluster / GetInstanceGroups / GetFullInstanceGroup / GetAssetBuilder / GetBootstrapData on a ConfigBuilder whose Clientset field is nil.","commonSituations":"Constructing ConfigBuilder manually in tests/tools without calling SetClientset or the option that injects it; a earlier GetClientset/factory call failed silently; refactoring dropped the clientset assignment.","solutions":["Set the clientset before use, e.g. via the builder option/factory (clientset from kops factory for the cluster's state store)","Check that config, cluster name, and state store flags are populated so clientset creation succeeds","In code, call GetClientset() first and surface its error instead of assuming nil-Clientset paths work"],"exampleFix":"// before\nb := &toolbox_enroll.ConfigBuilder{} // Clientset nil\ncluster, err := b.GetCluster(ctx)     // \"clientset is required\"\n// after\nclientset, err := factory.KopsClientset(clusterName)\nb := &toolbox_enroll.ConfigBuilder{Clientset: clientset}","handlingStrategy":"validation","validationCode":"if b.Clientset == nil {\n    cs, err := factory.KopsClientset(clusterName)\n    if err != nil { return err }\n    b.Clientset = cs\n}","typeGuard":"func (b *ConfigBuilder) HasClientset() bool { return b.Clientset != nil }","tryCatchPattern":"cluster, err := b.GetCluster(ctx)\nif err != nil && strings.Contains(err.Error(), \"clientset is required\") {\n    return fmt.Errorf(\"builder misconfigured: initialize Clientset first\")\n}","preventionTips":["Always construct ConfigBuilder via the factory/options that inject the clientset","Add a constructor check that Clientset is non-nil","Cover builder setup in unit tests"],"tags":["kubernetes","configuration","nil-check"],"backgroundTag":"missing-clientset","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"}