1- use std:: borrow:: Cow ;
2-
31use k8s_openapi:: apimachinery:: pkg:: apis:: meta:: v1:: Time ;
42use kube:: CustomResource ;
53use schemars:: JsonSchema ;
@@ -21,7 +19,7 @@ pub mod versioned {
2119 ) ,
2220 namespaced
2321 ) ) ]
24- #[ derive( Clone , Debug , PartialEq , CustomResource , Deserialize , Serialize , JsonSchema ) ]
22+ #[ derive( Clone , Debug , PartialEq , Eq , CustomResource , Deserialize , Serialize , JsonSchema ) ]
2523 pub struct ScalerSpec {
2624 /// Desired replica count.
2725 ///
@@ -40,7 +38,7 @@ pub mod versioned {
4038}
4139
4240/// Status of a StackableScaler.
43- #[ derive( Clone , Debug , Deserialize , Serialize , JsonSchema ) ]
41+ #[ derive( Clone , Debug , PartialEq , Eq , Deserialize , Serialize , JsonSchema ) ]
4442#[ serde( rename_all = "camelCase" ) ]
4543pub struct ScalerStatus {
4644 /// The current total number of replicas targeted by the managed StatefulSet.
@@ -59,25 +57,15 @@ pub struct ScalerStatus {
5957 pub last_transition_time : Time ,
6058}
6159
62- // We use `#[serde(tag)]` and `#[serde(content)]` here to circumvent Kubernetes restrictions in their
63- // structural schema subset of OpenAPI schemas. They don't allow one variant to be typed as a string
64- // and others to be typed as objects. We therefore encode the variant data in a separate details
65- // key/object. With this, all variants can be encoded as strings, while the status can still contain
66- // additional data in an extra field when needed.
67- #[ derive( Clone , Debug , Deserialize , Serialize , strum:: Display ) ]
68- #[ serde(
69- tag = "state" ,
70- content = "details" ,
71- rename_all = "camelCase" ,
72- rename_all_fields = "camelCase"
73- ) ]
60+ #[ derive( Clone , Debug , PartialEq , Eq , Deserialize , Serialize , JsonSchema , strum:: Display ) ]
61+ #[ serde( rename_all = "camelCase" , rename_all_fields = "camelCase" ) ]
7462#[ strum( serialize_all = "camelCase" ) ]
7563pub enum ScalerState {
7664 /// No scaling operation is in progress.
77- Idle ,
65+ Idle { } ,
7866
7967 /// Running the `pre_scale` hook (e.g. data offload).
80- PreScaling ,
68+ PreScaling { } ,
8169
8270 /// Waiting for the StatefulSet to converge to the new replica count.
8371 ///
@@ -104,44 +92,9 @@ pub enum ScalerState {
10492 } ,
10593}
10694
107- // We manually implement the JSON schema instead of deriving it, because kube's schema transformer
108- // cannot handle the derived JsonSchema and proceeds to hit the following error: "Property "state"
109- // has the schema ... but was already defined as ... in another subschema. The schemas for a
110- // property used in multiple subschemas must be identical".
111- impl JsonSchema for ScalerState {
112- fn schema_name ( ) -> Cow < ' static , str > {
113- "ScalerState" . into ( )
114- }
115-
116- fn json_schema ( generator : & mut schemars:: generate:: SchemaGenerator ) -> schemars:: Schema {
117- schemars:: json_schema!( {
118- "type" : "object" ,
119- "required" : [ "state" ] ,
120- "properties" : {
121- "state" : {
122- "type" : "string" ,
123- "enum" : [ "idle" , "preScaling" , "scaling" , "postScaling" , "failed" ]
124- } ,
125- "details" : {
126- "type" : "object" ,
127- "properties" : {
128- "failedIn" : generator. subschema_for:: <FailedInState >( ) ,
129- "previous_replicas" : {
130- "type" : "uint16" ,
131- "minimum" : u16 :: MIN ,
132- "maximum" : u16 :: MAX
133- } ,
134- "reason" : { "type" : "string" }
135- }
136- }
137- }
138- } )
139- }
140- }
141-
14295/// In which state the scaling operation failed.
143- #[ derive( Clone , Debug , Deserialize , Serialize , JsonSchema ) ]
144- #[ serde( rename_all = "camelCase " ) ]
96+ #[ derive( Clone , Debug , PartialEq , Eq , Deserialize , Serialize , JsonSchema ) ]
97+ #[ serde( rename_all = "PascalCase " ) ]
14598pub enum FailedInState {
14699 /// The `pre_scale` hook returned an error.
147100 PreScaling ,
0 commit comments