kubernetes/kops · error

clientset is required

Error message

clientset is required

What it means

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.

Source

Thrown at pkg/commands/toolbox_enroll.go:494

	// fullCluster holds the fully-expanded cluster configuration
	// Use GetFullCluster to read and auto-populate.
	fullCluster *kops.Cluster

	// fullInstanceGroup holds the fully-expanded instance group configuration
	// Use GetFullIntsanceGroup to read and auto-populate.
	fullInstanceGroup *kops.InstanceGroup

	// bootstrapData holds the final computed bootstrap configuration.
	// Use GetBootstrapData to read and auto-populate.
	bootstrapData *BootstrapData
}

func (b *ConfigBuilder) GetClientset(ctx context.Context) (simple.Clientset, error) {
	if b.Clientset != nil {
		return b.Clientset, nil
	}
	return nil, fmt.Errorf("clientset is required")
}

func (b *ConfigBuilder) GetFullCluster(ctx context.Context) (*kops.Cluster, error) {
	if b.fullCluster != nil {
		return b.fullCluster, nil
	}

	clientset, err := b.GetClientset(ctx)
	if err != nil {
		return nil, err
	}

	cluster, err := b.GetCluster(ctx)
	if err != nil {
		return nil, err
	}

	cloud, err := b.GetCloud(ctx)

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Set the clientset before use, e.g. via the builder option/factory (clientset from kops factory for the cluster's state store)
  2. Check that config, cluster name, and state store flags are populated so clientset creation succeeds
  3. In code, call GetClientset() first and surface its error instead of assuming nil-Clientset paths work

Example fix

// before
b := &toolbox_enroll.ConfigBuilder{} // Clientset nil
cluster, err := b.GetCluster(ctx)     // "clientset is required"
// after
clientset, err := factory.KopsClientset(clusterName)
b := &toolbox_enroll.ConfigBuilder{Clientset: clientset}
Defensive patterns

Strategy: validation

Validate before calling

if b.Clientset == nil {
    cs, err := factory.KopsClientset(clusterName)
    if err != nil { return err }
    b.Clientset = cs
}

Type guard

func (b *ConfigBuilder) HasClientset() bool { return b.Clientset != nil }

Try / catch

cluster, err := b.GetCluster(ctx)
if err != nil && strings.Contains(err.Error(), "clientset is required") {
    return fmt.Errorf("builder misconfigured: initialize Clientset first")
}

Prevention

When it happens

Trigger: Calling GetFullCluster / GetCluster / GetInstanceGroups / GetFullInstanceGroup / GetAssetBuilder / GetBootstrapData on a ConfigBuilder whose Clientset field is nil.

Common situations: 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.

Related errors


AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05). Data as JSON: /api/errors/d132b488c9314cbb. Report an issue: GitHub.