-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathupstream_bugs.rs
More file actions
305 lines (277 loc) · 13.4 KB
/
upstream_bugs.rs
File metadata and controls
305 lines (277 loc) · 13.4 KB
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
#![deny(unused)]
//! These fixups correspond to bugs in the upstream swagger spec.
// `StatefulSetSpec::volumeClaimTemplates` should be a map list keyed by `metadata.name`.
//
// The upstream Go source annotates `StatefulSetSpec.volumeClaimTemplates` with `// +listType=atomic`,
// which propagates to `x-kubernetes-list-type: atomic` in the OpenAPI spec. Semantically it should
// be a map list keyed by `metadata.name`, because each PVC in a StatefulSet has a unique name and
// merging by identity is the correct behavior.
//
// One possible reason this is not fixed upstream yet could be a limitation of the Kubernetes
// annotation system: `// +listMapKey=<field>` only supports direct scalar fields on the item type,
// but `PersistentVolumeClaim` carries its name via an embedded `ObjectMeta` (i.e. `metadata.name`
// in JSON), not as a top-level field. There is no existing precedent or tooling support for a
// nested `listMapKey` path in the Kubernetes codebase.
//
// We therefore fix it here by overriding the merge type after parsing the spec.
//
// Ref: https://github.com/kubernetes/kubernetes/issues/74819
pub(crate) fn appsv1_statefulsetspec_volume_claim_templates_merge_strategy(spec: &mut crate::swagger20::Spec) -> Result<(), crate::Error> {
let definition_path = crate::swagger20::DefinitionPath("io.k8s.api.apps.v1.StatefulSetSpec".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_schema, _required)) = properties.get_mut("volumeClaimTemplates") {
if let crate::swagger20::MergeType::List { strategy, keys, .. } =
&mut property_schema.merge_type
{
if *strategy == crate::swagger20::KubernetesListType::Atomic && keys.is_empty()
{
*strategy = crate::swagger20::KubernetesListType::Map;
*keys = vec!["metadata.name".to_string()];
return Ok(());
}
}
}
}
}
Err("never applied apps.k8s.io/v1.StatefulSetSpec volumeClaimTemplates list merge override".into())
}
// 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())
}
// `NetworkPolicySpec::podSelector`
//
// Ref: https://github.com/kubernetes/kubernetes/pull/131354
pub(crate) fn networkingv1_networkpolicyspec(spec: &mut crate::swagger20::Spec) -> Result<(), crate::Error> {
let definition_path = crate::swagger20::DefinitionPath("io.k8s.api.networking.v1.NetworkPolicySpec".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("podSelector") {
if property.1 {
property.1 = false;
return Ok(());
}
}
}
}
Err("never applied networking.k8s.io/v1.NetworkPolicySpec optional properties override".into())
}
// `StatefulSetSpec::serviceName`
//
// Ref: https://github.com/kubernetes/kubernetes/pull/130233
pub(crate) fn appsv1_statefulsetspec(spec: &mut crate::swagger20::Spec) -> Result<(), crate::Error> {
let definition_path = crate::swagger20::DefinitionPath("io.k8s.api.apps.v1.StatefulSetSpec".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("serviceName") {
if property.1 {
property.1 = false;
return Ok(());
}
}
}
}
Err("never applied apps.k8s.io/v1.StatefulSetSpec 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())
}
// `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())
}
// `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())
}
}