kubernetes/kops · error
conversion error for field %s: %s
Error message
conversion error for field %s: %s
What it means
During BuildConfigYaml's reflective walk, for every field carrying a `configfile` tag the code resolves the corresponding target field via getValueFromStruct(flagName, target). If that lookup fails, the error is wrapped as "conversion error for field %s". It means the flag name in the configfile tag does not map to a valid field path in the target struct.
Source
Thrown at pkg/configbuilder/buildconfigfile.go:56
}
tag := field.Tag.Get("configfile")
if tag == "" {
klog.V(4).Infof("not writing field with no configfile tag: %s", path)
// We want to descend - it could be a structure containing flags
return nil
}
if tag == "-" {
klog.V(4).Infof("skipping field with %q configfile tag: %s", tag, path)
return reflectutils.SkipReflection
}
tokens := strings.Split(tag, ",")
flagName := tokens[0]
targetValue, error := getValueFromStruct(flagName, target)
if error != nil {
return fmt.Errorf("conversion error for field %s: %s", flagName, error)
}
// We do have to do this, even though the recursive walk will do it for us
// because when we descend we won't have `field` set
if val.Kind() == reflect.Ptr {
if val.IsNil() {
return nil
}
}
switch v := val.Interface().(type) {
case *resource.Quantity:
floatVal, err := strconv.ParseFloat(v.AsDec().String(), 64)
if err != nil {
return fmt.Errorf("unable to convert from Quantity %v to float", v)
}
targetValue.Set(reflect.ValueOf(&floatVal))
default:
targetValue.Set(val)
}View on GitHub (pinned to 4c8573c808)
Solutions
- Check the `configfile` tag of the field named in the error and compare it with the actual field names in the target struct
- Fix the dotted flag path in the tag so each segment matches a real exported struct field (FieldByName is case-sensitive)
- If the target field was removed upstream, either add it back to the target struct or drop/rename the configfile tag
- Add a unit test walking BuildConfigYaml over the full options struct to catch tag/target mismatches early
Example fix
// before KubeLeaderElection *KubeLeaderElection `json:"leaderElection,omitempty" configfile:"leader-elect"` // after (target has LeaderElect under LeaderElection struct) KubeLeaderElection *KubeLeaderElection `json:"leaderElection,omitempty" configfile:"leaderElection.LeaderElect"`
Defensive patterns
Strategy: validation
Validate before calling
func tagTargetsExist(options interface{}, target interface{}) error {
var errs []string
walkTags(options, func(path, tag string) {
if tag == "" || tag == "-" { return }
flag := strings.Split(tag, ",")[0]
if _, err := getValueFromStruct(flag, target); err != nil {
errs = append(errs, fmt.Sprintf("%s -> %q: %v", path, flag, err))
}
})
if len(errs) > 0 { return fmt.Errorf(strings.Join(errs, "; ")) }
return nil
} Try / catch
targetValue, err := getValueFromStruct(flagName, target)
if err != nil {
return fmt.Errorf("conversion error for field %s: %w", flagName, err)
} Prevention
- Keep configfile tag paths in sync with the target struct field names; grep both sides when renaming fields
- FieldByName is case-sensitive — match exported Go field names exactly in dotted paths
- Add a CI test that walks every tagged field and resolves it against the target struct
- Use dotted paths only through nested structs, never through maps/slices
When it happens
Trigger: A `configfile:"some.flag"` struct tag on a KubeSchedulerConfig field names a dotted path whose field does not exist in the target struct, or the path traverses through a non-struct (e.g. a map, slice, or interface) before reaching the named field.
Common situations: Renaming a field in the target config struct (e.g. a component-config type from apimachinery) without updating the configfile tag; adding a new tagged field to KubeSchedulerConfig whose flag name was mistyped; version drift between kops' KubeSchedulerConfig and the upstream component config struct.
Related errors
- only accepts structs; got %T
- unable to convert from Quantity %v to float
- BuildFlagsList to reflect value: %s
- cannot parse flag spec: %q
- unhandled type %v %q
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/26cc2a5fb8da6236.
Report an issue: GitHub.