Skip to content

Commit 3ac6c7e

Browse files
committed
Update proto test data from Kubernetes v1.8/v1.24 to v1.35
Replace swagger v2 test fixtures (swagger.json, swagger_next.json) with trimmed extracts from the Kubernetes v1.35.2 OpenAPI spec, and update all OpenAPI v3 per-group specs from v1.24 to v1.35.2. Changes: - Replace v2 swagger test data with v1.35.2 equivalents (trimmed to only the definitions needed by tests) - Update v3 per-group OpenAPI specs (apps/v1, core/v1, apiextensions.k8s.io/v1, batch/v1) to v1.35.2 - Remove batch/v1beta1.json (no longer exists in Kubernetes 1.35) - Update all test references from deprecated apps/v1beta1 models to GA apps/v1 - Fix Container required-field assertions (only 'name' is required in modern Kubernetes, not 'name' and 'image') - Add selector to Deployment validation test (required in apps/v1) - Update DeploymentStatus.conditions extension assertions to include x-kubernetes-list-map-keys and x-kubernetes-list-type
1 parent 43fb72c commit 3ac6c7e

File tree

9 files changed

+73827
-10326
lines changed

9 files changed

+73827
-10326
lines changed

pkg/util/proto/openapi_test.go

Lines changed: 47 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ var fakeSchema = prototesting.Fake{Path: filepath.Join("testdata", "swagger.json
3131
var fakeSchemaNext = prototesting.Fake{Path: filepath.Join("testdata", "swagger_next.json")}
3232
var fakeSchemaV300 = prototesting.FakeV3{Path: filepath.Join("testdata", "openapi_v3_0_0")}
3333

34-
// loadV18Models loads the v1.8 swagger schema and returns proto.Models.
35-
func loadV18Models(t *testing.T) proto.Models {
34+
// loadModels loads the swagger schema and returns proto.Models.
35+
func loadModels(t *testing.T) proto.Models {
3636
t.Helper()
3737
s, err := fakeSchema.OpenAPISchema()
3838
if err != nil {
39-
t.Fatalf("failed to open v1.8 schema: %v", err)
39+
t.Fatalf("failed to open schema: %v", err)
4040
}
4141
models, err := proto.NewOpenAPIData(s)
4242
if err != nil {
@@ -45,13 +45,13 @@ func loadV18Models(t *testing.T) proto.Models {
4545
return models
4646
}
4747

48-
// loadV18DeploymentModel loads the v1.8 schema and returns the Deployment Kind.
49-
func loadV18DeploymentModel(t *testing.T) (proto.Models, proto.Schema, *proto.Kind) {
48+
// loadDeploymentModel loads the schema and returns the Deployment Kind.
49+
func loadDeploymentModel(t *testing.T) (proto.Models, proto.Schema, *proto.Kind) {
5050
t.Helper()
51-
models := loadV18Models(t)
52-
schema := models.LookupModel("io.k8s.api.apps.v1beta1.Deployment")
51+
models := loadModels(t)
52+
schema := models.LookupModel("io.k8s.api.apps.v1.Deployment")
5353
if schema == nil {
54-
t.Fatal("model io.k8s.api.apps.v1beta1.Deployment not found")
54+
t.Fatal("model io.k8s.api.apps.v1.Deployment not found")
5555
}
5656
deployment, ok := schema.(*proto.Kind)
5757
if !ok || deployment == nil {
@@ -60,33 +60,33 @@ func loadV18DeploymentModel(t *testing.T) (proto.Models, proto.Schema, *proto.Ki
6060
return models, schema, deployment
6161
}
6262

63-
func TestV18Deployment(t *testing.T) {
63+
func TestDeployment(t *testing.T) {
6464
t.Run("should lookup the Schema by its model name", func(t *testing.T) {
65-
models := loadV18Models(t)
66-
schema := models.LookupModel("io.k8s.api.apps.v1beta1.Deployment")
65+
models := loadModels(t)
66+
schema := models.LookupModel("io.k8s.api.apps.v1.Deployment")
6767
if schema == nil {
68-
t.Fatal("model io.k8s.api.apps.v1beta1.Deployment not found")
68+
t.Fatal("model io.k8s.api.apps.v1.Deployment not found")
6969
}
7070
})
7171

7272
t.Run("should be a Kind", func(t *testing.T) {
73-
_, _, deployment := loadV18DeploymentModel(t)
73+
_, _, deployment := loadDeploymentModel(t)
7474
if deployment == nil {
7575
t.Fatal("expected deployment to be non-nil")
7676
}
7777
})
7878

7979
t.Run("should have a path", func(t *testing.T) {
80-
_, _, deployment := loadV18DeploymentModel(t)
80+
_, _, deployment := loadDeploymentModel(t)
8181
got := deployment.GetPath().Get()
82-
want := []string{"io.k8s.api.apps.v1beta1.Deployment"}
82+
want := []string{"io.k8s.api.apps.v1.Deployment"}
8383
if !reflect.DeepEqual(got, want) {
8484
t.Errorf("path = %v, want %v", got, want)
8585
}
8686
})
8787

8888
t.Run("should have a kind key of type string", func(t *testing.T) {
89-
_, _, deployment := loadV18DeploymentModel(t)
89+
_, _, deployment := loadDeploymentModel(t)
9090
if _, ok := deployment.Fields["kind"]; !ok {
9191
t.Fatal("missing 'kind' field")
9292
}
@@ -98,14 +98,14 @@ func TestV18Deployment(t *testing.T) {
9898
t.Errorf("kind.Type = %q, want %q", key.Type, "string")
9999
}
100100
got := key.GetPath().Get()
101-
want := []string{"io.k8s.api.apps.v1beta1.Deployment", ".kind"}
101+
want := []string{"io.k8s.api.apps.v1.Deployment", ".kind"}
102102
if !reflect.DeepEqual(got, want) {
103103
t.Errorf("kind path = %v, want %v", got, want)
104104
}
105105
})
106106

107107
t.Run("should have a apiVersion key of type string", func(t *testing.T) {
108-
_, _, deployment := loadV18DeploymentModel(t)
108+
_, _, deployment := loadDeploymentModel(t)
109109
if _, ok := deployment.Fields["apiVersion"]; !ok {
110110
t.Fatal("missing 'apiVersion' field")
111111
}
@@ -117,14 +117,14 @@ func TestV18Deployment(t *testing.T) {
117117
t.Errorf("apiVersion.Type = %q, want %q", key.Type, "string")
118118
}
119119
got := key.GetPath().Get()
120-
want := []string{"io.k8s.api.apps.v1beta1.Deployment", ".apiVersion"}
120+
want := []string{"io.k8s.api.apps.v1.Deployment", ".apiVersion"}
121121
if !reflect.DeepEqual(got, want) {
122122
t.Errorf("apiVersion path = %v, want %v", got, want)
123123
}
124124
})
125125

126126
t.Run("should have a metadata key of type Reference", func(t *testing.T) {
127-
_, _, deployment := loadV18DeploymentModel(t)
127+
_, _, deployment := loadDeploymentModel(t)
128128
if _, ok := deployment.Fields["metadata"]; !ok {
129129
t.Fatal("missing 'metadata' field")
130130
}
@@ -142,16 +142,16 @@ func TestV18Deployment(t *testing.T) {
142142
})
143143

144144
t.Run("should have a status key of type Reference", func(t *testing.T) {
145-
_, _, deployment := loadV18DeploymentModel(t)
145+
_, _, deployment := loadDeploymentModel(t)
146146
if _, ok := deployment.Fields["status"]; !ok {
147147
t.Fatal("missing 'status' field")
148148
}
149149
key, ok := deployment.Fields["status"].(proto.Reference)
150150
if !ok {
151151
t.Fatal("expected 'status' to be proto.Reference")
152152
}
153-
if key.Reference() != "io.k8s.api.apps.v1beta1.DeploymentStatus" {
154-
t.Errorf("status reference = %q, want %q", key.Reference(), "io.k8s.api.apps.v1beta1.DeploymentStatus")
153+
if key.Reference() != "io.k8s.api.apps.v1.DeploymentStatus" {
154+
t.Errorf("status reference = %q, want %q", key.Reference(), "io.k8s.api.apps.v1.DeploymentStatus")
155155
}
156156
status, ok := key.SubSchema().(*proto.Kind)
157157
if !ok || status == nil {
@@ -160,7 +160,7 @@ func TestV18Deployment(t *testing.T) {
160160
})
161161

162162
t.Run("should have a valid DeploymentStatus", func(t *testing.T) {
163-
_, _, deployment := loadV18DeploymentModel(t)
163+
_, _, deployment := loadDeploymentModel(t)
164164
statusRef, ok := deployment.Fields["status"].(proto.Reference)
165165
if !ok {
166166
t.Fatal("expected 'status' to be proto.Reference")
@@ -190,11 +190,13 @@ func TestV18Deployment(t *testing.T) {
190190
if !ok || conditions == nil {
191191
t.Fatal("expected 'conditions' to be *proto.Array")
192192
}
193-
wantName := `Array of Reference to "io.k8s.api.apps.v1beta1.DeploymentCondition"`
193+
wantName := `Array of Reference to "io.k8s.api.apps.v1.DeploymentCondition"`
194194
if conditions.GetName() != wantName {
195195
t.Errorf("conditions name = %q, want %q", conditions.GetName(), wantName)
196196
}
197197
wantExt := map[string]interface{}{
198+
"x-kubernetes-list-map-keys": []interface{}{"type"},
199+
"x-kubernetes-list-type": "map",
198200
"x-kubernetes-patch-merge-key": "type",
199201
"x-kubernetes-patch-strategy": "merge",
200202
}
@@ -205,22 +207,22 @@ func TestV18Deployment(t *testing.T) {
205207
if !ok {
206208
t.Fatal("expected conditions.SubType to be proto.Reference")
207209
}
208-
if condition.Reference() != "io.k8s.api.apps.v1beta1.DeploymentCondition" {
209-
t.Errorf("condition reference = %q, want %q", condition.Reference(), "io.k8s.api.apps.v1beta1.DeploymentCondition")
210+
if condition.Reference() != "io.k8s.api.apps.v1.DeploymentCondition" {
211+
t.Errorf("condition reference = %q, want %q", condition.Reference(), "io.k8s.api.apps.v1.DeploymentCondition")
210212
}
211213
})
212214

213215
t.Run("should have a spec key of type Reference", func(t *testing.T) {
214-
_, _, deployment := loadV18DeploymentModel(t)
216+
_, _, deployment := loadDeploymentModel(t)
215217
if _, ok := deployment.Fields["spec"]; !ok {
216218
t.Fatal("missing 'spec' field")
217219
}
218220
key, ok := deployment.Fields["spec"].(proto.Reference)
219221
if !ok {
220222
t.Fatal("expected 'spec' to be proto.Reference")
221223
}
222-
if key.Reference() != "io.k8s.api.apps.v1beta1.DeploymentSpec" {
223-
t.Errorf("spec reference = %q, want %q", key.Reference(), "io.k8s.api.apps.v1beta1.DeploymentSpec")
224+
if key.Reference() != "io.k8s.api.apps.v1.DeploymentSpec" {
225+
t.Errorf("spec reference = %q, want %q", key.Reference(), "io.k8s.api.apps.v1.DeploymentSpec")
224226
}
225227
spec, ok := key.SubSchema().(*proto.Kind)
226228
if !ok || spec == nil {
@@ -229,7 +231,7 @@ func TestV18Deployment(t *testing.T) {
229231
})
230232

231233
t.Run("should have a spec with no gvk", func(t *testing.T) {
232-
_, _, deployment := loadV18DeploymentModel(t)
234+
_, _, deployment := loadDeploymentModel(t)
233235
specRef, ok := deployment.Fields["spec"].(proto.Reference)
234236
if !ok {
235237
t.Fatal("expected 'spec' to be proto.Reference")
@@ -244,7 +246,7 @@ func TestV18Deployment(t *testing.T) {
244246
})
245247

246248
t.Run("should have a spec with a PodTemplateSpec sub-field", func(t *testing.T) {
247-
_, _, deployment := loadV18DeploymentModel(t)
249+
_, _, deployment := loadDeploymentModel(t)
248250
specRef, ok := deployment.Fields["spec"].(proto.Reference)
249251
if !ok {
250252
t.Fatal("expected 'spec' to be proto.Reference")
@@ -266,25 +268,25 @@ func TestV18Deployment(t *testing.T) {
266268
})
267269
}
268270

269-
func TestV111Deployment(t *testing.T) {
271+
func TestNextSchemaDeployment(t *testing.T) {
270272
s, err := fakeSchemaNext.OpenAPISchema()
271273
if err != nil {
272-
t.Fatalf("failed to open v1.11 schema: %v", err)
274+
t.Fatalf("failed to open next schema: %v", err)
273275
}
274276
models, err := proto.NewOpenAPIData(s)
275277
if err != nil {
276278
t.Fatalf("failed to create OpenAPI data: %v", err)
277279
}
278280

279281
t.Run("should lookup the Schema by its model name", func(t *testing.T) {
280-
schema := models.LookupModel("io.k8s.api.apps.v1beta1.Deployment")
282+
schema := models.LookupModel("io.k8s.api.apps.v1.Deployment")
281283
if schema == nil {
282-
t.Fatal("model io.k8s.api.apps.v1beta1.Deployment not found")
284+
t.Fatal("model io.k8s.api.apps.v1.Deployment not found")
283285
}
284286
})
285287

286288
t.Run("should be a Kind", func(t *testing.T) {
287-
schema := models.LookupModel("io.k8s.api.apps.v1beta1.Deployment")
289+
schema := models.LookupModel("io.k8s.api.apps.v1.Deployment")
288290
if schema == nil {
289291
t.Fatal("model not found")
290292
}
@@ -295,25 +297,25 @@ func TestV111Deployment(t *testing.T) {
295297
})
296298
}
297299

298-
func TestV111ControllerRevision(t *testing.T) {
300+
func TestNextSchemaControllerRevision(t *testing.T) {
299301
s, err := fakeSchemaNext.OpenAPISchema()
300302
if err != nil {
301-
t.Fatalf("failed to open v1.11 schema: %v", err)
303+
t.Fatalf("failed to open next schema: %v", err)
302304
}
303305
models, err := proto.NewOpenAPIData(s)
304306
if err != nil {
305307
t.Fatalf("failed to create OpenAPI data: %v", err)
306308
}
307309

308310
t.Run("should lookup the Schema by its model name", func(t *testing.T) {
309-
schema := models.LookupModel("io.k8s.api.apps.v1beta1.ControllerRevision")
311+
schema := models.LookupModel("io.k8s.api.apps.v1.ControllerRevision")
310312
if schema == nil {
311-
t.Fatal("model io.k8s.api.apps.v1beta1.ControllerRevision not found")
313+
t.Fatal("model io.k8s.api.apps.v1.ControllerRevision not found")
312314
}
313315
})
314316

315317
t.Run("data property should be map[string]Arbitrary", func(t *testing.T) {
316-
schema := models.LookupModel("io.k8s.api.apps.v1beta1.ControllerRevision")
318+
schema := models.LookupModel("io.k8s.api.apps.v1.ControllerRevision")
317319
if schema == nil {
318320
t.Fatal("model not found")
319321
}
@@ -333,7 +335,7 @@ func TestV111ControllerRevision(t *testing.T) {
333335
if data.GetName() != wantName {
334336
t.Errorf("data name = %q, want %q", data.GetName(), wantName)
335337
}
336-
wantPath := []string{"io.k8s.api.apps.v1beta1.ControllerRevision", ".data"}
338+
wantPath := []string{"io.k8s.api.apps.v1.ControllerRevision", ".data"}
337339
if !reflect.DeepEqual(data.GetPath().Get(), wantPath) {
338340
t.Errorf("data path = %v, want %v", data.GetPath().Get(), wantPath)
339341
}
@@ -622,6 +624,8 @@ func TestV3Deployment(t *testing.T) {
622624
t.Errorf("conditions name = %q, want %q", conditions.GetName(), wantName)
623625
}
624626
wantExt := map[string]interface{}{
627+
"x-kubernetes-list-map-keys": []interface{}{"type"},
628+
"x-kubernetes-list-type": "map",
625629
"x-kubernetes-patch-merge-key": "type",
626630
"x-kubernetes-patch-strategy": "merge",
627631
}

pkg/util/proto/testdata/openapi_v3_0_0/apiextensions.k8s.io/v1.json

Lines changed: 3484 additions & 1 deletion
Large diffs are not rendered by default.

pkg/util/proto/testdata/openapi_v3_0_0/apps/v1.json

Lines changed: 16142 additions & 1 deletion
Large diffs are not rendered by default.

pkg/util/proto/testdata/openapi_v3_0_0/batch/v1.json

Lines changed: 9099 additions & 1 deletion
Large diffs are not rendered by default.

pkg/util/proto/testdata/openapi_v3_0_0/batch/v1beta1.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

pkg/util/proto/testdata/openapi_v3_0_0/v1.json

Lines changed: 37834 additions & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)