{"record":{"id":"ee630b9eeafd5515","repo":"kubesphere/kubesphere","slug":"failed-to-list-builtin-role-templates","errorCode":null,"errorMessage":"failed to list builtin role templates","messagePattern":"failed to list builtin role templates","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/controller/namespace/namespace_controller.go","lineNumber":126,"sourceCode":"\t\t}\n\t\treturn ctrl.Result{}, nil\n\t}\n\n\tif !workspaceLabelExists {\n\t\tif err := r.cleanUp(ctx, namespace); err != nil {\n\t\t\treturn ctrl.Result{}, errors.Wrapf(err, \"failed to clean up namespace %s\", namespace.Name)\n\t\t}\n\t}\n\n\tr.recorder.Event(namespace, corev1.EventTypeNormal, kscontroller.Synced, kscontroller.MessageResourceSynced)\n\treturn ctrl.Result{}, nil\n}\n\nfunc (r *Reconciler) initRoles(ctx context.Context, namespace *corev1.Namespace) error {\n\tlogger := klog.FromContext(ctx)\n\tvar templates iamv1beta1.BuiltinRoleList\n\tif err := r.List(ctx, &templates, client.MatchingLabels{iamv1beta1.ScopeLabel: iamv1beta1.ScopeNamespace}); err != nil {\n\t\treturn errors.Wrapf(err, \"failed to list builtin role templates\")\n\t}\n\tfor _, template := range templates.Items {\n\t\tselector, err := metav1.LabelSelectorAsSelector(&template.TargetSelector)\n\t\tif err != nil {\n\t\t\tlogger.V(4).Error(err, \"failed to pares target selector\", \"template\", template.Name)\n\t\t\tcontinue\n\t\t}\n\t\tif !selector.Matches(labels.Set(namespace.Labels)) {\n\t\t\tcontinue\n\t\t}\n\t\tvar builtinRoleTemplate iamv1beta1.Role\n\t\tif err := yaml.NewYAMLOrJSONDecoder(bytes.NewBuffer(template.Role.Raw), 1024).Decode(&builtinRoleTemplate); err == nil &&\n\t\t\tbuiltinRoleTemplate.Kind == iamv1beta1.ResourceKindRole {\n\t\t\texistingRole := &iamv1beta1.Role{ObjectMeta: metav1.ObjectMeta{Name: builtinRoleTemplate.Name, Namespace: namespace.Name}}\n\t\t\top, err := controllerutil.CreateOrUpdate(ctx, r.Client, existingRole, func() error {\n\t\t\t\texistingRole.Labels = builtinRoleTemplate.Labels\n\t\t\t\texistingRole.Annotations = builtinRoleTemplate.Annotations\n\t\t\t\texistingRole.AggregationRoleTemplates = builtinRoleTemplate.AggregationRoleTemplates","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/kubesphere/kubesphere/blob/04a29b5c601470fa6bc2f2e92358dcb802a0d414/pkg/controller/namespace/namespace_controller.go#L108-L144","documentation":"Reconciler.initRoles: listing BuiltinRole templates (iamv1beta1.BuiltinRoleList with the scope label selector) via r.List failed. Without the role templates the namespace's builtin roles cannot be materialized; the wrapped API error names the cause (RBAC, connectivity, or malformed cluster-scoped templates).","triggerScenarios":"Thrown at pkg/controller/namespace/namespace_controller.go:126 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Confirm BuiltinRole CRD is installed and template objects exist with the scope label","Check controller RBAC for list permissions on the builtinroles resource","Fix the underlying list error shown in the wrapped message and let the controller re-reconcile"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"04a29b5c601470fa6bc2f2e92358dcb802a0d414","analyzedAt":"2026-09-03T18:33:15.017Z","contentChangedAt":"2026-09-03T18:33:15.017Z","schemaVersion":2},"datasetVersion":"2026-09-11T00:17:11.886Z"}