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
use crate::SPU_API;
use k8_obj_metadata::Crd;
use k8_obj_metadata::Spec;
use k8_obj_core::pod::ContainerPortSpec;
use k8_obj_core::service::ServicePort;
use serde::Deserialize;
use serde::Serialize;
use super::SpuStatus;
impl Spec for SpuSpec {
type Status = SpuStatus;
fn metadata() -> &'static Crd {
&SPU_API
}
}
#[derive(Deserialize, Serialize, Debug, PartialEq, Default, Clone)]
#[serde(rename_all = "camelCase")]
pub struct SpuSpec {
pub spu_id: i32,
pub public_endpoint: IngressPort,
pub private_endpoint: Endpoint,
#[serde(skip_serializing_if = "Option::is_none")]
pub spu_type: Option<SpuType>,
#[serde(skip_serializing_if = "Option::is_none")]
pub rack: Option<String>,
}
#[derive(Deserialize, Serialize, Debug, PartialEq, Clone)]
pub enum SpuType {
Managed,
Custom,
}
#[derive(Deserialize, Serialize, Debug, PartialEq, Default, Clone)]
#[serde(rename_all = "camelCase", default)]
pub struct IngressPort {
pub port: u16,
pub ingress: Vec<IngressAddr>,
pub encryption: EncryptionEnum,
}
#[derive(Deserialize, Serialize, Debug, PartialEq, Default, Clone)]
pub struct IngressAddr {
pub hostname: Option<String>,
pub ip: Option<String>,
}
#[derive(Deserialize, Serialize, Debug, PartialEq, Default, Clone)]
#[serde(rename_all = "camelCase")]
pub struct Endpoint {
pub port: u16,
pub host: String,
pub encryption: EncryptionEnum,
}
#[derive(Deserialize, Serialize, Debug, PartialEq, Clone)]
pub enum EncryptionEnum {
PLAINTEXT,
SSL,
}
impl Endpoint {
pub fn new(port: u16, host: String) -> Self {
Endpoint {
port,
host,
encryption: EncryptionEnum::PLAINTEXT,
}
}
}
impl From<&Endpoint> for ContainerPortSpec {
fn from(end_point: &Endpoint) -> Self {
ContainerPortSpec {
container_port: end_point.port,
..Default::default()
}
}
}
impl From<&Endpoint> for ServicePort {
fn from(end_point: &Endpoint) -> Self {
ServicePort {
port: end_point.port,
..Default::default()
}
}
}
impl Default for EncryptionEnum {
fn default() -> EncryptionEnum {
EncryptionEnum::PLAINTEXT
}
}