Skip to content

Commit 1a0fcc3

Browse files
committed
refactor(stackable-versioned): Move status struct behind feature flag
1 parent abf5deb commit 1a0fcc3

File tree

2 files changed

+47
-42
lines changed

2 files changed

+47
-42
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
use std::collections::HashMap;
2+
3+
use k8s_version::Version;
4+
use schemars::schema::{InstanceType, Schema, SchemaObject, SingleOrVec};
5+
6+
// NOTE (@Techassi): This struct represents a rough first draft of how tracking values across
7+
// CRD versions can be achieved. It is currently untested and unproven and might change down the
8+
// line. Currently, this struct is only generated by the macro but not actually used by any other
9+
// code. The tracking itself will be introduced in a follow-up PR.
10+
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
11+
pub struct ChangedValues {
12+
/// List of values needed when downgrading to a particular version.
13+
pub downgrades: HashMap<Version, Vec<ChangedValue>>,
14+
15+
/// List of values needed when upgrading to a particular version.
16+
pub upgrades: HashMap<Version, Vec<ChangedValue>>,
17+
}
18+
19+
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
20+
pub struct ChangedValue {
21+
/// The name of the field of the custom resource this value is for.
22+
pub name: String,
23+
24+
/// The value to be used when upgrading or downgrading the custom resource.
25+
#[schemars(schema_with = "raw_object_schema")]
26+
pub value: serde_yaml::Value,
27+
}
28+
29+
// TODO (@Techassi): Think about where this should live. Basically this already exists in
30+
// stackable-operator, but we cannot use it without depending on it which I would like to
31+
// avoid.
32+
fn raw_object_schema(_: &mut schemars::r#gen::SchemaGenerator) -> Schema {
33+
Schema::Object(SchemaObject {
34+
instance_type: Some(SingleOrVec::Single(Box::new(InstanceType::Object))),
35+
extensions: [(
36+
"x-kubernetes-preserve-unknown-fields".to_owned(),
37+
serde_json::Value::Bool(true),
38+
)]
39+
.into(),
40+
..Default::default()
41+
})
42+
}

crates/stackable-versioned/src/lib.rs

Lines changed: 5 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -12,47 +12,10 @@
1212
//! See [`versioned`] for an in-depth usage guide and a list of supported
1313
//! parameters.
1414
15-
use std::collections::HashMap;
16-
17-
use k8s_version::Version;
18-
use schemars::schema::{InstanceType, Schema, SchemaObject, SingleOrVec};
1915
// Re-export macro
20-
pub use stackable_versioned_macros::*;
21-
22-
// NOTE (@Techassi): This struct represents a rough first draft of how tracking values across
23-
// CRD versions can be achieved. It is currently untested and unproven and might change down the
24-
// line. Currently, this struct is only generated by the macro but not actually used by any other
25-
// code. The tracking itself will be introduced in a follow-up PR.
26-
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
27-
pub struct ChangedValues {
28-
/// List of values needed when downgrading to a particular version.
29-
pub downgrades: HashMap<Version, Vec<ChangedValue>>,
30-
31-
/// List of values needed when upgrading to a particular version.
32-
pub upgrades: HashMap<Version, Vec<ChangedValue>>,
33-
}
34-
35-
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
36-
pub struct ChangedValue {
37-
/// The name of the field of the custom resource this value is for.
38-
pub name: String,
39-
40-
/// The value to be used when upgrading or downgrading the custom resource.
41-
#[schemars(schema_with = "raw_object_schema")]
42-
pub value: serde_yaml::Value,
43-
}
16+
#[cfg(feature = "k8s")]
17+
pub use k8s::*;
18+
pub use stackable_versioned_macros::versioned;
4419

45-
// TODO (@Techassi): Think about where this should live. Basically this already exists in
46-
// stackable-operator, but we cannot use it without depending on it which I would like to
47-
// avoid.
48-
fn raw_object_schema(_: &mut schemars::r#gen::SchemaGenerator) -> Schema {
49-
Schema::Object(SchemaObject {
50-
instance_type: Some(SingleOrVec::Single(Box::new(InstanceType::Object))),
51-
extensions: [(
52-
"x-kubernetes-preserve-unknown-fields".to_owned(),
53-
serde_json::Value::Bool(true),
54-
)]
55-
.into(),
56-
..Default::default()
57-
})
58-
}
20+
#[cfg(feature = "k8s")]
21+
mod k8s;

0 commit comments

Comments
 (0)