kubernetes/kops · error

could not get name from ClusterPackage

Error message

could not get name from ClusterPackage

What it means

loadClusterPackage derives the operator key from the ClusterPackage object's metadata name. If GetName() is empty the package cannot be keyed, so this error is returned. It means the ClusterPackage Unstructured object reached the builder without a usable name — a malformed or incomplete resource.

Source

Thrown at pkg/wellknownoperators/operators.go:79

				if err != nil {
					return nil, nil, fmt.Errorf("failed to load package: %w", err)
				}
				packages = append(packages, pkg)
				keep = false
			}
		}

		if keep {
			keepObjects = append(keepObjects, object)
		}
	}
	return packages, keepObjects, nil
}

func (b *Builder) loadClusterPackage(u *unstructured.Unstructured) (*Package, error) {
	operatorKey := u.GetName()
	if operatorKey == "" {
		return nil, fmt.Errorf("could not get name from ClusterPackage")
	}

	operatorVersion, _, err := unstructured.NestedString(u.Object, "spec", "version")
	if err != nil || operatorVersion == "" {
		return nil, fmt.Errorf("could not get spec.version from ClusterPackage")
	}

	id := operatorVersion

	location := path.Join("packages", operatorKey, operatorVersion, "manifest.yaml")
	channelURL, err := kops.ResolveChannel(b.Cluster.Spec.Channel)
	if err != nil {
		return nil, fmt.Errorf("error resolving channel %q: %v", b.Cluster.Spec.Channel, err)
	}

	locationURL := channelURL.ResolveReference(&url.URL{Path: location}).String()

	manifestBytes, err := b.VFSContext.ReadFile(locationURL)

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Set metadata.name on the ClusterPackage manifest and re-apply
  2. If constructing the object in code/tests, ensure ObjectName/SetName is called before Build
  3. Validate the addon YAML (kubectl apply --dry-run or kops toolbox) before adding it to the cluster
  4. Check the package source manifest actually contains the metadata block

Example fix

// before
u := &unstructured.Unstructured{}
u.SetGroupVersionKind(schema.GroupVersionKind{Group: "addons.x-k8s.io", Kind: "ClusterPackage"})
b.loadClusterPackage(u) // could not get name from ClusterPackage
// after
u.SetName("cert-manager")
b.loadClusterPackage(u)
Defensive patterns

Strategy: validation

Validate before calling

if u.GetName() == "" {
    return fmt.Errorf("ClusterPackage manifest must set metadata.name")
}

Type guard

func hasName(u *unstructured.Unstructured) bool {
    return u != nil && u.GetName() != ""
}

Try / catch

pkg, err := b.loadClusterPackage(u)
if err != nil {
    return nil, fmt.Errorf("ClusterPackage %q invalid: %w", u.GetName(), err)
}

Prevention

When it happens

Trigger: b.loadClusterPackage is called with an Unstructured object whose metadata.name is empty — the ClusterPackage was created without a name or the manifest omitted metadata entirely.

Common situations: Hand-written addon YAML missing the metadata section; programmatically constructed ClusterPackage (as in builder tests) that forgot to set Name; template rendering producing an object with empty name.

Related errors


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