Skip to content

Commit a9808e5

Browse files
committed
Add a test case under api/krusty for #5878 (#2)
1 parent 4ee4c1d commit a9808e5

File tree

3 files changed

+98
-3
lines changed

3 files changed

+98
-3
lines changed

api/krusty/openapicustomschema_test.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,3 +643,58 @@ spec:
643643
assert.Equal(t, kubernetesapi.DefaultOpenAPI, openapi.GetSchemaVersion())
644644
})
645645
}
646+
647+
// Tett for issue #5878
648+
func TestCustomOpenApiFieldWithoutMergePatchExtension(t *testing.T) {
649+
runOpenApiTest(t, func(t *testing.T) {
650+
t.Helper()
651+
th := kusttest_test.MakeHarness(t)
652+
writeTestSchema(th, "./")
653+
th.WriteF("yetanothercrd_base.yaml", `
654+
apiVersion: example.com/v1alpha1
655+
kind: MyCRD
656+
metadata:
657+
name: service
658+
spec:
659+
custom:
660+
objects:
661+
- name: foo
662+
value: foo
663+
- name: bar
664+
value: bar
665+
`)
666+
th.WriteF("yetanothercrd_patch.yaml", `
667+
apiVersion: example.com/v1alpha1
668+
kind: MyCRD
669+
metadata:
670+
name: service
671+
spec:
672+
custom:
673+
objects:
674+
- name: bar
675+
value: patched
676+
`)
677+
th.WriteK(".", `
678+
resources:
679+
- yetanothercrd_base.yaml
680+
openapi:
681+
path: mycrd_schema.json
682+
patches:
683+
- path: yetanothercrd_patch.yaml
684+
`)
685+
m := th.Run(".", th.MakeDefaultOptions())
686+
th.AssertActualEqualsExpected(m, `
687+
apiVersion: example.com/v1alpha1
688+
kind: MyCRD
689+
metadata:
690+
name: service
691+
spec:
692+
custom:
693+
objects:
694+
- name: foo
695+
value: foo
696+
- name: bar
697+
value: patched
698+
`)
699+
})
700+
}

api/krusty/testdata/customschema.json

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@
1515
"properties": {
1616
"template": {
1717
"$ref": "#/definitions/io.k8s.api.core.v1.PodTemplateSpec"
18+
},
19+
"custom": {
20+
"$ref": "#/definitions/com.example.v1alpha1.CustomSpec"
1821
}
1922
},
2023
"type": "object"
2124
},
2225
"status": {
23-
"properties": {
26+
"properties": {
2427
"success": {
2528
"type": "boolean"
2629
}
@@ -89,7 +92,7 @@
8992
"type": "string"
9093
},
9194
"ports": {
92-
"items": {
95+
"items": {
9396
"$ref": "#/definitions/io.k8s.api.core.v1.ContainerPort"
9497
},
9598
"type": "array",
@@ -105,7 +108,7 @@
105108
"type": "object"
106109
},
107110
"io.k8s.api.core.v1.ContainerPort": {
108-
"properties": {
111+
"properties": {
109112
"containerPort": {
110113
"format": "int32",
111114
"type": "integer"
@@ -118,6 +121,27 @@
118121
}
119122
},
120123
"type": "object"
124+
},
125+
"com.example.v1alpha1.CustomSpec": {
126+
"properties": {
127+
"objects": {
128+
"items": {
129+
"properties": {
130+
"name": {
131+
"type": "string"
132+
},
133+
"value": {
134+
"type": "string"
135+
}
136+
}
137+
},
138+
"type": "array",
139+
"x-kubernetes-list-map-keys": [
140+
"name"
141+
],
142+
"x-kubernetes-list-type": "map"
143+
}
144+
}
121145
}
122146
}
123147
}

api/krusty/testdata/customschema.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ definitions:
1111
properties:
1212
template:
1313
"$ref": "#/definitions/io.k8s.api.core.v1.PodTemplateSpec"
14+
custom:
15+
"$ref": "#/definitions/com.example.v1alpha1.CustomSpec"
1416
type: object
1517
status:
1618
properties:
@@ -70,9 +72,23 @@ definitions:
7072
io.k8s.api.core.v1.ContainerPort:
7173
properties:
7274
containerPort:
75+
format: int32
7376
type: integer
7477
name:
7578
type: string
7679
protocol:
7780
type: string
7881
type: object
82+
com.example.v1alpha1.CustomSpec:
83+
properties:
84+
objects:
85+
items:
86+
properties:
87+
name:
88+
type: string
89+
value:
90+
type: string
91+
type: array
92+
x-kubernetes-list-map-keys:
93+
- name
94+
x-kubernetes-list-type: map

0 commit comments

Comments
 (0)