-
Notifications
You must be signed in to change notification settings - Fork 41
/
upstream_bugs.rs
407 lines (366 loc) · 18.2 KB
/
upstream_bugs.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
#![deny(unused)]
//! These fixups correspond to bugs in the upstream swagger spec.
// Path operation annotated with a "x-kubernetes-group-version-kind" that references a type that doesn't exist in the schema.
//
// Ref: https://github.com/kubernetes/kubernetes/pull/66807
#[allow(clippy::if_same_then_else)]
pub(crate) fn connect_options_gvk(spec: &mut crate::swagger20::Spec) -> Result<(), crate::Error> {
let mut found = false;
for operation in &mut spec.operations {
if let Some(kubernetes_group_kind_version) = &mut operation.kubernetes_group_kind_version {
if kubernetes_group_kind_version.group.is_empty() && kubernetes_group_kind_version.version == "v1" {
let kind = &mut kubernetes_group_kind_version.kind;
if &*kind == "NodeProxyOptions" {
*kind = "Node".to_string();
found = true;
}
else if &*kind == "PodAttachOptions" {
*kind = "Pod".to_string();
found = true;
}
else if &*kind == "PodExecOptions" {
*kind = "Pod".to_string();
found = true;
}
else if &*kind == "PodPortForwardOptions" {
*kind = "Pod".to_string();
found = true;
}
else if &*kind == "PodProxyOptions" {
*kind = "Pod".to_string();
found = true;
}
else if &*kind == "ServiceProxyOptions" {
*kind = "Service".to_string();
found = true;
}
}
}
}
if found {
Ok(())
}
else {
Err("never applied connect options kubernetes_group_kind_version override".into())
}
}
// The spec says that this property is an array, but it can be null.
//
// Override it to be optional to achieve the same effect.
pub(crate) mod optional_properties {
// `Event::eventTime`
pub(crate) fn eventsv1_event(spec: &mut crate::swagger20::Spec) -> Result<(), crate::Error> {
let definition_path = crate::swagger20::DefinitionPath("io.k8s.api.events.v1.Event".to_owned());
if let Some(definition) = spec.definitions.get_mut(&definition_path) {
if let crate::swagger20::SchemaKind::Properties(properties) = &mut definition.kind {
if let Some(property) = properties.get_mut("eventTime") {
if property.1 {
property.1 = false;
return Ok(());
}
}
}
}
Err("never applied events.k8s.io/v1.Event optional properties override".into())
}
}
// The spec says that this property is optional, but it's required.
//
// Override it to be required.
pub(crate) mod required_properties {
// `ConfigMapEnvSource::name`
//
// Ref: https://github.com/kubernetes/kubernetes/pull/124694
pub(crate) fn config_map_env_source(spec: &mut crate::swagger20::Spec) -> Result<(), crate::Error> {
let definition_path = crate::swagger20::DefinitionPath("io.k8s.api.core.v1.ConfigMapEnvSource".to_owned());
if let Some(definition) = spec.definitions.get_mut(&definition_path) {
if let crate::swagger20::SchemaKind::Properties(properties) = &mut definition.kind {
if let Some(property) = properties.get_mut("name") {
if !property.1 {
property.1 = true;
return Ok(());
}
}
}
}
Err("never applied ConfigMapEnvSource required properties override".into())
}
// `ConfigMapKeySelector::name`
//
// Ref: https://github.com/kubernetes/kubernetes/pull/124694
pub(crate) fn config_map_key_selector(spec: &mut crate::swagger20::Spec) -> Result<(), crate::Error> {
let definition_path = crate::swagger20::DefinitionPath("io.k8s.api.core.v1.ConfigMapKeySelector".to_owned());
if let Some(definition) = spec.definitions.get_mut(&definition_path) {
if let crate::swagger20::SchemaKind::Properties(properties) = &mut definition.kind {
if let Some(property) = properties.get_mut("name") {
if !property.1 {
property.1 = true;
return Ok(());
}
}
}
}
Err("never applied ConfigMapKeySelector required properties override".into())
}
// `ConfigMapProjection::name`
//
// Ref: https://github.com/kubernetes/kubernetes/pull/124694
pub(crate) fn config_map_projection(spec: &mut crate::swagger20::Spec) -> Result<(), crate::Error> {
let definition_path = crate::swagger20::DefinitionPath("io.k8s.api.core.v1.ConfigMapProjection".to_owned());
if let Some(definition) = spec.definitions.get_mut(&definition_path) {
if let crate::swagger20::SchemaKind::Properties(properties) = &mut definition.kind {
if let Some(property) = properties.get_mut("name") {
if !property.1 {
property.1 = true;
return Ok(());
}
}
}
}
Err("never applied ConfigMapProjection required properties override".into())
}
// `ConfigMapVolumeSource::name`
//
// Ref: https://github.com/kubernetes/kubernetes/pull/124694
pub(crate) fn config_map_volume_source(spec: &mut crate::swagger20::Spec) -> Result<(), crate::Error> {
let definition_path = crate::swagger20::DefinitionPath("io.k8s.api.core.v1.ConfigMapVolumeSource".to_owned());
if let Some(definition) = spec.definitions.get_mut(&definition_path) {
if let crate::swagger20::SchemaKind::Properties(properties) = &mut definition.kind {
if let Some(property) = properties.get_mut("name") {
if !property.1 {
property.1 = true;
return Ok(());
}
}
}
}
Err("never applied ConfigMapVolumeSource required properties override".into())
}
// `HostAlias::ip`
//
// Ref: https://github.com/kubernetes/kubernetes/pull/124694
pub(crate) fn host_alias(spec: &mut crate::swagger20::Spec) -> Result<(), crate::Error> {
let definition_path = crate::swagger20::DefinitionPath("io.k8s.api.core.v1.HostAlias".to_owned());
if let Some(definition) = spec.definitions.get_mut(&definition_path) {
if let crate::swagger20::SchemaKind::Properties(properties) = &mut definition.kind {
if let Some(property) = properties.get_mut("ip") {
if !property.1 {
property.1 = true;
return Ok(());
}
}
}
}
Err("never applied HostAlias required properties override".into())
}
// `HostIP::ip`
//
// Ref: https://github.com/kubernetes/kubernetes/pull/126057
pub(crate) fn host_ip(spec: &mut crate::swagger20::Spec) -> Result<(), crate::Error> {
let definition_path = crate::swagger20::DefinitionPath("io.k8s.api.core.v1.HostIP".to_owned());
if let Some(definition) = spec.definitions.get_mut(&definition_path) {
if let crate::swagger20::SchemaKind::Properties(properties) = &mut definition.kind {
if let Some(property) = properties.get_mut("ip") {
if !property.1 {
property.1 = true;
return Ok(());
}
}
}
}
Err("never applied HostIP required properties override".into())
}
// `LocalObjectReference::name`
//
// Ref: https://github.com/kubernetes/kubernetes/pull/124694
pub(crate) fn local_object_reference(spec: &mut crate::swagger20::Spec) -> Result<(), crate::Error> {
let definition_path = crate::swagger20::DefinitionPath("io.k8s.api.core.v1.LocalObjectReference".to_owned());
if let Some(definition) = spec.definitions.get_mut(&definition_path) {
if let crate::swagger20::SchemaKind::Properties(properties) = &mut definition.kind {
if let Some(property) = properties.get_mut("name") {
if !property.1 {
property.1 = true;
return Ok(());
}
}
}
}
Err("never applied LocalObjectReference required properties override".into())
}
// `PodIP::ip`
//
// Ref: https://github.com/kubernetes/kubernetes/pull/126057
pub(crate) fn pod_ip(spec: &mut crate::swagger20::Spec) -> Result<(), crate::Error> {
let definition_path = crate::swagger20::DefinitionPath("io.k8s.api.core.v1.PodIP".to_owned());
if let Some(definition) = spec.definitions.get_mut(&definition_path) {
if let crate::swagger20::SchemaKind::Properties(properties) = &mut definition.kind {
if let Some(property) = properties.get_mut("ip") {
if !property.1 {
property.1 = true;
return Ok(());
}
}
}
}
Err("never applied PodIP required properties override".into())
}
// `SecretEnvSource::name`
//
// Ref: https://github.com/kubernetes/kubernetes/pull/124694
pub(crate) fn secret_env_source(spec: &mut crate::swagger20::Spec) -> Result<(), crate::Error> {
let definition_path = crate::swagger20::DefinitionPath("io.k8s.api.core.v1.SecretEnvSource".to_owned());
if let Some(definition) = spec.definitions.get_mut(&definition_path) {
if let crate::swagger20::SchemaKind::Properties(properties) = &mut definition.kind {
if let Some(property) = properties.get_mut("name") {
if !property.1 {
property.1 = true;
return Ok(());
}
}
}
}
Err("never applied SecretEnvSource required properties override".into())
}
// `SecretKeySelector::name`
//
// Ref: https://github.com/kubernetes/kubernetes/pull/124694
pub(crate) fn secret_key_selector(spec: &mut crate::swagger20::Spec) -> Result<(), crate::Error> {
let definition_path = crate::swagger20::DefinitionPath("io.k8s.api.core.v1.SecretKeySelector".to_owned());
if let Some(definition) = spec.definitions.get_mut(&definition_path) {
if let crate::swagger20::SchemaKind::Properties(properties) = &mut definition.kind {
if let Some(property) = properties.get_mut("name") {
if !property.1 {
property.1 = true;
return Ok(());
}
}
}
}
Err("never applied SecretKeySelector required properties override".into())
}
// `SecretProjection::name`
//
// Ref: https://github.com/kubernetes/kubernetes/pull/124694
pub(crate) fn secret_projection(spec: &mut crate::swagger20::Spec) -> Result<(), crate::Error> {
let definition_path = crate::swagger20::DefinitionPath("io.k8s.api.core.v1.SecretProjection".to_owned());
if let Some(definition) = spec.definitions.get_mut(&definition_path) {
if let crate::swagger20::SchemaKind::Properties(properties) = &mut definition.kind {
if let Some(property) = properties.get_mut("name") {
if !property.1 {
property.1 = true;
return Ok(());
}
}
}
}
Err("never applied SecretProjection required properties override".into())
}
// `ValidatingAdmissionPolicyBindingList::items`
pub(crate) fn alpha1_validating_admission_policy_binding_list(spec: &mut crate::swagger20::Spec) -> Result<(), crate::Error> {
let definition_path = crate::swagger20::DefinitionPath("io.k8s.api.admissionregistration.v1alpha1.ValidatingAdmissionPolicyBindingList".to_owned());
if let Some(definition) = spec.definitions.get_mut(&definition_path) {
if let crate::swagger20::SchemaKind::Properties(properties) = &mut definition.kind {
if let Some(property) = properties.get_mut("items") {
if !property.1 {
property.1 = true;
return Ok(());
}
}
}
}
Err("never applied admissionregistration.k8s.io/v1alpha1.ValidatingAdmissionPolicyBindingList required properties override".into())
}
// `ValidatingAdmissionPolicyList::items`
pub(crate) fn alpha1_validating_admission_policy_list(spec: &mut crate::swagger20::Spec) -> Result<(), crate::Error> {
let definition_path = crate::swagger20::DefinitionPath("io.k8s.api.admissionregistration.v1alpha1.ValidatingAdmissionPolicyList".to_owned());
if let Some(definition) = spec.definitions.get_mut(&definition_path) {
if let crate::swagger20::SchemaKind::Properties(properties) = &mut definition.kind {
if let Some(property) = properties.get_mut("items") {
if !property.1 {
property.1 = true;
return Ok(());
}
}
}
}
Err("never applied admissionregistration.k8s.io/v1alpha1.ValidatingAdmissionPolicyList required properties override".into())
}
}
// `Status` has extra group-version-kind entries than the original `"":v1:Status` that cause it to not be detected as a `Resource`.
// Remove the extras.
pub(crate) fn status_extra_gvk(spec: &mut crate::swagger20::Spec) -> Result<(), crate::Error> {
let definition_path = crate::swagger20::DefinitionPath("io.k8s.apimachinery.pkg.apis.meta.v1.Status".to_owned());
if let Some(definition) = spec.definitions.get_mut(&definition_path) {
if definition.kubernetes_group_kind_versions.len() > 1 {
#[allow(clippy::comparison_to_empty)]
definition.kubernetes_group_kind_versions.retain(|gvk| gvk.group == "" && gvk.kind == "Status" && gvk.version == "v1");
if definition.kubernetes_group_kind_versions.len() == 1 {
return Ok(());
}
return Err(format!(
"Status extra group-version-kinds override did not retain the expected group-version-kind: {:?}",
definition.kubernetes_group_kind_versions).into());
}
}
Err("never applied Status extra group-version-kinds override".into())
}
// `PodSchedulingContextSpec` has `set` merge strategy in versions before v1.29
// but v1.29 decided it would like clients to treat it as `atomic`.
//
// Ref: https://github.com/kubernetes/kubernetes/pull/119962
pub(crate) fn pod_scheduling_context_spec_potential_nodes_merge_strategy(spec: &mut crate::swagger20::Spec) -> Result<(), crate::Error> {
let definition_path = crate::swagger20::DefinitionPath("io.k8s.api.resource.v1alpha2.PodSchedulingContextSpec".to_owned());
if let Some(definition) = spec.definitions.get_mut(&definition_path) {
if let crate::swagger20::SchemaKind::Properties(properties) = &mut definition.kind {
if let Some(property) = properties.get_mut("potentialNodes") {
if let crate::swagger20::MergeType::List { strategy, .. } = &mut property.0.merge_type {
if *strategy == crate::swagger20::KubernetesListType::Set {
*strategy = crate::swagger20::KubernetesListType::Atomic;
return Ok(());
}
}
}
}
}
Err("never applied PodSchedulingContextSpec.potentialNodes merge strategy override".into())
}
// `ResourceClaimSchedulingStatus` has `set` merge strategy in versions before v1.29
// but v1.29 decided it would like clients to treat it as `atomic`.
//
// Ref: https://github.com/kubernetes/kubernetes/pull/119962
pub(crate) fn v1alpha1_resource_claim_scheduling_status_unsuitable_nodes_merge_strategy(spec: &mut crate::swagger20::Spec) -> Result<(), crate::Error> {
let definition_path = crate::swagger20::DefinitionPath("io.k8s.api.resource.v1alpha1.ResourceClaimSchedulingStatus".to_owned());
if let Some(definition) = spec.definitions.get_mut(&definition_path) {
if let crate::swagger20::SchemaKind::Properties(properties) = &mut definition.kind {
if let Some(property) = properties.get_mut("unsuitableNodes") {
if let crate::swagger20::MergeType::List { strategy, .. } = &mut property.0.merge_type {
if *strategy == crate::swagger20::KubernetesListType::Set {
*strategy = crate::swagger20::KubernetesListType::Atomic;
return Ok(());
}
}
}
}
}
Err("never applied ResourceClaimSchedulingStatus.unsuitableNodes merge strategy override".into())
}
// `ResourceClaimSchedulingStatus` has `set` merge strategy in versions before v1.29
// but v1.29 decided it would like clients to treat it as `atomic`.
//
// Ref: https://github.com/kubernetes/kubernetes/pull/119962
pub(crate) fn v1alpha2_resource_claim_scheduling_status_unsuitable_nodes_merge_strategy(spec: &mut crate::swagger20::Spec) -> Result<(), crate::Error> {
let definition_path = crate::swagger20::DefinitionPath("io.k8s.api.resource.v1alpha2.ResourceClaimSchedulingStatus".to_owned());
if let Some(definition) = spec.definitions.get_mut(&definition_path) {
if let crate::swagger20::SchemaKind::Properties(properties) = &mut definition.kind {
if let Some(property) = properties.get_mut("unsuitableNodes") {
if let crate::swagger20::MergeType::List { strategy, .. } = &mut property.0.merge_type {
if *strategy == crate::swagger20::KubernetesListType::Set {
*strategy = crate::swagger20::KubernetesListType::Atomic;
return Ok(());
}
}
}
}
}
Err("never applied ResourceClaimSchedulingStatus.unsuitableNodes merge strategy override".into())
}