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
use serde::{Deserialize, Serialize};
use crate::inference::candidate::{ApiVersionCandidate, InferenceSource};
use crate::lookup::ProviderOrigin;
use super::canonicalise::{canonicalise_candidates, canonicalise_strings};
/// Identity key used to dedupe diagnostics. Diagnostics with the same
/// key are considered "the same logical event"; only the first one
/// inserted into a [`crate::diagnostic::DiagnosticSink`] is kept.
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub enum DiagnosticKey {
/// No provider could supply the requested resource schema.
MissingSchema {
/// Kubernetes resource kind.
kind: String,
/// API version requested by the chart.
api_version: String,
},
/// A compatible Kubernetes release supplied the resource schema.
ResolvedFromFallbackVersion {
/// Kubernetes resource kind.
kind: String,
/// API version requested by the chart.
api_version: String,
/// Kubernetes release that supplied the schema.
resolved_version: String,
},
/// Static or bounded fallback analysis inferred a missing API version.
InferredApiVersion {
/// Kubernetes resource kind.
kind: String,
/// API version selected by inference.
inferred_api_version: String,
/// Evidence tier that produced the candidate.
source: InferenceSource,
},
/// More than one API version remains viable for a resource kind.
AmbiguousApiVersion {
/// Kubernetes resource kind with ambiguous candidates.
kind: String,
},
/// A CRD catalog owns the group and kind but lacks the requested version.
CrdVersionNotFound {
/// CRD API group.
group: String,
/// CRD resource kind.
kind: String,
/// Version requested by the chart.
requested_version: String,
},
/// A CRD exists at versions other than the one requested.
CrdVersionAvailableAtOtherVersions {
/// CRD API group.
group: String,
/// CRD resource kind.
kind: String,
/// Version requested by the chart.
requested_version: String,
},
/// A configured local override exists but cannot be read.
LocalOverrideUnreadable {
/// Kubernetes resource kind.
kind: String,
/// API version requested by the chart.
api_version: String,
/// Filesystem path of the unreadable override.
override_path: String,
},
/// An older cache layout was invalidated before use.
CacheLayoutInvalidated {
/// Root directory containing the cache.
cache_root: String,
/// Layout marker previously found on disk.
previous_marker: Option<u32>,
},
/// The on-disk cache was written by a newer incompatible binary.
CacheLayoutForwardIncompatible {
/// Root directory containing the cache.
cache_root: String,
/// Newer layout marker found on disk.
on_disk_marker: u32,
},
/// Input channels give the same JSON number different Helm range semantics.
InputChannelNumericRangeAmbiguity {
/// Values path affected by the ambiguity.
value_path: String,
},
}
/// User-facing diagnostic. Every event helm-schema emits at runtime is
/// one of these. `Diagnostic::key` produces the deduplication key.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(tag = "type")]
pub enum Diagnostic {
/// No configured provider could supply a resource schema.
MissingSchema {
/// Kubernetes resource kind.
kind: String,
/// API version requested by the chart.
api_version: String,
/// Kubernetes releases consulted in order.
k8s_versions_tried: Vec<String>,
/// Candidate schema filenames consulted.
tried_filenames: Vec<String>,
/// Releases whose local caches contain the resource.
available_in_cache_versions: Vec<String>,
/// Older release likely to contain the removed API.
suggested_k8s_version: Option<String>,
/// Actionable context for resolving the lookup failure.
hint: Option<String>,
},
/// A fallback Kubernetes release supplied the requested API schema.
ResolvedFromFallbackVersion {
/// Kubernetes resource kind.
kind: String,
/// API version requested by the chart.
api_version: String,
/// Primary Kubernetes release selected by policy.
primary_version: String,
/// Fallback Kubernetes release that supplied the schema.
resolved_version: String,
},
/// Analysis inferred an API version omitted from the resource.
InferredApiVersion {
/// Kubernetes resource kind.
kind: String,
/// API version selected by inference.
inferred_api_version: String,
/// Evidence tier that produced the candidate.
source: InferenceSource,
/// Provider family that supplied the evidence.
origin: ProviderOrigin,
},
/// Several inferred API versions remain equally viable.
AmbiguousApiVersion {
/// Kubernetes resource kind.
kind: String,
/// Stable set of candidates and their provenance.
candidates: Vec<ApiVersionCandidate>,
},
/// A CRD catalog lacks the requested version.
CrdVersionNotFound {
/// CRD API group.
group: String,
/// CRD resource kind.
kind: String,
/// Version requested by the chart.
requested_version: String,
/// Cache paths and upstream locations consulted.
locations_tried: Vec<String>,
},
/// A CRD exists, but only at other versions.
CrdVersionAvailableAtOtherVersions {
/// CRD API group.
group: String,
/// CRD resource kind.
kind: String,
/// Version requested by the chart.
requested_version: String,
/// Versions found for the same group and kind.
available_versions: Vec<String>,
},
/// A configured local schema override could not be read.
LocalOverrideUnreadable {
/// Kubernetes resource kind.
kind: String,
/// API version requested by the chart.
api_version: String,
/// Filesystem path of the override.
override_path: String,
/// Human-readable I/O failure.
io_error: String,
},
/// An obsolete cache layout was discarded.
CacheLayoutInvalidated {
/// Root directory containing the cache.
cache_root: String,
/// Layout marker previously found on disk.
previous_marker: Option<u32>,
/// Layout marker required by this binary.
current_marker: u32,
},
/// A newer on-disk cache layout cannot be read safely.
CacheLayoutForwardIncompatible {
/// Root directory containing the cache.
cache_root: String,
/// Newer layout marker found on disk.
on_disk_marker: u32,
/// Layout marker understood by this binary.
compiled_marker: u32,
},
/// A one-variable Helm range can iterate an integer supplied through
/// `--set`, while the same JSON number supplied by a values file or
/// `--set-json` has a non-rangeable runtime kind. JSON Schema cannot
/// distinguish those input channels.
InputChannelNumericRangeAmbiguity {
/// Values path affected by channel-dependent numeric semantics.
value_path: String,
},
}
impl Diagnostic {
/// The deduplication key for this diagnostic.
#[must_use]
pub fn key(&self) -> DiagnosticKey {
match self {
Diagnostic::MissingSchema {
kind, api_version, ..
} => DiagnosticKey::MissingSchema {
kind: kind.clone(),
api_version: api_version.clone(),
},
Diagnostic::ResolvedFromFallbackVersion {
kind,
api_version,
resolved_version,
..
} => DiagnosticKey::ResolvedFromFallbackVersion {
kind: kind.clone(),
api_version: api_version.clone(),
resolved_version: resolved_version.clone(),
},
Diagnostic::InferredApiVersion {
kind,
inferred_api_version,
source,
..
} => DiagnosticKey::InferredApiVersion {
kind: kind.clone(),
inferred_api_version: inferred_api_version.clone(),
source: *source,
},
Diagnostic::AmbiguousApiVersion { kind, .. } => {
DiagnosticKey::AmbiguousApiVersion { kind: kind.clone() }
}
Diagnostic::CrdVersionNotFound {
group,
kind,
requested_version,
..
} => DiagnosticKey::CrdVersionNotFound {
group: group.clone(),
kind: kind.clone(),
requested_version: requested_version.clone(),
},
Diagnostic::CrdVersionAvailableAtOtherVersions {
group,
kind,
requested_version,
..
} => DiagnosticKey::CrdVersionAvailableAtOtherVersions {
group: group.clone(),
kind: kind.clone(),
requested_version: requested_version.clone(),
},
Diagnostic::LocalOverrideUnreadable {
kind,
api_version,
override_path,
..
} => DiagnosticKey::LocalOverrideUnreadable {
kind: kind.clone(),
api_version: api_version.clone(),
override_path: override_path.clone(),
},
Diagnostic::CacheLayoutInvalidated {
cache_root,
previous_marker,
..
} => DiagnosticKey::CacheLayoutInvalidated {
cache_root: cache_root.clone(),
previous_marker: *previous_marker,
},
Diagnostic::CacheLayoutForwardIncompatible {
cache_root,
on_disk_marker,
..
} => DiagnosticKey::CacheLayoutForwardIncompatible {
cache_root: cache_root.clone(),
on_disk_marker: *on_disk_marker,
},
Diagnostic::InputChannelNumericRangeAmbiguity { value_path } => {
DiagnosticKey::InputChannelNumericRangeAmbiguity {
value_path: value_path.clone(),
}
}
}
}
/// Canonicalise mutable list fields so two emissions of the same
/// logical event produce identical payloads regardless of probe
/// order.
pub(crate) fn canonicalise(&mut self) {
match self {
Diagnostic::MissingSchema {
k8s_versions_tried,
tried_filenames,
available_in_cache_versions,
..
} => {
canonicalise_strings(k8s_versions_tried);
canonicalise_strings(tried_filenames);
canonicalise_strings(available_in_cache_versions);
}
Diagnostic::AmbiguousApiVersion { candidates, .. } => {
canonicalise_candidates(candidates);
}
Diagnostic::CrdVersionNotFound {
locations_tried, ..
} => canonicalise_strings(locations_tried),
Diagnostic::CrdVersionAvailableAtOtherVersions {
available_versions, ..
} => canonicalise_strings(available_versions),
Diagnostic::ResolvedFromFallbackVersion { .. }
| Diagnostic::InferredApiVersion { .. }
| Diagnostic::LocalOverrideUnreadable { .. }
| Diagnostic::CacheLayoutInvalidated { .. }
| Diagnostic::CacheLayoutForwardIncompatible { .. }
| Diagnostic::InputChannelNumericRangeAmbiguity { .. } => {}
}
}
}