-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathutil.rs
51 lines (47 loc) · 1.2 KB
/
util.rs
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
use crate::OPERATOR_NAME;
use stackable_operator::k8s_openapi::api::batch::v1::Job;
use stackable_operator::kvp::ObjectLabels;
use stackable_superset_crd::APP_NAME;
pub enum JobState {
InProgress,
Complete,
Failed,
}
pub fn get_job_state(job: &Job) -> JobState {
let conditions = job
.status
.as_ref()
.and_then(|status| status.conditions.clone())
.unwrap_or_default();
if conditions
.iter()
.any(|condition| condition.type_ == "Failed" && condition.status == "True")
{
JobState::Failed
} else if conditions
.iter()
.any(|condition| condition.type_ == "Complete" && condition.status == "True")
{
JobState::Complete
} else {
JobState::InProgress
}
}
/// Creates recommended `ObjectLabels` to be used in deployed resources
pub fn build_recommended_labels<'a, T>(
owner: &'a T,
controller_name: &'a str,
app_version: &'a str,
role: &'a str,
role_group: &'a str,
) -> ObjectLabels<'a, T> {
ObjectLabels {
owner,
app_name: APP_NAME,
app_version,
operator_name: OPERATOR_NAME,
controller_name,
role,
role_group,
}
}