Skip to content

Add support for Kubernetes-specific string formats added in Kubernetes Declarative Validation tags (+k8s:format=*) #597

Description

@aaron-prindle

The Kubernetes Declarative Validation feature uses several custom string formats for validation in native types. This issue tracks making these formats available for CustomResourceDefinitions (CRDs).

Currently, kube-openapi supports k8s-short-name and k8s-long-name in kubernetes-extensions.go.

We want to also add support for the following additional formats defined in k/k format.go:

  • k8s-extended-resource-name
  • k8s-label-key
  • k8s-label-value
  • k8s-long-name-caseless
  • k8s-path-segment-name
  • k8s-resource-fully-qualified-name
  • k8s-resource-pool-name
  • k8s-uuid

Likely Implementation Steps (based on existing formats):

  1. In kubernetes-extensions.go, follow the pattern used for ShortName and LongName.
  2. Define a new type for each format, e.g.:
    // swagger:strfmt k8s-label-key
    type LabelKey string
  3. Implement required methods for the type (MarshalText, UnmarshalText, MarshalJSON, UnmarshalJSON, DeepCopyInto, DeepCopy, String).
  4. Define a regular expression and max length for validation.
  5. Register the format in the init() function:
    func init() {
        // ...
        labelKey := LabelKey("")
        Default.Add(k8sPrefix+"label-key", &labelKey, IsLabelKey)
    }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions