kubernetes/kops · error
cannot interpret %q value as v1.Duration
Error message
cannot interpret %q value as v1.Duration
What it means
When a field is tagged as metav1.Duration ("v1.Duration"), setType parses the string with time.ParseDuration. Any string that is not a Go duration literal (e.g. missing unit) produces this error. It tells you the supplied value is not a valid duration for the field.
Source
Thrown at util/pkg/reflectutils/access.go:281
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})
case "resource.Quantity":
quantity, err := resource.ParseQuantity(newValue)
if err != nil {
return fmt.Errorf("cannot interpret %q value as resource.Quantity", newValue)
}
newV = reflect.ValueOf(quantity)
default:
// This handles enums and other simple conversions
newV = reflect.ValueOf(newValue)
if newV.Type().ConvertibleTo(v.Type()) {
newV = newV.Convert(v.Type())
} else {
return fmt.Errorf("unhandled type %q", t)
}View on GitHub (pinned to 4c8573c808)
Solutions
- Use time.ParseDuration syntax with units: "300s", "5m", "1h30m"
- For a plain seconds number, check whether the field is actually an int and pass 300 instead of "300s"
- Validate the value locally with `go` time.ParseDuration before running the set command
Example fix
// before kops set cluster spec.kubelet.evictionHard="nodefs.available<10" // duration example before kops set ... spec.nodeProblemDetector.monitorPeriod=30 // after kops set ... spec.nodeProblemDetector.monitorPeriod=30s
Defensive patterns
Strategy: validation
Validate before calling
d := "30s"
if _, err := time.ParseDuration(d); err != nil {
return fmt.Errorf("invalid duration %q: %v", d, err)
} Type guard
func isValidDuration(s string) bool { _, err := time.ParseDuration(s); return err == nil } Try / catch
if err := doSet(); err != nil && strings.Contains(err.Error(), "as v1.Duration") {
// retry with corrected duration string, e.g. append "s"
} Prevention
- Always include a time unit (s/m/h) in duration values
- Validate durations with time.ParseDuration before applying
- Remember these are Go durations, not plain seconds
When it happens
Trigger: `kops set cluster spec.kubelet.nodeLeaseDurationSeconds=5m` style calls on duration-tagged fields (e.g. kube-dns, node-problem-detector settings) with strings like "300", "5", or "forever" — time.ParseDuration requires a unit.
Common situations: Users copy seconds values from Kubernetes docs into duration fields, forgetting Go duration syntax; empty values from templates; locale-specific formats like "1h30" (missing m).
Understand the failure class
Background: "invalid duration" / "failed to parse duration": why your timeout, interval, or TTL string is rejected and which formats each library accepts — this error's family across 32 libraries.
Related errors
- cannot interpret %q value as unsigned integer
- ReadOnlyError
- unexpected kind for cluster, got %T, want kops.Cluster
- method CreateCluster not supported in server-side client
- method UpdateCluster not supported in server-side client
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/1ebb0e74136b6796.
Report an issue: GitHub.