cdl_openapi/
model_claim.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
use chrono::{DateTime, Utc};
use k8s_openapi::api::core::v1::ResourceRequirements;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use strum::{Display, EnumString};

use crate::model_storage::ModelStorageKind;

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(feature = "k8s", derive(::kube::CustomResource))]
#[cfg_attr(
    feature = "k8s",
    kube(
        group = "cdl.ulagbulag.io",
        version = "v1alpha1",
        kind = "ModelClaim",
        root = "ModelClaimCrd",
        status = "ModelClaimStatus",
        shortname = "mc",
        namespaced,
        printcolumn = r#"{
            "name": "sto`rage",
            "type": "string",
            "description": "attached storage name",
            "jsonPath": ".spec.storageName"
        }"#,
        printcolumn = r#"{
            "name": "state",
            "type": "string",
            "description": "state of the model claim",
            "jsonPath": ".status.state"
        }"#,
        printcolumn = r#"{
            "name": "created-at",
            "type": "date",
            "description": "created time",
            "jsonPath": ".metadata.creationTimestamp"
        }"#,
        printcolumn = r#"{
            "name": "updated-at",
            "type": "date",
            "description": "updated time",
            "jsonPath": ".status.lastUpdated"
        }"#,
        printcolumn = r#"{
            "name": "version",
            "type": "integer",
            "description": "model claim version",
            "jsonPath": ".metadata.generation"
        }"#,
    )
)]
#[serde(rename_all = "camelCase")]
pub struct ModelClaimSpec {
    #[serde(default)]
    pub affinity: ModelClaimAffinity,
    #[serde(default = "ModelClaimSpec::default_allow_replacement")]
    pub allow_replacement: bool,
    #[serde(default)]
    pub binding_policy: ModelClaimBindingPolicy,
    #[serde(default)]
    pub deletion_policy: ModelClaimDeletionPolicy,
    #[serde(default)]
    pub resources: Option<ResourceRequirements>,
    #[serde(default)]
    pub storage: Option<ModelStorageKind>,
    #[serde(default)]
    pub storage_name: Option<String>,
}

#[cfg(feature = "k8s")]
impl ModelClaimCrd {
    pub const FINALIZER_NAME: &'static str = "cdl.ulagbulag.io/finalizer-model-claims";
}

impl Default for ModelClaimSpec {
    fn default() -> Self {
        Self {
            affinity: ModelClaimAffinity::default(),
            allow_replacement: Self::default_allow_replacement(),
            binding_policy: ModelClaimBindingPolicy::default(),
            deletion_policy: ModelClaimDeletionPolicy::default(),
            resources: None,
            storage: None,
            storage_name: None,
        }
    }
}

impl ModelClaimSpec {
    const fn default_allow_replacement() -> bool {
        true
    }
}

#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "camelCase")]
pub struct ModelClaimAffinity {
    #[serde(default)]
    pub placement_affinity: ModelClaimAffinityRequirements,
    #[serde(default)]
    pub replacement_affinity: ModelClaimAffinityRequirements,
}

#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "camelCase")]
pub struct ModelClaimAffinityRequirements {
    #[serde(default)]
    pub preferred: Vec<ModelClaimPreferredAffinity>,
    #[serde(default)]
    pub required: Vec<ModelClaimAffinityPreference>,
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "camelCase")]
pub struct ModelClaimPreferredAffinity {
    #[serde(default, flatten)]
    pub base: ModelClaimAffinityPreference,
    pub weight: u8,
}

#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "camelCase")]
pub struct ModelClaimAffinityPreference {
    #[serde(default)]
    pub match_expressions: Vec<ModelClaimAffinityExpression>,
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "camelCase")]
pub struct ModelClaimAffinityExpression {
    pub query: String,
    #[serde(default)]
    pub source: ModelClaimAffinityExpressionSource,
}

#[derive(
    Copy,
    Clone,
    Debug,
    Display,
    Default,
    EnumString,
    PartialEq,
    Eq,
    PartialOrd,
    Ord,
    Hash,
    Serialize,
    Deserialize,
    JsonSchema,
)]
pub enum ModelClaimAffinityExpressionSource {
    #[default]
    Prometheus,
}

#[derive(
    Copy,
    Clone,
    Debug,
    Display,
    Default,
    EnumString,
    PartialEq,
    Eq,
    PartialOrd,
    Ord,
    Hash,
    Serialize,
    Deserialize,
    JsonSchema,
)]
pub enum ModelClaimBindingPolicy {
    Balanced,
    #[default]
    LowestCopy,
    LowestLatency,
}

#[derive(
    Copy,
    Clone,
    Debug,
    Display,
    Default,
    EnumString,
    PartialEq,
    Eq,
    PartialOrd,
    Ord,
    Hash,
    Serialize,
    Deserialize,
    JsonSchema,
)]
pub enum ModelClaimDeletionPolicy {
    Delete,
    #[default]
    Retain,
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "camelCase")]
pub struct ModelClaimStatus {
    #[serde(default)]
    pub state: ModelClaimState,
    #[serde(default)]
    pub resources: Option<ResourceRequirements>,
    #[serde(default)]
    pub storage: Option<ModelStorageKind>,
    #[serde(default)]
    pub storage_name: Option<String>,
    pub last_updated: DateTime<Utc>,
}

#[derive(
    Copy,
    Clone,
    Debug,
    Display,
    Default,
    EnumString,
    PartialEq,
    Eq,
    PartialOrd,
    Ord,
    Hash,
    Serialize,
    Deserialize,
    JsonSchema,
)]
pub enum ModelClaimState {
    #[default]
    Pending,
    Ready,
    Replacing,
    Deleting,
}