Skip to content

Commit d6b13f7

Browse files
Add tests to ensure scenarios with preflight
1 parent c518f68 commit d6b13f7

5 files changed

Lines changed: 532 additions & 6 deletions

File tree

internal/operator-controller/rukpak/preflights/crdupgradesafety/crdupgradesafety_test.go

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,11 @@ func TestInstall(t *testing.T) {
192192
},
193193
},
194194
{
195-
name: "optional field addition should not fail (RHDH scenario)",
196-
oldCrdPath: "crd-rhdh-old.json",
195+
name: "optional field addition should not fail",
196+
oldCrdPath: "crd-optional-field-old.json",
197197
release: &release.Release{
198198
Name: "test-release",
199-
Manifest: getManifestString(t, "crd-rhdh-new-optional-field.json"),
199+
Manifest: getManifestString(t, "crd-optional-field-new.json"),
200200
},
201201
},
202202
}
@@ -379,13 +379,34 @@ func TestUpgrade(t *testing.T) {
379379
},
380380
},
381381
{
382-
name: "optional field addition should not fail (RHDH scenario)",
383-
oldCrdPath: "crd-rhdh-old.json",
382+
name: "optional field addition should not fail",
383+
oldCrdPath: "crd-optional-field-old.json",
384384
release: &release.Release{
385385
Name: "test-release",
386-
Manifest: getManifestString(t, "crd-rhdh-new-optional-field.json"),
386+
Manifest: getManifestString(t, "crd-optional-field-new.json"),
387387
},
388388
},
389+
{
390+
name: "complex breaking changes should fail",
391+
oldCrdPath: "crd-complex-breaking-changes-old.json",
392+
release: &release.Release{
393+
Name: "test-release",
394+
Manifest: getManifestString(t, "crd-complex-breaking-changes-new.json"),
395+
},
396+
// This test verifies detection of multiple breaking changes in a single CRD upgrade:
397+
// 1. Type changed from "object" to "" - Properly detected by type validator
398+
// 2. Nullable changed from false to true - Properly detected by nullable validator
399+
// 3. OneOf constraint added - Reported as "unhandled" (needs crdify support)
400+
// See: https://github.com/kubernetes-sigs/crdify/issues/25
401+
// The upgrade is correctly blocked, but OneOf changes need better categorization.
402+
requireErr: wantErrorMsgs([]string{
403+
`validating upgrade for CRD "services.networking.example.com"`,
404+
`type: type changed`,
405+
`nullable: nullable added`,
406+
`unhandled: unhandled changes found`,
407+
`OneOf`,
408+
}),
409+
},
389410
}
390411

391412
for _, tc := range tests {
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
{
2+
"apiVersion": "apiextensions.k8s.io/v1",
3+
"kind": "CustomResourceDefinition",
4+
"metadata": {
5+
"name": "services.networking.example.com"
6+
},
7+
"spec": {
8+
"group": "networking.example.com",
9+
"versions": [
10+
{
11+
"name": "v1beta1",
12+
"served": true,
13+
"storage": true,
14+
"schema": {
15+
"openAPIV3Schema": {
16+
"type": "object",
17+
"properties": {
18+
"spec": {
19+
"type": "object",
20+
"properties": {
21+
"ingress": {
22+
"type": "object",
23+
"properties": {
24+
"gateway": {
25+
"type": "object",
26+
"properties": {
27+
"servers": {
28+
"type": "array",
29+
"items": {
30+
"type": "object",
31+
"properties": {
32+
"hosts": {
33+
"description": "One or more hosts exposed by this gateway",
34+
"type": "array",
35+
"items": {
36+
"type": "string"
37+
}
38+
},
39+
"port": {
40+
"type": "object",
41+
"properties": {
42+
"name": {
43+
"description": "Label assigned to the port",
44+
"type": "string"
45+
},
46+
"number": {
47+
"description": "Port number",
48+
"type": "integer"
49+
}
50+
}
51+
},
52+
"tls": {
53+
"nullable": true,
54+
"oneOf": [
55+
{
56+
"required": ["mode", "credentialName"]
57+
},
58+
{
59+
"required": ["httpsRedirect"]
60+
}
61+
],
62+
"properties": {
63+
"credentialName": {
64+
"description": "TLS certificate name",
65+
"type": "string"
66+
},
67+
"httpsRedirect": {
68+
"description": "If set to true, the load balancer will send a 301 redirect to HTTPS",
69+
"type": "boolean"
70+
},
71+
"mode": {
72+
"description": "TLS mode",
73+
"type": "string"
74+
}
75+
}
76+
}
77+
}
78+
}
79+
}
80+
}
81+
}
82+
}
83+
}
84+
}
85+
}
86+
}
87+
}
88+
}
89+
}
90+
],
91+
"scope": "Namespaced",
92+
"names": {
93+
"plural": "services",
94+
"singular": "service",
95+
"kind": "Service",
96+
"shortNames": [
97+
"svc"
98+
]
99+
}
100+
},
101+
"status": {
102+
"storedVersions": [
103+
"v1beta1"
104+
]
105+
}
106+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
{
2+
"apiVersion": "apiextensions.k8s.io/v1",
3+
"kind": "CustomResourceDefinition",
4+
"metadata": {
5+
"name": "services.networking.example.com"
6+
},
7+
"spec": {
8+
"group": "networking.example.com",
9+
"versions": [
10+
{
11+
"name": "v1beta1",
12+
"served": true,
13+
"storage": true,
14+
"schema": {
15+
"openAPIV3Schema": {
16+
"type": "object",
17+
"properties": {
18+
"spec": {
19+
"type": "object",
20+
"properties": {
21+
"ingress": {
22+
"type": "object",
23+
"properties": {
24+
"gateway": {
25+
"type": "object",
26+
"properties": {
27+
"servers": {
28+
"type": "array",
29+
"items": {
30+
"type": "object",
31+
"properties": {
32+
"hosts": {
33+
"description": "One or more hosts exposed by this gateway",
34+
"type": "array",
35+
"items": {
36+
"type": "string"
37+
}
38+
},
39+
"port": {
40+
"type": "object",
41+
"properties": {
42+
"name": {
43+
"description": "Label assigned to the port",
44+
"type": "string"
45+
},
46+
"number": {
47+
"description": "Port number",
48+
"type": "integer"
49+
}
50+
}
51+
},
52+
"tls": {
53+
"type": "object",
54+
"nullable": false,
55+
"properties": {
56+
"credentialName": {
57+
"description": "TLS certificate name",
58+
"type": "string"
59+
},
60+
"mode": {
61+
"description": "TLS mode",
62+
"type": "string"
63+
}
64+
}
65+
}
66+
}
67+
}
68+
}
69+
}
70+
}
71+
}
72+
}
73+
}
74+
}
75+
}
76+
}
77+
}
78+
}
79+
],
80+
"scope": "Namespaced",
81+
"names": {
82+
"plural": "services",
83+
"singular": "service",
84+
"kind": "Service",
85+
"shortNames": [
86+
"svc"
87+
]
88+
}
89+
},
90+
"status": {
91+
"storedVersions": [
92+
"v1beta1"
93+
]
94+
}
95+
}

0 commit comments

Comments
 (0)