Skip to content

'2w' is not valid duration #347

@nissy-dev

Description

@nissy-dev

This issue is similar to #300

Summary

Kubernetes API machinery allows duration fields to be specified using either:

  • Go time.ParseDuration format, or
  • Scala duration format

duration: a duration string like "22 ns" as parsed by Golang time.ParseDuration or compatible with Scala duration format

https://github.com/kubernetes/apiextensions-apiserver/blob/1ecd29f74da0639e2e6e3b8fac0c9bfd217e05eb/pkg/apis/apiextensions/v1/types_jsonschema.go#L71

However, kubeconform only accepts:

  • Go time.ParseDuration format, and
  • ISO 8601 duration format

See:

// validateDuration is a custom validator for the duration format
// as JSONSchema only supports the ISO 8601 format, i.e. `PT1H30M`,
// while Kubernetes API machinery expects the Go duration format, i.e. `1h30m`
// which is commonly used in Kubernetes operators for specifying intervals.
// https://github.com/kubernetes/apiextensions-apiserver/blob/1ecd29f74da0639e2e6e3b8fac0c9bfd217e05eb/pkg/apis/apiextensions/v1/types_jsonschema.go#L71

Issue

Because kubeconform does not support Scala duration format, values that are valid in Kubernetes — such as 2w (2 weeks) — are incorrectly treated as invalid by kubeconform.

Examples of valid Kubernetes durations rejected by kubeconform:

  • 2w
  • 3d
  • 1h30m
  • Values valid under Scala duration rules but not under Go's time.ParseDuration

Expected Behavior

kubeconform should accept all duration formats that Kubernetes itself considers valid, including Scala duration format.

Actual Behavior

Duration values valid in Kubernetes but formatted according to Scala duration rules are rejected as invalid during validation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions