{"record":{"id":"e04fb7b3f24595b7","repo":"kubernetes/kops","slug":"failed-to-initialize-the-service-controller-error","errorCode":null,"errorMessage":"failed to initialize the service controller, error: %v","messagePattern":"failed to initialize the service controller, error: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"dns-controller/cmd/dns-controller/main.go","lineNumber":168,"sourceCode":"}\n\n// initializeWatchers is responsible for creating the watchers\nfunc initializeWatchers(client kubernetes.Interface, dnsctl *dns.DNSController, namespace string, watchIngress bool, internalRecordTypes []dns.RecordType) error {\n\tklog.V(1).Infof(\"initializing the watch controllers, namespace: %q\", namespace)\n\n\tnodeController, err := watchers.NewNodeController(client, dnsctl, internalRecordTypes)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to initialize the node controller, error: %v\", err)\n\t}\n\n\tpodController, err := watchers.NewPodController(client, dnsctl, namespace)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to initialize the pod controller, error: %v\", err)\n\t}\n\n\tserviceController, err := watchers.NewServiceController(client, dnsctl, namespace)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to initialize the service controller, error: %v\", err)\n\t}\n\n\tvar ingressController *watchers.IngressController\n\tif watchIngress {\n\t\tingressController, err = watchers.NewIngressController(client, dnsctl, namespace)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to initialize the ingress controller, error: %v\", err)\n\t\t}\n\t} else {\n\t\tklog.Infof(\"Ingress controller disabled\")\n\t}\n\n\tgo nodeController.Run()\n\tgo podController.Run()\n\tgo serviceController.Run()\n\n\tif watchIngress {\n\t\tgo ingressController.Run()","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/dns-controller/cmd/dns-controller/main.go#L150-L186","documentation":"Wraps a failure of watchers.NewServiceController during dns-controller startup. The controller that watches Service objects for DNS records could not be constructed, so the watcher set cannot be initialized and the process exits.","triggerScenarios":"NewServiceController is called with a nil/invalid client, nil DNS controller, or invalid namespace and returns an error.","commonSituations":"Malformed kubeconfig or missing RBAC preventing client setup; invalid --namespace value; corrupted build/binary passing bad arguments.","solutions":["Inspect the wrapped underlying error text.","Verify RBAC and kubeconfig allow listing/watching services in the target namespace.","Correct the --namespace flag or omit it to watch all namespaces."],"exampleFix":"// before\nserviceController, err := watchers.NewServiceController(nil, dnsctl, ns)\n// after\nif client == nil { klog.Fatalf(\"nil kubernetes client\") }\nserviceController, err := watchers.NewServiceController(client, dnsctl, ns)","handlingStrategy":"try-catch","validationCode":"if client == nil || dnsctl == nil {\n\treturn errors.New(\"client and dns controller must be non-nil before NewServiceController\")\n}","typeGuard":"func canBuildControllers(client kubernetes.Interface, dnsctl *dns.DNSController) bool {\n\treturn client != nil && dnsctl != nil\n}","tryCatchPattern":"if err := initializeWatchers(client, dnsctl, ns, watchIngress, types); err != nil {\n\tklog.Fatalf(\"failed to init watchers: %v\", err)\n}","preventionTips":["Verify RBAC (list/watch services) with the same identity dns-controller runs as.","Initialize the DNS controller before any watcher construction.","Test controller constructors against a client-go fake clientset."],"tags":["dns-controller","kubernetes","initialization"],"backgroundTag":"controller-init-failed","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}