kubernetes/kops · error
field Name not found in %T
Error message
field Name not found in %T
What it means
Inside setType, string values targeting an env-var-style struct are split into Name/Value fields via reflection. If the destination struct type has no exported field named "Name", FieldByName fails and this error is returned. This guards against applying an env-var-shaped string to an incompatible struct type.
Source
Thrown at util/pkg/reflectutils/access.go:265
newV = reflect.ValueOf(v32)
case "uint64":
v64 := uint64(v)
newV = reflect.ValueOf(v64)
default:
panic("missing case in uint switch")
}
case "intstr.IntOrString":
newV = reflect.ValueOf(intstr.Parse(newValue))
case "kops.EnvVar":
newV = reflect.New(v.Type()).Elem()
envVarType := newV.Type()
fdName, found := envVarType.FieldByName("Name")
if !found {
return fmt.Errorf("field Name not found in %T", newV.Interface())
}
fdValue, found := envVarType.FieldByName("Value")
if !found {
return fmt.Errorf("field Value not found in %T", newV.Interface())
}
name, value, hasValue := strings.Cut(newValue, "=")
newV.FieldByIndex(fdName.Index).SetString(name)
if hasValue {
newV.FieldByIndex(fdValue.Index).SetString(value)
}
case "v1.Duration":
duration, err := time.ParseDuration(newValue)
if err != nil {
return fmt.Errorf("cannot interpret %q value as v1.Duration", newValue)
}
newV = reflect.ValueOf(metav1.Duration{Duration: duration})View on GitHub (pinned to 4c8573c808)
Solutions
- Verify the struct's reflectutils type tag: fields tagged as env-var must have Name and Value string fields
- Update the struct definition to include Name/Value fields, or change the type tag to a matching kind
- Use a field path that targets the correct field instead of the whole struct
Example fix
// before
type EnvEntry struct {
Key string
Value string
}
// after
type EnvEntry struct {
Name string
Value string
} Defensive patterns
Strategy: type-guard
Validate before calling
t := reflect.TypeOf(targetStruct)
if _, ok := t.FieldByName("Name"); !ok {
return fmt.Errorf("type %s cannot be used as env-var entry", t)
} Type guard
func isEnvVarType(v interface{}) bool {
t := reflect.TypeOf(v)
if t.Kind() == reflect.Ptr { t = t.Elem() }
_, hasName := t.FieldByName("Name")
_, hasValue := t.FieldByName("Value")
return hasName && hasValue
} Try / catch
if err := Unset/set...; err != nil && strings.Contains(err.Error(), "field Name not found") {
// struct schema mismatch; fix type tag or field
} Prevention
- Keep reflectutils type tags in sync with struct definitions
- Add unit tests covering set/unset on env-var-tagged fields
When it happens
Trigger: Calling kops set with a path whose value is treated as an env-var entry (TypeTag "env-var") while the resolved struct type lacks a Name field — essentially only possible if the type tag in the struct tag is wrong or the struct definition changed.
Common situations: Custom downstream types reusing the reflectutils tags but without Name/Value fields, or an API version change that renamed fields while stale struct tags still declare the env-var type.
Related errors
- field Value not found in %T
- conversion error for field %s: %s
- unable to convert from Quantity %v to float
- BuildFlagsList to reflect value: %s
- only accepts structs; got %T
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/0c16861fd63234f5.
Report an issue: GitHub.