|
| 1 | +use std::borrow::Cow; |
| 2 | + |
1 | 3 | use k8s_openapi::apimachinery::pkg::apis::meta::v1::Time; |
2 | 4 | use kube::CustomResource; |
3 | 5 | use schemars::JsonSchema; |
@@ -57,8 +59,13 @@ pub struct ScalerStatus { |
57 | 59 | pub last_transition_time: Time, |
58 | 60 | } |
59 | 61 |
|
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 | +)] |
62 | 69 | #[strum(serialize_all = "camelCase")] |
63 | 70 | pub enum ScalerState { |
64 | 71 | /// No scaling operation is in progress. |
@@ -92,6 +99,37 @@ pub enum ScalerState { |
92 | 99 | }, |
93 | 100 | } |
94 | 101 |
|
| 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 | + |
95 | 133 | /// Which stage of a scaling operation failed. |
96 | 134 | #[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)] |
97 | 135 | #[serde(rename_all = "camelCase")] |
|
0 commit comments