1
1
use std:: collections:: HashMap ;
2
2
3
3
use k8s_version:: Version ;
4
+ #[ cfg( doc) ]
5
+ use kube:: core:: conversion:: ConversionReview ;
4
6
use schemars:: schema:: { InstanceType , Schema , SchemaObject , SingleOrVec } ;
7
+ use snafu:: Snafu ;
5
8
6
9
// NOTE (@Techassi): This struct represents a rough first draft of how tracking values across
7
10
// CRD versions can be achieved. It is currently untested and unproven and might change down the
8
11
// line. Currently, this struct is only generated by the macro but not actually used by any other
9
12
// code. The tracking itself will be introduced in a follow-up PR.
13
+ /// Contains changed values during upgrades and downgrades of CRDs.
10
14
#[ derive( Clone , Debug , serde:: Deserialize , serde:: Serialize , schemars:: JsonSchema ) ]
11
15
pub struct ChangedValues {
12
16
/// List of values needed when downgrading to a particular version.
@@ -16,6 +20,7 @@ pub struct ChangedValues {
16
20
pub upgrades : HashMap < Version , Vec < ChangedValue > > ,
17
21
}
18
22
23
+ /// Contains a changed value for a single field of the CRD.
19
24
#[ derive( Clone , Debug , serde:: Deserialize , serde:: Serialize , schemars:: JsonSchema ) ]
20
25
pub struct ChangedValue {
21
26
/// The name of the field of the custom resource this value is for.
@@ -40,3 +45,30 @@ fn raw_object_schema(_: &mut schemars::r#gen::SchemaGenerator) -> Schema {
40
45
..Default :: default ( )
41
46
} )
42
47
}
48
+
49
+ /// This error indicates that parsing an object from a [`ConversionReview`] failed.
50
+ #[ derive( Debug , Snafu ) ]
51
+ pub enum ParseObjectError {
52
+ #[ snafu( display( r#"failed to find "apiVersion" field"# ) ) ]
53
+ FieldNotPresent ,
54
+
55
+ #[ snafu( display( r#"the "apiVersion" field is not a string"# ) ) ]
56
+ FieldNotStr ,
57
+
58
+ #[ snafu( display( "encountered unknown object api version {api_version:?}" ) ) ]
59
+ UnknownApiVersion { api_version : String } ,
60
+
61
+ #[ snafu( display( "failed to deserialize object from json" ) ) ]
62
+ Deserialize { source : serde_json:: Error } ,
63
+ }
64
+
65
+ /// This error indicates that converting an object from a [`ConversionReview`] to the desired
66
+ /// version failed.
67
+ #[ derive( Debug , Snafu ) ]
68
+ pub enum ConvertObjectError {
69
+ #[ snafu( display( "failed to parse object" ) ) ]
70
+ Parse { source : ParseObjectError } ,
71
+
72
+ #[ snafu( display( "failed to serialize object into json" ) ) ]
73
+ Serialize { source : serde_json:: Error } ,
74
+ }
0 commit comments