Skip to content

Commit f5dffba

Browse files
authored
Merge pull request #381 from arjunrn/quantities-intstr
✨ Change Quantity type to int-or-string
2 parents 0dd9d80 + f6c370c commit f5dffba

File tree

2 files changed

+57
-15
lines changed

2 files changed

+57
-15
lines changed

pkg/crd/known_types.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,12 @@ var KnownPackages = map[string]PackageOverride{
5555
"k8s.io/apimachinery/pkg/api/resource": func(p *Parser, pkg *loader.Package) {
5656
p.Schemata[TypeIdent{Name: "Quantity", Package: pkg}] = apiext.JSONSchemaProps{
5757
// TODO(directxman12): regexp validation for this (or get kube to support it as a format value)
58-
Type: "string",
58+
XIntOrString: true,
59+
AnyOf: []apiext.JSONSchemaProps{
60+
{Type: "integer"},
61+
{Type: "string"},
62+
},
63+
Pattern: "^(\\+|-)?(([0-9]+(\\.[0-9]*)?)|(\\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\\+|-)?(([0-9]+(\\.[0-9]*)?)|(\\.[0-9]+))))?$",
5964
}
6065
// No point in calling AddPackage, this is the sole inhabitant
6166
},

pkg/crd/testdata/testdata.kubebuilder.io_cronjobs.yaml

Lines changed: 51 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,10 +1103,14 @@ spec:
11031103
for env vars'
11041104
type: string
11051105
divisor:
1106+
anyOf:
1107+
- type: integer
1108+
- type: string
11061109
description: Specifies the output
11071110
format of the exposed resources,
11081111
defaults to "1"
1109-
type: string
1112+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
1113+
x-kubernetes-int-or-string: true
11101114
resource:
11111115
description: 'Required: resource
11121116
to select'
@@ -1767,14 +1771,22 @@ spec:
17671771
properties:
17681772
limits:
17691773
additionalProperties:
1770-
type: string
1774+
anyOf:
1775+
- type: integer
1776+
- type: string
1777+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
1778+
x-kubernetes-int-or-string: true
17711779
description: 'Limits describes the maximum
17721780
amount of compute resources allowed. More
17731781
info: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/'
17741782
type: object
17751783
requests:
17761784
additionalProperties:
1777-
type: string
1785+
anyOf:
1786+
- type: integer
1787+
- type: string
1788+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
1789+
x-kubernetes-int-or-string: true
17781790
description: 'Requests describes the minimum
17791791
amount of compute resources required.
17801792
If Requests is omitted for a container,
@@ -2300,10 +2312,14 @@ spec:
23002312
for env vars'
23012313
type: string
23022314
divisor:
2315+
anyOf:
2316+
- type: integer
2317+
- type: string
23032318
description: Specifies the output
23042319
format of the exposed resources,
23052320
defaults to "1"
2306-
type: string
2321+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
2322+
x-kubernetes-int-or-string: true
23072323
resource:
23082324
description: 'Required: resource
23092325
to select'
@@ -2964,14 +2980,22 @@ spec:
29642980
properties:
29652981
limits:
29662982
additionalProperties:
2967-
type: string
2983+
anyOf:
2984+
- type: integer
2985+
- type: string
2986+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
2987+
x-kubernetes-int-or-string: true
29682988
description: 'Limits describes the maximum
29692989
amount of compute resources allowed. More
29702990
info: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/'
29712991
type: object
29722992
requests:
29732993
additionalProperties:
2974-
type: string
2994+
anyOf:
2995+
- type: integer
2996+
- type: string
2997+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
2998+
x-kubernetes-int-or-string: true
29752999
description: 'Requests describes the minimum
29763000
amount of compute resources required.
29773001
If Requests is omitted for a container,
@@ -3929,10 +3953,14 @@ spec:
39293953
for env vars'
39303954
type: string
39313955
divisor:
3956+
anyOf:
3957+
- type: integer
3958+
- type: string
39323959
description: Specifies the output
39333960
format of the exposed resources,
39343961
defaults to "1"
3935-
type: string
3962+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
3963+
x-kubernetes-int-or-string: true
39363964
resource:
39373965
description: 'Required: resource
39383966
to select'
@@ -3958,6 +3986,9 @@ spec:
39583986
or Memory. More info: https://kubernetes.io/docs/concepts/storage/volumes#emptydir'
39593987
type: string
39603988
sizeLimit:
3989+
anyOf:
3990+
- type: integer
3991+
- type: string
39613992
description: 'Total amount of local storage
39623993
required for this EmptyDir volume. The
39633994
size limit is also applicable for memory
@@ -3968,7 +3999,8 @@ spec:
39683999
a pod. The default is nil which means
39694000
that the limit is undefined. More info:
39704001
http://kubernetes.io/docs/user-guide/volumes#emptydir'
3971-
type: string
4002+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
4003+
x-kubernetes-int-or-string: true
39724004
type: object
39734005
fc:
39744006
description: FC represents a Fibre Channel resource
@@ -4524,11 +4556,15 @@ spec:
45244556
for env vars'
45254557
type: string
45264558
divisor:
4559+
anyOf:
4560+
- type: integer
4561+
- type: string
45274562
description: Specifies
45284563
the output format
45294564
of the exposed resources,
45304565
defaults to "1"
4531-
type: string
4566+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
4567+
x-kubernetes-int-or-string: true
45324568
resource:
45334569
description: 'Required:
45344570
resource to select'
@@ -4987,12 +5023,13 @@ spec:
49875023
type: object
49885024
type: object
49895025
mapOfInfo:
4990-
description: A map that allows different actors to manage different fields
4991-
type: object
4992-
x-kubernetes-map-type: granular
49935026
additionalProperties:
49945027
format: byte
49955028
type: string
5029+
description: A map that allows different actors to manage different
5030+
fields
5031+
type: object
5032+
x-kubernetes-map-type: granular
49965033
noReallySuspend:
49975034
description: This flag is like suspend, but for when you really mean
49985035
it. It helps test the +kubebuilder:validation:Type marker.
@@ -5019,8 +5056,6 @@ spec:
50195056
type: object
50205057
structWithSeveralFields:
50215058
description: A struct that can only be entirely replaced
5022-
type: object
5023-
x-kubernetes-map-type: atomic
50245059
properties:
50255060
bar:
50265061
type: boolean
@@ -5029,6 +5064,8 @@ spec:
50295064
required:
50305065
- bar
50315066
- foo
5067+
type: object
5068+
x-kubernetes-map-type: atomic
50325069
successfulJobsHistoryLimit:
50335070
description: The number of successful finished jobs to retain. This
50345071
is a pointer to distinguish between explicit zero and not specified.

0 commit comments

Comments
 (0)