|
1 | 1 | //! The definition for host system state. |
2 | 2 |
|
3 | | -use k8s_openapi::apimachinery::pkg::apis::meta::v1 as k8smeta; |
4 | | -use kube::CustomResource; |
5 | 3 | use schemars::JsonSchema; |
6 | 4 | use serde::{Deserialize, Serialize}; |
7 | 5 |
|
8 | | -/// Representation of a bootc host system |
9 | | -#[derive( |
10 | | - CustomResource, Serialize, Deserialize, Default, Debug, PartialEq, Eq, Clone, JsonSchema, |
11 | | -)] |
12 | | -#[kube( |
13 | | - group = "org.containers.bootc", |
14 | | - version = "v1alpha1", |
15 | | - kind = "BootcHost", |
16 | | - struct = "Host", |
17 | | - namespaced, |
18 | | - status = "HostStatus", |
19 | | - derive = "PartialEq", |
20 | | - derive = "Default" |
21 | | -)] |
| 6 | +use crate::k8sapitypes; |
| 7 | + |
| 8 | +const API_VERSION: &str = "org.containers.bootc/v1alpha1"; |
| 9 | +const KIND: &str = "BootcHost"; |
| 10 | + |
| 11 | +#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)] |
| 12 | +#[serde(rename_all = "camelCase")] |
| 13 | +/// The core host definition |
| 14 | +pub struct Host { |
| 15 | + /// Metadata |
| 16 | + #[serde(flatten)] |
| 17 | + pub resource: k8sapitypes::Resource, |
| 18 | + /// The spec |
| 19 | + #[serde(default)] |
| 20 | + pub spec: HostSpec, |
| 21 | + /// The status |
| 22 | + pub status: Option<HostStatus>, |
| 23 | +} |
| 24 | + |
| 25 | +#[derive(Serialize, Deserialize, Default, Debug, Clone, PartialEq, Eq)] |
22 | 26 | #[serde(rename_all = "camelCase")] |
| 27 | +/// The host specification |
23 | 28 | pub struct HostSpec { |
24 | 29 | /// The host image |
25 | 30 | pub image: Option<ImageReference>, |
@@ -58,7 +63,7 @@ pub struct ImageStatus { |
58 | 63 | /// The version string, if any |
59 | 64 | pub version: Option<String>, |
60 | 65 | /// The build timestamp, if any |
61 | | - pub timestamp: Option<k8smeta::Time>, |
| 66 | + pub timestamp: Option<chrono::DateTime<chrono::Utc>>, |
62 | 67 | /// The digest of the fetched image (e.g. sha256:a0...); |
63 | 68 | pub image_digest: String, |
64 | 69 | } |
@@ -102,6 +107,25 @@ pub struct HostStatus { |
102 | 107 | pub is_container: bool, |
103 | 108 | } |
104 | 109 |
|
| 110 | +impl Host { |
| 111 | + /// Create a new host |
| 112 | + pub fn new(name: &str, spec: HostSpec) -> Self { |
| 113 | + let metadata = k8sapitypes::ObjectMeta { |
| 114 | + name: Some(name.to_owned()), |
| 115 | + ..Default::default() |
| 116 | + }; |
| 117 | + Self { |
| 118 | + resource: k8sapitypes::Resource { |
| 119 | + api_version: API_VERSION.to_owned(), |
| 120 | + kind: KIND.to_owned(), |
| 121 | + metadata, |
| 122 | + }, |
| 123 | + spec, |
| 124 | + status: None, |
| 125 | + } |
| 126 | + } |
| 127 | +} |
| 128 | + |
105 | 129 | #[cfg(test)] |
106 | 130 | mod tests { |
107 | 131 | use super::*; |
|
0 commit comments