{"record":{"id":"4aee7ae8de28195f","repo":"kubernetes/kops","slug":"error-building-corev1-client-v","errorCode":null,"errorMessage":"error building corev1 client: %v","messagePattern":"error building corev1 client: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kops-controller/controllers/awsipam.go","lineNumber":54,"sourceCode":"\tcorev1client \"k8s.io/client-go/kubernetes/typed/core/v1\"\n\t\"k8s.io/klog/v2\"\n\t\"k8s.io/kops/util/pkg/awslog\"\n\tctrl \"sigs.k8s.io/controller-runtime\"\n\t\"sigs.k8s.io/controller-runtime/pkg/client\"\n\t\"sigs.k8s.io/controller-runtime/pkg/manager\"\n)\n\n// NewAWSIPAMReconciler is the constructor for a IPAMReconciler\nfunc NewAWSIPAMReconciler(ctx context.Context, mgr manager.Manager) (*AWSIPAMReconciler, error) {\n\tklog.Info(\"Starting aws ipam controller\")\n\tr := &AWSIPAMReconciler{\n\t\tclient: mgr.GetClient(),\n\t\tlog:    ctrl.Log.WithName(\"controllers\").WithName(\"IPAM\"),\n\t}\n\n\tcoreClient, err := corev1client.NewForConfig(mgr.GetConfig())\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error building corev1 client: %v\", err)\n\t}\n\tr.coreV1Client = coreClient\n\n\tconfig, err := awsconfig.LoadDefaultConfig(ctx, awslog.WithAWSLogger())\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error loading default AWS config: %v\", err)\n\t}\n\n\tmetadata := imds.NewFromConfig(config)\n\n\tresp, err := metadata.GetRegion(ctx, &imds.GetRegionInput{})\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error querying ec2 metadata service (for region): %v\", err)\n\t}\n\n\tec2Config := config.Copy()\n\tec2Config.Region = resp.Region\n\tr.ec2Client = ec2.NewFromConfig(ec2Config)","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/cmd/kops-controller/controllers/awsipam.go#L36-L72","documentation":"NewAWSIPAMReconciler builds a typed client-go CoreV1Client from the controller-runtime manager's rest.Config via corev1client.NewForConfig. This error is returned when that client construction fails, with the underlying cause embedded via %v. It almost always indicates an invalid REST configuration rather than a connectivity problem.","triggerScenarios":"Calling NewAWSIPAMReconciler (from setupCloudIPAM) when mgr.GetConfig() yields a rest.Config that NewForConfig cannot use — e.g. nil/empty host, unparsable API URL, or missing/invalid TLS material.","commonSituations":"Running kops-controller outside the cluster without a valid kubeconfig; KUBERNETES_SERVICE_HOST/PORT unset so the in-cluster config is broken; a malformed --server flag or corrupted kubeconfig mounted into the controller pod.","solutions":["Inspect the %v cause after this message — it names the invalid config field (e.g. host must be a URL).","When running locally, set KUBECONFIG or pass a valid kubeconfig so the manager's rest.Config has a reachable API server host.","Verify the controller is running in-cluster with a mounted service-account token and KUBERNETES_SERVICE_HOST/PORT set.","Check that the rest.Config's CA data / bearer token files exist and are readable."],"exampleFix":"// before (local dev, no kubeconfig)\nctrl.NewManager(ctrl.GetConfigOrDie(), ...)\n// after\nexport KUBECONFIG=~/.kube/config\n// or in-cluster, ensure the pod has its service account mounted and RBAC for nodes","handlingStrategy":"try-catch","validationCode":"cfg, err := ctrl.GetConfig()\nif err != nil {\n    return fmt.Errorf(\"no usable kube config: %w\", err)\n}\nif cfg.Host == \"\" {\n    return fmt.Errorf(\"kube config host is empty; set KUBECONFIG or run in-cluster\")\n}","typeGuard":null,"tryCatchPattern":"rec, err := NewAWSIPAMReconciler(ctx, mgr)\nif err != nil {\n    if strings.Contains(err.Error(), \"error building corev1 client\") {\n        return fmt.Errorf(\"check kubeconfig / in-cluster service account: %w\", err)\n    }\n    return err\n}","preventionTips":["Run kops-controller in-cluster with a mounted service account, or set KUBECONFIG when developing locally.","Validate rest.Config (host URL, CA, token) before creating the manager.","Grant RBAC for nodes get/list/watch/patch per the kubebuilder marker."],"tags":["kubernetes","client-go","controller-runtime","aws-ipam"],"backgroundTag":"invalid-kubeconfig","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"}