kubernetes / kubernetes/kube-openapi

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

Open
#597 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
356
Forks
249
Avg merge
1d 15h
Merged PRs (30d)
3

Description

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](file:///usr/local/google/home/aprindle/kubernetes/vendor/k8s.io/kube-openapi/pkg/validation/strfmt/kubernetes-extensions.go).

We want to also add support for the following additional formats defined in [k/k format.go](https://github.com/kubernetes/kubernetes/blob/a08a1b633d24878176d1e41807990e9cb22fb5d0/staging/src/k8s.io/code-generator/cmd/validation-gen/validators/format.go#L130-L161):
- `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](file:///usr/local/google/home/aprindle/kubernetes/vendor/k8s.io/kube-openapi/pkg/validation/strfmt/kubernetes-extensions.go), follow the pattern used for `ShortName` and `LongName`.
2. Define a new type for each format, e.g.:
```go
// 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:
```go
func init() {
// ...
labelKey := LabelKey("")
Default.Add(k8sPrefix+"label-key", &labelKey, IsLabelKey)
}
```

Contributor guide

Open the contributing guide

Research direction

Read kubernetes-extensions.go and follow the existing ShortName and LongName implementations. Compare the requested formats with validators/format.go in Kubernetes, then add each type’s validation and registration following the stated pattern. Done means all eight formats are available for CRDs with their required methods, regular expressions, maximum lengths, and registry entries.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, kubernetes
Domain
api, backend-api-design
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.