{"record":{"id":"bc298b5d28369ad1","repo":"kubernetes/kops","slug":"error-setting-clientconnection-kubeconfig-in-kube","errorCode":null,"errorMessage":"error setting clientConnection.kubeconfig in kube-scheduler configuration: %w","messagePattern":"error setting clientConnection\\.kubeconfig in kube-scheduler configuration: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/model/components/kubescheduler/model.go","lineNumber":93,"sourceCode":"\tif len(matches) > 1 {\n\t\treturn nil, fmt.Errorf(\"found multiple KubeSchedulerConfiguration objects in cluster configuration; expected at most one\")\n\t}\n\n\tvar config *unstructured.Unstructured\n\tif len(matches) == 1 {\n\t\tconfig = matches[0].ToUnstructured()\n\t} else {\n\t\tconfig = &unstructured.Unstructured{}\n\t\tconfig.SetKind(\"KubeSchedulerConfiguration\")\n\t\tconfig.SetAPIVersion(\"kubescheduler.config.k8s.io/v1\")\n\t\t// We need to store the object, because we are often called repeatedly (until we converge)\n\t\tb.AdditionalObjects = append(b.AdditionalObjects, kubemanifest.NewObject(config.Object))\n\t}\n\n\t// TODO: Handle different versions? e.g. gvk := config.GroupVersionKind()\n\n\tif err := unstructured.SetNestedField(config.Object, wellknownpaths.KubeSchedulerKubeConfig, \"clientConnection\", \"kubeconfig\"); err != nil {\n\t\treturn nil, fmt.Errorf(\"error setting clientConnection.kubeconfig in kube-scheduler configuration: %w\", err)\n\t}\n\n\tkubeScheduler := b.Cluster.Spec.KubeScheduler\n\tif kubeScheduler != nil {\n\t\tif err := MapToUnstructured(kubeScheduler, config); err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t}\n\n\tconfigYAML, err := yaml.Marshal(config)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\treturn configYAML, nil\n}\n\n// MapToUnstructured reflects the options interface and extracts the parameters for the config file\nfunc MapToUnstructured(options interface{}, target *unstructured.Unstructured) error {","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/model/components/kubescheduler/model.go#L75-L111","documentation":"After selecting (or defaulting) the KubeSchedulerConfiguration, buildSchedulerConfig sets clientConnection.kubeconfig to the well-known kube-scheduler kubeconfig path via unstructured.SetNestedField. This fails only if the intermediate structure is wrong (e.g. clientConnection exists but is not a map, or the object shape is unexpected), so the wrapped error reports why the nested field could not be set.","triggerScenarios":"Calling Build → buildSchedulerConfig with a KubeSchedulerConfiguration AdditionalObject whose clientConnection field is not an object/map (e.g. a string or null leaf) so unstructured.SetNestedField cannot walk/create the path.","commonSituations":"A hand-written scheduler config YAML where clientConnection was mistyped as a scalar; a rendered template producing a malformed nested field; older config versions with a different schema.","solutions":["Inspect the KubeSchedulerConfiguration object and ensure clientConnection is a nested object (map), not a scalar","Let the builder create the default config by removing the malformed AdditionalObject","Validate the manifest with a schema tool (kubectl apply --dry-run=server) before adding it as an AdditionalObject"],"exampleFix":"# before\nclientConnection: /etc/kubernetes/kubeconfig\n# after\nclientConnection:\n  kubeconfig: /etc/kubernetes/kubeconfig","handlingStrategy":"validation","validationCode":"cc, found, err := unstructured.NestedFieldNoCopy(config.Object, \"clientConnection\")\nif found {\n    if _, ok := cc.(map[string]interface{}); !ok {\n        return fmt.Errorf(\"clientConnection must be an object, got %T\", cc)\n    }\n}","typeGuard":"func isNestedMap(v interface{}) bool {\n    _, ok := v.(map[string]interface{})\n    return ok\n}","tryCatchPattern":"if _, err := buildSchedulerConfig(b); err != nil {\n    if strings.Contains(err.Error(), \"error setting clientConnection.kubeconfig\") {\n        // drop/repair the offending KubeSchedulerConfiguration and retry with defaults\n    }\n    return err\n}","preventionTips":["Ensure clientConnection is a nested object in any supplied scheduler config","Dry-run validate manifests before adding as AdditionalObjects","Prefer letting kOps generate the default scheduler config"],"tags":["kube-scheduler","unstructured","componentconfig","manifest-validation"],"backgroundTag":"schema-validation-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"}