{"record":{"id":"c81f2c1b57bbce9c","repo":"kubernetes/kops","slug":"could-not-get-name-from-clusterpackage","errorCode":null,"errorMessage":"could not get name from ClusterPackage","messagePattern":"could not get name from ClusterPackage","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/wellknownoperators/operators.go","lineNumber":79,"sourceCode":"\t\t\t\tif err != nil {\n\t\t\t\t\treturn nil, nil, fmt.Errorf(\"failed to load package: %w\", err)\n\t\t\t\t}\n\t\t\t\tpackages = append(packages, pkg)\n\t\t\t\tkeep = false\n\t\t\t}\n\t\t}\n\n\t\tif keep {\n\t\t\tkeepObjects = append(keepObjects, object)\n\t\t}\n\t}\n\treturn packages, keepObjects, nil\n}\n\nfunc (b *Builder) loadClusterPackage(u *unstructured.Unstructured) (*Package, error) {\n\toperatorKey := u.GetName()\n\tif operatorKey == \"\" {\n\t\treturn nil, fmt.Errorf(\"could not get name from ClusterPackage\")\n\t}\n\n\toperatorVersion, _, err := unstructured.NestedString(u.Object, \"spec\", \"version\")\n\tif err != nil || operatorVersion == \"\" {\n\t\treturn nil, fmt.Errorf(\"could not get spec.version from ClusterPackage\")\n\t}\n\n\tid := operatorVersion\n\n\tlocation := path.Join(\"packages\", operatorKey, operatorVersion, \"manifest.yaml\")\n\tchannelURL, err := kops.ResolveChannel(b.Cluster.Spec.Channel)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error resolving channel %q: %v\", b.Cluster.Spec.Channel, err)\n\t}\n\n\tlocationURL := channelURL.ResolveReference(&url.URL{Path: location}).String()\n\n\tmanifestBytes, err := b.VFSContext.ReadFile(locationURL)","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/wellknownoperators/operators.go#L61-L97","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Set metadata.name on the ClusterPackage manifest and re-apply","If constructing the object in code/tests, ensure ObjectName/SetName is called before Build","Validate the addon YAML (kubectl apply --dry-run or kops toolbox) before adding it to the cluster","Check the package source manifest actually contains the metadata block"],"exampleFix":"// before\nu := &unstructured.Unstructured{}\nu.SetGroupVersionKind(schema.GroupVersionKind{Group: \"addons.x-k8s.io\", Kind: \"ClusterPackage\"})\nb.loadClusterPackage(u) // could not get name from ClusterPackage\n// after\nu.SetName(\"cert-manager\")\nb.loadClusterPackage(u)","handlingStrategy":"validation","validationCode":"if u.GetName() == \"\" {\n    return fmt.Errorf(\"ClusterPackage manifest must set metadata.name\")\n}","typeGuard":"func hasName(u *unstructured.Unstructured) bool {\n    return u != nil && u.GetName() != \"\"\n}","tryCatchPattern":"pkg, err := b.loadClusterPackage(u)\nif err != nil {\n    return nil, fmt.Errorf(\"ClusterPackage %q invalid: %w\", u.GetName(), err)\n}","preventionTips":["Always include a metadata block in ClusterPackage YAML","When constructing Unstructured objects in code, call SetName before Build","Dry-run apply the manifest to catch missing metadata early"],"tags":["go","kops","clusterpackage","validation","model-builder"],"backgroundTag":"cluster-package-load-failed","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"}