Skip to content

Commit de8db62

Browse files
committed
chore(stackable-versioned): Move K8s related error enums
1 parent bc7da2b commit de8db62

File tree

2 files changed

+38
-37
lines changed

2 files changed

+38
-37
lines changed

crates/stackable-versioned/src/k8s.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
use std::collections::HashMap;
22

33
use k8s_version::Version;
4+
#[cfg(doc)]
5+
use kube::core::conversion::ConversionReview;
46
use schemars::schema::{InstanceType, Schema, SchemaObject, SingleOrVec};
7+
use snafu::Snafu;
58

69
// NOTE (@Techassi): This struct represents a rough first draft of how tracking values across
710
// CRD versions can be achieved. It is currently untested and unproven and might change down the
811
// line. Currently, this struct is only generated by the macro but not actually used by any other
912
// code. The tracking itself will be introduced in a follow-up PR.
13+
/// Contains changed values during upgrades and downgrades of CRDs.
1014
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
1115
pub struct ChangedValues {
1216
/// List of values needed when downgrading to a particular version.
@@ -16,6 +20,7 @@ pub struct ChangedValues {
1620
pub upgrades: HashMap<Version, Vec<ChangedValue>>,
1721
}
1822

23+
/// Contains a changed value for a single field of the CRD.
1924
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
2025
pub struct ChangedValue {
2126
/// 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 {
4045
..Default::default()
4146
})
4247
}
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+
}

crates/stackable-versioned/src/lib.rs

Lines changed: 6 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
1-
//! This crate enables versioning of structs and enums through procedural
2-
//! macros.
1+
//! This crate enables versioning of structs and enums through procedural macros.
32
//!
43
//! Currently supported versioning schemes:
54
//!
6-
//! - Kubernetes API versions (eg: `v1alpha1`, `v1beta1`, `v1`, `v2`), with
7-
//! optional support for generating CRDs.
5+
//! - Kubernetes API versions (eg: `v1alpha1`, `v1beta1`, `v1`, `v2`), with optional support for
6+
//! generating CRDs.
87
//!
9-
//! Support will be extended to SemVer versions, as well as custom version
10-
//! formats in the future.
8+
//! Support will be extended to SemVer versions, as well as custom version formats in the future.
119
//!
12-
//! See [`versioned`] for an in-depth usage guide and a list of supported
13-
//! parameters.
14-
use snafu::Snafu;
10+
//! See [`versioned`] for an in-depth usage guide and a list of supported arguments.
11+
1512
// Re-exports
1613
pub use stackable_versioned_macros::versioned;
1714

@@ -20,31 +17,3 @@ pub use stackable_versioned_macros::versioned;
2017
mod k8s;
2118
#[cfg(feature = "k8s")]
2219
pub use k8s::*;
23-
24-
// Behind flux-converter feature
25-
// #[cfg(feature = "flux-converter")]
26-
// pub mod flux_converter;
27-
28-
#[derive(Debug, Snafu)]
29-
pub enum ParseObjectError {
30-
#[snafu(display(r#"failed to find "apiVersion" field"#))]
31-
FieldNotPresent,
32-
33-
#[snafu(display(r#"the "apiVersion" field is not a string"#))]
34-
FieldNotStr,
35-
36-
#[snafu(display("encountered unknown object api version {api_version:?}"))]
37-
UnknownApiVersion { api_version: String },
38-
39-
#[snafu(display("failed to deserialize object from json"))]
40-
Deserialize { source: serde_json::Error },
41-
}
42-
43-
#[derive(Debug, Snafu)]
44-
pub enum ConvertObjectError {
45-
#[snafu(display("failed to parse object"))]
46-
Parse { source: ParseObjectError },
47-
48-
#[snafu(display("failed to serialize object into json"))]
49-
Serialize { source: serde_json::Error },
50-
}

0 commit comments

Comments
 (0)