Skip to content

Commit fc4aef4

Browse files
committed
fix: Adjust status representation/schema
1 parent 8d69f3b commit fc4aef4

1 file changed

Lines changed: 40 additions & 2 deletions

File tree

  • crates/stackable-operator/src/crd/scaler

crates/stackable-operator/src/crd/scaler/mod.rs

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::borrow::Cow;
2+
13
use k8s_openapi::apimachinery::pkg::apis::meta::v1::Time;
24
use kube::CustomResource;
35
use schemars::JsonSchema;
@@ -57,8 +59,13 @@ pub struct ScalerStatus {
5759
pub last_transition_time: Time,
5860
}
5961

60-
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema, strum::Display)]
61-
#[serde(rename_all = "camelCase", rename_all_fields = "camelCase")]
62+
#[derive(Clone, Debug, Deserialize, Serialize, strum::Display)]
63+
#[serde(
64+
tag = "state",
65+
content = "details",
66+
rename_all = "camelCase",
67+
rename_all_fields = "camelCase"
68+
)]
6269
#[strum(serialize_all = "camelCase")]
6370
pub enum ScalerState {
6471
/// No scaling operation is in progress.
@@ -92,6 +99,37 @@ pub enum ScalerState {
9299
},
93100
}
94101

102+
impl JsonSchema for ScalerState {
103+
fn schema_name() -> Cow<'static, str> {
104+
"ScalerState".into()
105+
}
106+
107+
fn json_schema(generator: &mut schemars::generate::SchemaGenerator) -> schemars::Schema {
108+
schemars::json_schema!({
109+
"type": "object",
110+
"required": ["state"],
111+
"properties": {
112+
"state": {
113+
"type": "string",
114+
"enum": ["idle", "preScaling", "scaling", "postScaling", "failed"]
115+
},
116+
"details": {
117+
"type": "object",
118+
"properties": {
119+
"failedIn": generator.subschema_for::<FailedInState>(),
120+
"previous_replicas": {
121+
"type": "uint16",
122+
"minimum": u16::MIN,
123+
"maximum": u16::MAX
124+
},
125+
"reason": { "type": "string" }
126+
}
127+
}
128+
}
129+
})
130+
}
131+
}
132+
95133
/// Which stage of a scaling operation failed.
96134
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
97135
#[serde(rename_all = "camelCase")]

0 commit comments

Comments
 (0)