{"record":{"id":"417317afb9f29c25","repo":"kubernetes/kubernetes","slug":"controllerref-controller-is-not-set-to-true","errorCode":null,"errorMessage":"controllerRef.Controller is not set to true","messagePattern":"controllerRef\\.Controller is not set to true","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/controller/controller_utils.go","lineNumber":532,"sourceCode":"\tprefix := fmt.Sprintf(\"%s-\", controllerName)\n\tif len(validation.ValidatePodName(prefix, true)) != 0 {\n\t\tprefix = controllerName\n\t}\n\treturn prefix\n}\n\nfunc validateControllerRef(controllerRef *metav1.OwnerReference) error {\n\tif controllerRef == nil {\n\t\treturn fmt.Errorf(\"controllerRef is nil\")\n\t}\n\tif len(controllerRef.APIVersion) == 0 {\n\t\treturn fmt.Errorf(\"controllerRef has empty APIVersion\")\n\t}\n\tif len(controllerRef.Kind) == 0 {\n\t\treturn fmt.Errorf(\"controllerRef has empty Kind\")\n\t}\n\tif controllerRef.Controller == nil || !*controllerRef.Controller {\n\t\treturn fmt.Errorf(\"controllerRef.Controller is not set to true\")\n\t}\n\tif controllerRef.BlockOwnerDeletion == nil || !*controllerRef.BlockOwnerDeletion {\n\t\treturn fmt.Errorf(\"controllerRef.BlockOwnerDeletion is not set\")\n\t}\n\treturn nil\n}\n\nfunc (r RealPodControl) CreatePods(ctx context.Context, namespace string, template *v1.PodTemplateSpec, controllerObject runtime.Object, controllerRef *metav1.OwnerReference) error {\n\treturn r.CreatePodsWithGenerateName(ctx, namespace, template, controllerObject, controllerRef, \"\")\n}\n\nfunc (r RealPodControl) CreatePodsWithGenerateName(ctx context.Context, namespace string, template *v1.PodTemplateSpec, controllerObject runtime.Object, controllerRef *metav1.OwnerReference, generateName string) error {\n\tif err := validateControllerRef(controllerRef); err != nil {\n\t\treturn err\n\t}\n\tpod, err := GetPodFromTemplate(template, controllerObject, controllerRef)\n\tif err != nil {\n\t\treturn err","sourceCodeStart":514,"sourceCodeEnd":550,"githubUrl":"https://github.com/kubernetes/kubernetes/blob/94c136764292cc5fac976c0de6587daaea56410f/pkg/controller/controller_utils.go#L514-L550","documentation":"validateControllerRef rejects an OwnerReference where Controller is nil or set to false. The Controller boolean must be true to indicate that this owner is the managing controller of the pod. Kubernetes allows at most one OwnerReference with Controller=true per object. Setting it to false or nil would make this a non-controlling reference, which is invalid for the pod creation path.","triggerScenarios":"RealPodControl.CreatePodsWithGenerateName validates controllerRef.Controller. The check is: controllerRef.Controller == nil || !*controllerRef.Controller. A controllerRef with Controller unset or explicitly false triggers this.","commonSituations":"Manually building an OwnerReference and forgetting to set Controller: pointer.Bool(true). Using a non-controlling OwnerReference (e.g., for metadata linking) where a controlling one was expected. Refactoring that drops the Controller field.","solutions":["Set Controller: pointer.Bool(true) on the OwnerReference.","Use metav1.NewControllerRef which sets Controller=true automatically.","Review any code that modifies controllerRef.Controller after construction."],"exampleFix":"// before\ncontrollerRef := &metav1.OwnerReference{\n    APIVersion: \"apps/v1\",\n    Kind: \"StatefulSet\",\n    Name: setName,\n    UID: set.UID,\n}\n\n// after\ncontrollerRef := &metav1.OwnerReference{\n    APIVersion: \"apps/v1\",\n    Kind: \"StatefulSet\",\n    Name: setName,\n    UID: set.UID,\n    Controller: pointer.Bool(true),\n    BlockOwnerDeletion: pointer.Bool(true),\n}","handlingStrategy":"validation","validationCode":"if controllerRef != nil && (controllerRef.Controller == nil || !*controllerRef.Controller) {\n    return fmt.Errorf(\"controllerRef.Controller must be true\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always use metav1.NewControllerRef — it sets Controller=true by default.","Never set Controller to false for a reference you intend to use for pod creation.","Use k8s.io/utils/pointer.Bool(true) to set the Controller field correctly."],"tags":["controller","pod-control","owner-reference","validation","controller-flag"],"backgroundTag":null,"analyzedSha":"94c136764292cc5fac976c0de6587daaea56410f","analyzedAt":"2026-08-08T23:58:27.554Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}