{"record":{"id":"7f84565e6542ad00","repo":"kubernetes/kops","slug":"field-q-in-s-not-found","errorCode":null,"errorMessage":"field %q in %s not found","messagePattern":"field %q in (.+?) not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/kubemanifest/manifest.go","lineNumber":228,"sourceCode":"\tif !found {\n\t\treturn \"\"\n\t}\n\ts, ok := v.(string)\n\tif !ok {\n\t\treturn \"\"\n\t}\n\treturn s\n}\n\n// Reparse parses a subfield from an object\nfunc (m *Object) Reparse(obj interface{}, fields ...string) error {\n\thumanFields := strings.Join(fields, \".\")\n\n\tcurrent := m.data\n\tfor _, field := range fields {\n\t\tv, found := current[field]\n\t\tif !found {\n\t\t\treturn fmt.Errorf(\"field %q in %s not found\", field, humanFields)\n\t\t}\n\n\t\tm, ok := v.(map[string]interface{})\n\t\tif !ok {\n\t\t\treturn fmt.Errorf(\"field %q in %s was not an object, was %T\", field, humanFields, v)\n\t\t}\n\t\tcurrent = m\n\t}\n\n\tb, err := yaml.Marshal(current)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error marshaling %s to yaml: %v\", humanFields, err)\n\t}\n\n\tif err := yaml.Unmarshal(b, obj); err != nil {\n\t\treturn fmt.Errorf(\"error unmarshaling subobject %s: %v\", humanFields, err)\n\t}\n","sourceCodeStart":210,"sourceCodeEnd":246,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/kubemanifest/manifest.go#L210-L246","documentation":"Reparse navigates the manifest's data map along a dotted field path (e.g. spec.template.spec) and re-marshals the sub-object into a typed struct. If any segment of the path is absent from the map, this error reports which field within which path was missing, failing the reparse.","triggerScenarios":"Calling Reparse with a fields path that doesn't exist on the manifest — e.g. addPodSpecLabels on a manifest lacking spec.template.spec, or on an object of the wrong kind where the expected nesting is absent.","commonSituations":"Applying label-rewriting to addon manifests that don't contain a pod spec (e.g. ConfigMaps, CRDs, or objects missing containers); typos in the field path.","solutions":["Verify the manifest kind actually contains the path (e.g. Deployment with spec.template.spec)","Check ObjectList filtering — only apply Reparse to objects with the expected structure/kind","Correct the fields path passed to Reparse","Add a nil/exists check on the manifest structure before calling Reparse"],"exampleFix":"// before: applying to any object\nfor _, obj := range objects { obj.Reparse([]string{\"spec\",\"template\",\"spec\"}, ...); }\n// after: guard by kind\nfor _, obj := range objects {\n  if obj.GetKind() == \"Deployment\" || obj.GetKind() == \"DaemonSet\" {\n    obj.Reparse([]string{\"spec\",\"template\",\"spec\"}, ...)\n  }\n}","handlingStrategy":"validation","validationCode":"func hasField(obj *kubemanifest.Object, path ...string) bool {\n\tcur, err := obj.ToJSONMap() // or access internal data via exported accessor\n\tif err != nil { return false }\n\tfor _, f := range path {\n\t\tm, ok := cur[f].(map[string]interface{})\n\t\tif !ok { return false }\n\t\tcur = m\n\t}\n\treturn true\n}\n","typeGuard":"func isPodSpecHolder(kind string) bool {\n\tswitch kind {\n\tcase \"Deployment\", \"DaemonSet\", \"StatefulSet\", \"Pod\", \"Job\", \"CronJob\":\n\t\treturn true\n\t}\n\treturn false\n}\n","tryCatchPattern":"err := obj.Reparse([]string{\"spec\",\"template\",\"spec\"}, &podSpec)\nif err != nil && strings.Contains(err.Error(), \"not found\") {\n\t// skip objects without the path instead of failing\n\treturn nil\n}\n","preventionTips":["Filter ObjectList by kind before Reparse","Confirm field paths against the manifest's API version","Skip non-pod objects when rewriting pod specs","Log kind/name of objects that fail reparse"],"tags":["manifest","path-navigation","go"],"backgroundTag":"manifest-field-not-found","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"}