{"record":{"id":"d021f58df30ffae8","repo":"kubernetes/kops","slug":"building-kubernetes-client-for-node-labeler-w","errorCode":null,"errorMessage":"building kubernetes client for node labeler: %w","messagePattern":"building kubernetes client for node labeler: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"channels/pkg/cmd/apply_channel.go","lineNumber":109,"sourceCode":"\t\t\treturn nil, fmt.Errorf(\"Error too many '=' (%d) in %s\", len(pair), pair)\n\t\t} else if len(pair) == 2 {\n\t\t\tlabels[pair[0]] = pair[1]\n\t\t} else {\n\t\t\tlabels[rawpair] = \"\"\n\t\t}\n\t}\n\treturn labels, nil\n}\n\n// runApplyChannelIteration patches node labels (when --node-name is set) then\n// applies the channel. Labels go first so addons targeting the control-plane\n// label can schedule on the local node as soon as their manifests land.\nfunc runApplyChannelIteration(ctx context.Context, f *ChannelsFactory, out io.Writer, options *ApplyChannelOptions, args []string) error {\n\tvar merr error\n\tif options.NodeName != \"\" {\n\t\tlabelerClient, err := f.KubernetesClient()\n\t\tif err != nil {\n\t\t\tmerr = multierr.Append(merr, fmt.Errorf(\"building kubernetes client for node labeler: %w\", err))\n\t\t} else if err := nodelabeler.BootstrapControlPlaneNodeLabels(ctx, labelerClient, options.NodeName, options.NodeLabels); err != nil {\n\t\t\tmerr = multierr.Append(merr, fmt.Errorf(\"bootstrapping node labels: %w\", err))\n\t\t}\n\t}\n\tif err := RunApplyChannel(ctx, f, out, options, args); err != nil {\n\t\tmerr = multierr.Append(merr, err)\n\t}\n\treturn merr\n}\n\n// runApplyChannelLoop reconciles repeatedly until ctx is cancelled. A fresh\n// ChannelsFactory per iteration drops cached REST configs and the discovery\n// cache, picking up cert rotation and new CRDs without a restart.\nfunc runApplyChannelLoop(ctx context.Context, out io.Writer, options *ApplyChannelOptions, args []string) error {\n\t// In daemon mode kops-channels runs as a system-node-critical static pod; serve a\n\t// readiness probe reporting the last apply outcome, so a persistent failure surfaces\n\t// as NotReady (failing `kops validate cluster`, which gates rolling updates) instead\n\t// of only being logged. Starts NotReady until the first successful apply.","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/channels/pkg/cmd/apply_channel.go#L91-L127","documentation":"runApplyChannelIteration wraps any failure from f.KubernetesClient() with this message when --node-name is set, before node labels can be bootstrapped. The underlying error comes from constructing a clientset from the REST config (bad kubeconfig, unreachable apiserver, TLS problems). It is accumulated into a multierr alongside any channel-apply failure.","triggerScenarios":"`kops channels --node-name <node>` where the Kubernetes client cannot be built: in-cluster config unavailable (not running in a pod, missing KUBERNETES_SERVICE_HOST), invalid or missing kubeconfig, or malformed REST config from the factory.","commonSituations":"Running the binary locally without a kubeconfig when it expects in-cluster config; a static pod missing service-account mounts; KUBECONFIG pointing at a deleted context; registry/auth plugin errors.","solutions":["Ensure the kubeconfig or in-cluster service account is present and valid (KUBECONFIG, /var/run/secrets/kubernetes.io/serviceaccount)","Run `kubectl version` with the same config to confirm the client can reach the cluster","If in a pod, verify the service account token and KUBERNETES_SERVICE_HOST/PORT env are set","Inspect the wrapped inner error for the exact config problem"],"exampleFix":"// before (no config found)\nkops channels --node-name ip-10-0-0-5\n// after\nKUBECONFIG=/etc/kubernetes/admin.conf kops channels --node-name ip-10-0-0-5","handlingStrategy":"try-catch","validationCode":"// Go: verify client construction before calling\nif _, err := f.KubernetesClient(); err != nil {\n\treturn fmt.Errorf(\"precheck: kubernetes client unavailable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"err := runApplyChannelIteration(ctx, f, out, options, args)\nif err != nil && strings.Contains(err.Error(), \"building kubernetes client for node labeler\") {\n\t// inspect wrapped cause with errors.Unwrap / %v inner error\n\tklog.Errorf(\"client init failed, check kubeconfig/in-cluster config: %v\", err)\n}","preventionTips":["Mount the service-account token when running in-pod","Set KUBECONFIG explicitly in scripts","Verify with `kubectl version` before invoking kops channels","Refresh kubeconfig after cluster rebuilds"],"tags":["kubernetes","client-init","configuration","kubeconfig"],"backgroundTag":"kube-client-init-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"}