kubernetes/kops · error

unable to parse assets as assetBuilder is not defined

Error message

unable to parse assets as assetBuilder is not defined

What it means

Image() builds the docker image reference for a kOps component, but resolving an image may require rewriting/verifying assets, which needs an AssetBuilder. The function guards against a nil assetsBuilder and refuses to run, returning this error instead of panicking on a nil pointer.

Source

Thrown at pkg/model/components/context.go:139

		baseIPInt := big.NewInt(0)
		baseIPInt.SetBytes(ip6)
		serviceIPInt := big.NewInt(0)
		serviceIPInt.Add(big.NewInt(int64(id)), baseIPInt)
		serviceIP := make(net.IP, len(ip6))
		serviceIPBytes := serviceIPInt.Bytes()
		for i := range serviceIPBytes {
			serviceIP[len(serviceIP)-len(serviceIPBytes)+i] = serviceIPBytes[i]
		}
		return serviceIP, nil
	}

	return nil, fmt.Errorf("unexpected IP address type for ServiceClusterIPRange: %s", networkingSpec.ServiceClusterIPRange)
}

// Image returns the docker image name for the specified component
func Image(component string, clusterSpec *kops.ClusterSpec, assetsBuilder *assets.AssetBuilder) (string, error) {
	if assetsBuilder == nil {
		return "", fmt.Errorf("unable to parse assets as assetBuilder is not defined")
	}

	kubernetesVersion, err := kopsmodel.ParseKubernetesVersion(clusterSpec.KubernetesVersion)
	if err != nil {
		return "", err
	}

	imageName := component

	if !kubernetesVersion.IsBaseURL() {
		image := "registry.k8s.io/" + imageName + ":" + "v" + kubernetesVersion.String()

		return assetsBuilder.RemapImage(image), nil
	}

	// The simple name is valid when pulling.  But if we
	// are loading from a tarfile then the image is tagged with
	// the architecture suffix.

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Pass a valid *assets.AssetBuilder (e.g. built via BuildOptions / assetutils.RecommendAssets) instead of nil
  2. If assets are irrelevant for your case, compute the image name manually or use the default image path that does not require asset rewriting
  3. In tests, construct a minimal AssetBuilder or use the existing TestImage harness that supplies one

Example fix

// before
img, err := components.Image("kube-apiserver", clusterSpec, nil)
// after
assetsBuilder := assets.NewAssetBuilder(assetsLocation, kubernetesVersion, false)
img, err := components.Image("kube-apiserver", clusterSpec, assetsBuilder)
Defensive patterns

Strategy: validation

Validate before calling

if assetsBuilder == nil {
    return fmt.Errorf("assetsBuilder must be constructed before calling components.Image")
}

Type guard

func hasAssetBuilder(b *assets.AssetBuilder) bool { return b != nil }

Try / catch

img, err := components.Image(component, clusterSpec, assetsBuilder)
if err != nil {
    return fmt.Errorf("resolving image for %s: %w", component, err)
}

Prevention

When it happens

Trigger: Calling components.Image(component, clusterSpec, nil) — e.g. when a caller such as BuildOptions skips asset construction or a test passes no builder — and the component image cannot be resolved without the builder.

Common situations: Custom code or tests invoking Image() directly without building assets via assetutils/build options; refactored call sites that dropped the AssetBuilder argument; partial initialization of build options.

Understand the failure class

Related errors


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