{"record":{"id":"c39f84788f265198","repo":"kubernetes/kops","slug":"error-marshaling-pod-to-yaml-v","errorCode":null,"errorMessage":"error marshaling pod to yaml: %v","messagePattern":"error marshaling pod to yaml: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nodeup/pkg/model/kube_controller_manager.go","lineNumber":81,"sourceCode":"\n\tif err := b.BuildPrivateKeyTask(c, \"service-account\", pathSrvKCM, \"service-account\", nil, nil); err != nil {\n\t\treturn err\n\t}\n\tkcm.ServiceAccountPrivateKeyFile = filepath.Join(pathSrvKCM, \"service-account.key\")\n\n\tif err := b.writeServerCertificate(c, &kcm); err != nil {\n\t\treturn err\n\t}\n\n\t{\n\t\tpod, err := b.buildPod(&kcm)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error building kube-controller-manager pod: %v\", err)\n\t\t}\n\n\t\tmanifest, err := k8scodecs.ToVersionedYaml(pod)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error marshaling pod to yaml: %v\", err)\n\t\t}\n\n\t\tc.AddTask(&nodetasks.File{\n\t\t\tPath:     \"/etc/kubernetes/manifests/kube-controller-manager.manifest\",\n\t\t\tContents: fi.NewBytesResource(manifest),\n\t\t\tType:     nodetasks.FileType_File,\n\t\t})\n\t}\n\n\t{\n\t\tc.AddTask(&nodetasks.File{\n\t\t\tPath:        \"/var/log/kube-controller-manager.log\",\n\t\t\tContents:    fi.NewStringResource(\"\"),\n\t\t\tType:        nodetasks.FileType_File,\n\t\t\tMode:        s(\"0400\"),\n\t\t\tIfNotExists: true,\n\t\t})\n\t}","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/nodeup/pkg/model/kube_controller_manager.go#L63-L99","documentation":"nodeup's KubeControllerManagerBuilder.Build renders the static pod manifest for kube-controller-manager. After building the pod spec it serializes it with k8scodecs.ToVersionedYaml; if that conversion to versioned YAML fails, the underlying codec error is wrapped as 'error marshaling pod to yaml'. This indicates the in-memory pod object could not be converted to a versioned YAML representation.","triggerScenarios":"k8scodecs.ToVersionedYaml(pod) returns an error, typically because the pod object contains fields that cannot be converted to the target API version (invalid/unknown fields, nil objects in required positions, or a bad conversion scheme in the codecs setup).","commonSituations":"kops/nodeup version mismatch where the KubeControllerManagerConfig produced fields not representable in the target manifest API version; corrupt cluster spec values injected into the pod; bugs in the codec scheme initialization; custom builds with modified pod structures.","solutions":["Check the wrapped %v detail in the error message to identify which pod field failed conversion","Verify the kops binary and nodeup version match the cluster spec version (run kops upgrade / use matching release)","Validate the cluster spec (kops validate / inspect KubeControllerManagerConfig values) for invalid or unsupported fields","If reproducible, file an issue with the kops project including the wrapped error text; this is rarely caused by user config alone"],"exampleFix":"// before (nodeup binary older than cluster spec)\nkops update cluster --yes   # with mismatched kops/nodeup versions\n// after\nmake kops && make nodeup    # rebuild both from the same source\nkops update cluster --yes","handlingStrategy":"try-catch","validationCode":"if pod == nil || pod.Spec.Containers == nil {\n    return fmt.Errorf(\"kube-controller-manager pod incomplete before marshal\")\n}\nif _, err := json.Marshal(pod); err != nil {\n    return fmt.Errorf(\"pod not serializable: %v\", err)\n}","typeGuard":"func isMarshalErr(err error) bool {\n    return err != nil && strings.Contains(err.Error(), \"error marshaling pod to yaml\")\n}","tryCatchPattern":"manifest, err := k8scodecs.ToVersionedYaml(pod)\nif err != nil {\n    return fmt.Errorf(\"error marshaling pod to yaml: %v\", err)\n}\n// caller:\nif err := b.Build(c, ...); err != nil {\n    if isMarshalErr(err) { /* log pod spec, fix config or version skew */ }\n    return err\n}","preventionTips":["Keep kops and nodeup binaries on the exact same version","Never hand-edit generated NodeupConfig or pod templates","Validate the cluster spec after every kops upgrade before updating nodes","Log the full wrapped error text to identify the failing field"],"tags":["go","kubernetes","nodeup","yaml-marshaling"],"backgroundTag":"yaml-marshaling-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"}