kubernetes/kops · error
field %q in %s not found
Error message
field %q in %s not found
What it means
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.
Source
Thrown at pkg/kubemanifest/manifest.go:228
if !found {
return ""
}
s, ok := v.(string)
if !ok {
return ""
}
return s
}
// Reparse parses a subfield from an object
func (m *Object) Reparse(obj interface{}, fields ...string) error {
humanFields := strings.Join(fields, ".")
current := m.data
for _, field := range fields {
v, found := current[field]
if !found {
return fmt.Errorf("field %q in %s not found", field, humanFields)
}
m, ok := v.(map[string]interface{})
if !ok {
return fmt.Errorf("field %q in %s was not an object, was %T", field, humanFields, v)
}
current = m
}
b, err := yaml.Marshal(current)
if err != nil {
return fmt.Errorf("error marshaling %s to yaml: %v", humanFields, err)
}
if err := yaml.Unmarshal(b, obj); err != nil {
return fmt.Errorf("error unmarshaling subobject %s: %v", humanFields, err)
}
View on GitHub (pinned to 4c8573c808)
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
Example fix
// before: applying to any object
for _, obj := range objects { obj.Reparse([]string{"spec","template","spec"}, ...); }
// after: guard by kind
for _, obj := range objects {
if obj.GetKind() == "Deployment" || obj.GetKind() == "DaemonSet" {
obj.Reparse([]string{"spec","template","spec"}, ...)
}
} Defensive patterns
Strategy: validation
Validate before calling
func hasField(obj *kubemanifest.Object, path ...string) bool {
cur, err := obj.ToJSONMap() // or access internal data via exported accessor
if err != nil { return false }
for _, f := range path {
m, ok := cur[f].(map[string]interface{})
if !ok { return false }
cur = m
}
return true
}
Type guard
func isPodSpecHolder(kind string) bool {
switch kind {
case "Deployment", "DaemonSet", "StatefulSet", "Pod", "Job", "CronJob":
return true
}
return false
}
Try / catch
err := obj.Reparse([]string{"spec","template","spec"}, &podSpec)
if err != nil && strings.Contains(err.Error(), "not found") {
// skip objects without the path instead of failing
return nil
}
Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- rewriting channels manifest: %w
- field %q in %s was not an object, was %T
- ReadOnlyError
- error parsing addons or manifest: %v
- failed to parse objects: %w
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/7f84565e6542ad00.
Report an issue: GitHub.