modelexpress_server/registry/
k8s_types.rs1use kube::CustomResource;
12use schemars::JsonSchema;
13use serde::{Deserialize, Serialize};
14
15#[derive(CustomResource, Clone, Debug, Deserialize, Serialize, JsonSchema)]
17#[kube(
18 group = "modelexpress.nvidia.com",
19 version = "v1alpha1",
20 kind = "ModelCacheEntry",
21 plural = "modelcacheentries",
22 shortname = "mxcache",
23 namespaced,
24 status = "ModelCacheEntryStatus",
25 doc = "ModelExpress model-download lifecycle metadata",
26 printcolumn = r#"{"name":"Model","type":"string","jsonPath":".spec.modelName"}"#,
27 printcolumn = r#"{"name":"Phase","type":"string","jsonPath":".status.phase"}"#,
28 printcolumn = r#"{"name":"LastUsed","type":"date","jsonPath":".status.lastUsedAt"}"#,
29 printcolumn = r#"{"name":"Claim","type":"string","jsonPath":".status.claimId","priority":1}"#,
30 printcolumn = r#"{"name":"Lease","type":"date","jsonPath":".status.leaseExpiresAt","priority":1}"#,
31 printcolumn = r#"{"name":"Age","type":"date","jsonPath":".metadata.creationTimestamp"}"#
32)]
33pub struct ModelCacheEntrySpec {
34 #[serde(rename = "modelName")]
38 pub model_name: String,
39
40 #[schemars(with = "ProviderSchema")]
42 pub provider: String,
43}
44
45#[derive(Clone, Debug, Default, Deserialize, Serialize, JsonSchema)]
47pub struct ModelCacheEntryStatus {
48 #[serde(default)]
51 #[schemars(with = "PhaseSchema")]
52 pub phase: String,
53
54 #[serde(rename = "createdAt", default)]
56 #[schemars(with = "Option<chrono::DateTime<chrono::Utc>>")]
57 pub created_at: Option<String>,
58
59 #[serde(rename = "lastUsedAt", default)]
61 #[schemars(with = "Option<chrono::DateTime<chrono::Utc>>")]
62 pub last_used_at: Option<String>,
63
64 #[serde(default)]
66 pub message: Option<String>,
67
68 #[serde(rename = "claimId", default)]
70 pub claim_id: Option<String>,
71
72 #[serde(rename = "leaseExpiresAt", default)]
75 #[schemars(with = "Option<chrono::DateTime<chrono::Utc>>")]
76 pub lease_expires_at: Option<String>,
77}
78
79#[derive(JsonSchema)]
80#[allow(dead_code)]
81enum ProviderSchema {
82 HuggingFace,
83 Ngc,
84 Gcs,
85 S3,
86}
87
88#[derive(JsonSchema)]
89#[allow(dead_code)]
90enum PhaseSchema {
91 #[schemars(rename = "")]
92 Empty,
93 Downloading,
94 Downloaded,
95 Error,
96}
97
98pub mod phase {
100 pub const DOWNLOADING: &str = "Downloading";
101 pub const DOWNLOADED: &str = "Downloaded";
102 pub const ERROR: &str = "Error";
103}
104
105#[cfg(test)]
106#[allow(clippy::expect_used)]
107mod tests {
108 use super::*;
109
110 #[test]
111 fn spec_roundtrips_through_json() {
112 let spec = ModelCacheEntrySpec {
113 model_name: "meta-llama/Llama-3.1-70B".to_string(),
114 provider: "HuggingFace".to_string(),
115 };
116 let json = serde_json::to_string(&spec).expect("serialize");
117 assert!(json.contains("\"modelName\":\"meta-llama/Llama-3.1-70B\""));
118 let back: ModelCacheEntrySpec = serde_json::from_str(&json).expect("deserialize");
119 assert_eq!(back.model_name, spec.model_name);
120 assert_eq!(back.provider, spec.provider);
121 }
122
123 #[test]
124 fn status_default_is_empty() {
125 let status = ModelCacheEntryStatus::default();
126 assert_eq!(status.phase, "");
127 assert!(status.created_at.is_none());
128 assert!(status.last_used_at.is_none());
129 assert!(status.message.is_none());
130 assert!(status.claim_id.is_none());
131 assert!(status.lease_expires_at.is_none());
132 }
133}