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
use super::Result;
#[derive(Serialize, Deserialize, Clone, Default, Debug)]
#[cfg_attr(feature = "filesystem", serde(deny_unknown_fields))]
pub struct HttpGet {
pub path: String,
#[serde(default = "http_get_default_port")]
pub port: String,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub httpHeaders: Vec<HttpHeader>,
}
fn http_get_default_port() -> String {
"http".into()
}
#[derive(Serialize, Deserialize, Clone, Default, Debug)]
#[cfg_attr(feature = "filesystem", serde(deny_unknown_fields))]
pub struct HttpHeader {
pub name: String,
pub value: String,
}
#[derive(Serialize, Deserialize, Clone, Default, Debug)]
#[cfg_attr(feature = "filesystem", serde(deny_unknown_fields))]
pub struct Exec {
pub command: Vec<String>,
}
#[derive(Serialize, Deserialize, Clone, Default, Debug)]
#[cfg_attr(feature = "filesystem", serde(deny_unknown_fields))]
pub struct TcpSocket {
pub port: String,
}
#[derive(Serialize, Deserialize, Clone, Default, Debug)]
#[cfg_attr(feature = "filesystem", serde(deny_unknown_fields))]
pub struct Probe {
#[serde(default, skip_serializing_if = "Option::is_none")]
httpGet: Option<HttpGet>,
#[serde(default, skip_serializing_if = "Option::is_none")]
exec: Option<Exec>,
#[serde(default, skip_serializing_if = "Option::is_none")]
tcpSocket: Option<TcpSocket>,
#[serde(default = "initial_delay_seconds_default")]
pub initialDelaySeconds: u32,
#[serde(default = "period_seconds_default")]
pub periodSeconds: u32,
#[serde(default = "success_threshold_default")]
pub successThreshold: u32,
#[serde(default = "failure_threshold_default")]
pub failureThreshold: u32,
#[serde(default = "timeout_seconds_default")]
pub timeoutSeconds: u32,
}
fn initial_delay_seconds_default() -> u32 {
30
}
fn period_seconds_default() -> u32 {
5
}
fn success_threshold_default() -> u32 {
1
}
fn failure_threshold_default() -> u32 {
3
}
fn timeout_seconds_default() -> u32 {
1
}
impl Probe {
pub fn verify(&self) -> Result<()> {
if self.httpGet.is_some() && (self.exec.is_some() || self.tcpSocket.is_some()) {
bail!("Probe needs to have at most one of 'httpGet' or 'exec'");
}
if self.httpGet.is_none() && self.exec.is_none() && self.tcpSocket.is_none() {
bail!("Probe needs to define one of 'httpGet', 'exec', 'tcpSocket");
}
Ok(())
}
}