Skip to main content

devops_armory/cloud/gcp/gke/deployment/
models.rs

1use serde_derive::{Serialize, Deserialize};
2
3#[derive(Serialize, Deserialize, Default,Debug)]
4pub struct CreateDeployment {
5    pub apiVersion: String,
6    pub kind: String,
7    pub metadata: DeploymentMetadata,
8    pub spec: DeploymentSpec,
9}
10
11#[derive(Serialize, Deserialize, Default,Debug)]
12pub struct DeploymentMetadata {
13    pub name: String,
14    pub labels: DeploymentMetadataLabels,
15    pub namespace: String
16}
17
18#[derive(Serialize, Deserialize, Default,Debug)]
19pub struct DeploymentMetadataLabels {
20    pub app: String
21}
22
23#[derive(Serialize, Deserialize, Default,Debug)]
24pub struct DeploymentSpec {
25    pub strategy: DeploymentSpecStrategy,
26    pub replicas: i32,
27    pub selector: DeploymentSelector,
28    pub template: DeploymentTemplate,
29}
30
31#[derive(Serialize, Deserialize, Default,Debug)]
32pub struct DeploymentSpecStrategy {
33    pub r#type: String,
34    pub rollingUpdate: RollingUpdate
35}
36
37#[derive(Serialize, Deserialize, Default,Debug)]
38pub struct RollingUpdate {
39    pub maxSurge: String,
40    pub maxUnavailable: String,
41}
42
43#[derive(Serialize, Deserialize, Default,Debug)]
44pub struct DeploymentSelector {
45    pub matchLabels: SelectorLabels
46}
47
48#[derive(Serialize, Deserialize, Default,Debug)]
49pub struct SelectorLabels {
50    pub app: String
51}
52
53#[derive(Serialize, Deserialize, Default,Debug)]
54pub struct DeploymentTemplate {
55    pub metadata: DeploymentTemplateMetadata,
56    pub spec: DeploymentTemplateSpec
57}
58
59#[derive(Serialize, Deserialize, Default,Debug)]
60pub struct DeploymentTemplateMetadata {
61    pub labels: DeploymentTemplateMetadataLabels
62}
63
64#[derive(Serialize, Deserialize, Default,Debug)]
65pub struct DeploymentTemplateMetadataLabels {
66    pub app: String
67}
68
69#[derive(Serialize, Deserialize, Default,Debug)]
70pub struct DeploymentTemplateSpec {
71    pub restartPolicy: String,
72    pub dnsPolicy: String,
73    pub terminationGracePeriodSeconds: i64,
74    pub containers: Vec<DeploymentContainers>
75}
76
77#[derive(Serialize, Deserialize, Default,Debug)]
78pub struct DeploymentContainers {
79    pub name: String,
80    pub image: String,
81    pub imagePullPolicy: String,
82    pub command: Vec<String>,
83    pub resources: DeploymentResources,
84    pub ports: Vec<DeploymentPorts>,
85    pub livenessProbe: DeploymentProbe,
86    pub readinessProbe: DeploymentProbe,
87    pub env: Option<Vec<DeploymentEnvSpecs>>
88}
89
90#[derive(Serialize, Deserialize, Default,Debug)]
91pub struct DeploymentResources {
92    pub requests: DeploymentResourcesRequests,
93    pub limits: DeploymentResourcesLimits,
94}
95
96#[derive(Serialize, Deserialize, Default,Debug)]
97pub struct DeploymentResourcesRequests {
98    pub memory: String,
99    pub cpu: f32
100}
101
102#[derive(Serialize, Deserialize, Default,Debug)]
103pub struct DeploymentResourcesLimits {
104    pub memory: String,
105    pub cpu: f32
106}
107
108#[derive(Serialize, Deserialize, Default,Debug)]
109pub struct DeploymentProbe {
110    pub failureThreshold: i32,
111    pub httpGet: HttpProbe,
112    pub initialDelaySeconds: i32,
113    pub periodSeconds: i32,
114    pub successThreshold: i8,
115    pub timeoutSeconds: i32
116}
117
118#[derive(Serialize, Deserialize, Default,Debug)]
119pub struct HttpProbe {
120    pub path: String,
121    pub port: i64,
122    pub scheme: String,
123}
124
125#[derive(Serialize, Deserialize, Default,Debug)]
126pub struct DeploymentPorts {
127    pub containerPort: i64,
128    pub protocol: String
129}
130
131// Update Deployment
132// Handle with care !
133
134#[derive(Serialize, Deserialize, Default,Debug)]
135pub struct UpdateDeployment {
136    pub apiVersion: String,
137    pub kind: String,
138    pub metadata: DeploymentMetadata,
139    pub spec: UpdateDeploymentSpec,
140}
141
142#[derive(Serialize, Deserialize, Default,Debug)]
143pub struct UpdateDeploymentSpec {
144    pub strategy: UpdateDeploymentSpecStrategy,
145    pub replicas: i32,
146    pub selector: UpdateDeploymentSelector,
147    pub template: UpdateDeploymentTemplate,
148}
149
150#[derive(Serialize, Deserialize, Default,Debug)]
151pub struct UpdateDeploymentSpecStrategy {
152    pub r#type: String,
153    pub rollingUpdate: RollingUpdate
154}
155
156#[derive(Serialize, Deserialize, Default,Debug)]
157pub struct UpdateDeploymentSelector {
158    pub matchLabels: UpdateSelectorLabels 
159}
160
161#[derive(Serialize, Deserialize, Default,Debug)]
162pub struct UpdateSelectorLabels {
163    pub app: String
164}
165
166#[derive(Serialize, Deserialize, Default,Debug)]
167pub struct UpdateDeploymentTemplate {
168    pub metadata: UpdateDeploymentTemplateMetadata,
169    pub spec: UpdateDeploymentTemplateSpec
170}
171
172#[derive(Serialize, Deserialize, Default,Debug)]
173pub struct UpdateDeploymentTemplateMetadata {
174    pub labels: UpdateDeploymentTemplateMetadataLabels
175}
176
177#[derive(Serialize, Deserialize, Default,Debug)]
178pub struct UpdateDeploymentTemplateMetadataLabels {
179    pub app: String
180}
181
182#[derive(Serialize, Deserialize, Default,Debug)]
183pub struct UpdateDeploymentTemplateSpec {
184    pub containers: Option<Vec<UpdateDeploymentContainers>>
185}
186
187#[derive(Serialize, Deserialize, Default,Debug)]
188pub struct UpdateDeploymentContainers {
189    pub name: String,
190    #[serde(skip_serializing_if = "Option::is_none")]
191    #[serde(default)]
192    pub image: Option<String>,
193    #[serde(skip_serializing_if = "Option::is_none")]
194    #[serde(default)]
195    pub imagePullPolicy: Option<String>,
196    #[serde(skip_serializing_if = "Option::is_none")]
197    #[serde(default)]
198    pub command: Option<Vec<String>>,
199    #[serde(skip_serializing_if = "Option::is_none")]
200    #[serde(default)]    
201    pub resources: Option<DeploymentResources>,
202    #[serde(skip_serializing_if = "Option::is_none")]
203    #[serde(default)]
204    pub ports: Option<Vec<DeploymentPorts>>,
205    #[serde(skip_serializing_if = "Option::is_none")]
206    #[serde(default)]
207    pub livenessProbe: Option<DeploymentProbe>,
208    #[serde(skip_serializing_if = "Option::is_none")]
209    #[serde(default)]
210    pub readinessProbe: Option<DeploymentProbe>,
211    #[serde(skip_serializing_if = "Option::is_none")]
212    #[serde(default)]
213    pub env: Option<Vec<DeploymentEnvSpecs>>
214}
215
216#[derive(Serialize, Deserialize, Debug)]
217#[serde(untagged)]
218pub enum DeploymentEnvSpecs {
219    PlainValue(DeploymentEnvs),
220    SecretValue(DeploymentEnvSecret)
221}
222
223#[derive(Serialize, Deserialize, Default,Debug)]
224pub struct DeploymentEnvs {
225    pub name: String,
226    pub value: String
227}
228
229#[derive(Serialize, Deserialize, Default,Debug)]
230pub struct DeploymentEnvSecret {
231    pub name: String,
232    pub valueFrom: SecretValueFrom
233}
234
235#[derive(Serialize, Deserialize, Default,Debug)]
236pub struct SecretValueFrom {
237    pub secretKeyRef: SecretyKeyRef
238}
239
240#[derive(Serialize, Deserialize, Default,Debug)]
241pub struct SecretyKeyRef {
242    pub name: String,
243    pub key: String
244}