Skip to content

Commit 59e82a7

Browse files
committed
encoding/jsonschema: update format support
As far as I can make out, the set of format keywords supported by CRDs is the same as that supported by the rest of the Kubernetes API. We had been following the official Kubernetes documentation ([1], [2]) for supported keywords, but this is not definitive. The actual code ([3]) gives us a better idea. We also fix the `byte` format which had been corrupted in passing ([4]) (not that it makes any difference, given that it's not supported yet). Relevant issue: kubernetes/kubernetes#131082 [1] https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#format [2] https://github.com/kubernetes/apiextensions-apiserver/blob/887679f927f8ed53c2d0660e720da42419c6ee93/pkg/apis/apiextensions/v1/types_jsonschema.go#L47-L72 [3] https://github.com/kubernetes/kube-openapi/tree/c8a335a9a2ffc5aff16dfef74896a1ee34eb235d/pkg/validation [4] https://review.gerrithub.io/c/cue-lang/cue/+/1211200 Signed-off-by: Roger Peppe <[email protected]> Change-Id: Ie2279fd12bba5348d8a62fe3bd116e4daa9b225d Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1214771 Reviewed-by: Daniel Martí <[email protected]> TryBot-Result: CUEcueckoo <[email protected]> Unity-Result: CUE porcuepine <[email protected]>
1 parent 4e8dc78 commit 59e82a7

File tree

2 files changed

+39
-29
lines changed

2 files changed

+39
-29
lines changed

encoding/jsonschema/constraints_format.go

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -33,48 +33,50 @@ type formatFuncInfo struct {
3333
var formatFuncs = sync.OnceValue(func() map[string]formatFuncInfo {
3434
return map[string]formatFuncInfo{
3535
"binary": {openAPI, formatTODO},
36-
"bsonobjectid": {k8sCRD, formatTODO},
37-
"byte|k8sCRD": {openAPI, formatTODO},
38-
"cidr": {k8sCRD, formatTODO},
39-
"creditcard": {k8sCRD, formatTODO},
36+
"bsonobjectid": {k8s, formatTODO},
37+
"byte": {openAPI | k8s, formatTODO},
38+
"cidr": {k8s, formatTODO},
39+
"creditcard": {k8s, formatTODO},
4040
"data": {openAPI, formatTODO},
41-
"date": {vfrom(VersionDraft7) | openAPI | k8sCRD, formatDate},
41+
"date": {vfrom(VersionDraft7) | openAPI | k8s, formatDate},
4242
"date-time": {allVersions | openAPI, formatDateTime},
43-
"datetime": {k8sCRD, formatDateTime},
44-
"double": {openAPI, formatTODO},
45-
"duration": {vfrom(VersionDraft2019_09) | k8sCRD, formatTODO},
46-
"email": {allVersions | openAPI | k8sCRD, formatTODO},
47-
"float": {openAPI, formatTODO},
48-
"hexcolor": {k8sCRD, formatTODO},
49-
"hostname": {allVersions | openAPI | k8sCRD, formatTODO},
43+
"datetime": {k8s, formatDateTime},
44+
"double": {openAPI | k8s, formatTODO},
45+
"duration": {vfrom(VersionDraft2019_09) | k8s, formatTODO},
46+
"email": {allVersions | openAPI | k8s, formatTODO},
47+
"float": {openAPI | k8s, formatTODO},
48+
"hexcolor": {k8s, formatTODO},
49+
"hostname": {allVersions | openAPI | k8s, formatTODO},
5050
"idn-email": {vfrom(VersionDraft7), formatTODO},
5151
"idn-hostname": {vfrom(VersionDraft7), formatTODO},
52-
"int32": {openAPI, formatInt32},
53-
"int64": {openAPI, formatInt64},
54-
"ipv4": {allVersions | openAPI | k8sCRD, formatTODO},
55-
"ipv6": {allVersions | openAPI | k8sCRD, formatTODO},
52+
"int32": {openAPI | k8s, formatInt32},
53+
"int64": {openAPI | k8s, formatInt64},
54+
"ipv4": {allVersions | openAPI | k8s, formatTODO},
55+
"ipv6": {allVersions | openAPI | k8s, formatTODO},
5656
"iri": {vfrom(VersionDraft7), formatURI},
5757
"iri-reference": {vfrom(VersionDraft7), formatURIReference},
58-
"isbn": {k8sCRD, formatTODO},
59-
"isbn10": {k8sCRD, formatTODO},
60-
"isbn13": {k8sCRD, formatTODO},
58+
"isbn": {k8s, formatTODO},
59+
"isbn10": {k8s, formatTODO},
60+
"isbn13": {k8s, formatTODO},
6161
"json-pointer": {vfrom(VersionDraft6), formatTODO},
62-
"mac": {k8sCRD, formatTODO},
63-
"password": {openAPI | k8sCRD, formatTODO},
62+
"mac": {k8s, formatTODO},
63+
"password": {openAPI | k8s, formatTODO},
6464
"regex": {vfrom(VersionDraft7), formatRegex},
6565
"relative-json-pointer": {vfrom(VersionDraft7), formatTODO},
66-
"rgbcolor": {k8sCRD, formatTODO},
67-
"ssn": {k8sCRD, formatTODO},
66+
"rgbcolor": {k8s, formatTODO},
67+
"ssn": {k8s, formatTODO},
6868
"time": {vfrom(VersionDraft7), formatTODO},
69+
"uint32": {k8s, formatUint32},
70+
"uint64": {k8s, formatUint64},
6971
// TODO we should probably disallow non-ASCII URIs (IRIs) but
7072
// this is good enough for now.
71-
"uri": {allVersions | openAPI | k8sCRD, formatURI},
73+
"uri": {allVersions | openAPI | k8s, formatURI},
7274
"uri-reference": {vfrom(VersionDraft6), formatURIReference},
7375
"uri-template": {vfrom(VersionDraft6), formatTODO},
74-
"uuid": {vfrom(VersionDraft2019_09) | k8sCRD, formatTODO},
75-
"uuid3": {k8sCRD, formatTODO},
76-
"uuid4": {k8sCRD, formatTODO},
77-
"uuid5": {k8sCRD, formatTODO},
76+
"uuid": {vfrom(VersionDraft2019_09) | k8s, formatTODO},
77+
"uuid3": {k8s, formatTODO},
78+
"uuid4": {k8s, formatTODO},
79+
"uuid5": {k8s, formatTODO},
7880
}
7981
})
8082

@@ -144,4 +146,12 @@ func formatInt64(n cue.Value, s *state) {
144146
s.add(n, numType, ast.NewIdent("int64"))
145147
}
146148

149+
func formatUint32(n cue.Value, s *state) {
150+
s.add(n, numType, ast.NewIdent("uint32"))
151+
}
152+
153+
func formatUint64(n cue.Value, s *state) {
154+
s.add(n, numType, ast.NewIdent("uint64"))
155+
}
156+
147157
func formatTODO(n cue.Value, s *state) {}

encoding/jsonschema/testdata/txtar/crd_simple.txtar

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ _embeddedResource
3737
spec?: {
3838
...
3939
}
40-
intField?: number
40+
intField?: uint32
4141

4242
_embeddedResource: {
4343
apiVersion!: string

0 commit comments

Comments
 (0)