-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaffinity.rs
More file actions
99 lines (92 loc) · 3.6 KB
/
affinity.rs
File metadata and controls
99 lines (92 loc) · 3.6 KB
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
use stackable_operator::{
commons::affinity::{StackableAffinityFragment, affinity_between_role_pods},
k8s_openapi::api::core::v1::PodAntiAffinity,
};
use crate::crd::{APP_NAME, HiveRole};
pub fn get_affinity(cluster_name: &str, role: &HiveRole) -> StackableAffinityFragment {
StackableAffinityFragment {
pod_affinity: None,
pod_anti_affinity: Some(PodAntiAffinity {
preferred_during_scheduling_ignored_during_execution: Some(vec![
affinity_between_role_pods(APP_NAME, cluster_name, &role.to_string(), 70),
]),
required_during_scheduling_ignored_during_execution: None,
}),
node_affinity: None,
node_selector: None,
}
}
#[cfg(test)]
mod tests {
use std::collections::BTreeMap;
use rstest::rstest;
use stackable_operator::{
commons::affinity::StackableAffinity,
k8s_openapi::{
api::core::v1::{PodAffinityTerm, PodAntiAffinity, WeightedPodAffinityTerm},
apimachinery::pkg::apis::meta::v1::LabelSelector,
},
};
use super::*;
use crate::crd::v1alpha1;
#[rstest]
#[case(HiveRole::MetaStore)]
fn test_affinity_defaults(#[case] role: HiveRole) {
let input = r#"
apiVersion: hive.stackable.tech/v1alpha1
kind: HiveCluster
metadata:
name: simple-hive
spec:
image:
productVersion: 4.2.0
clusterConfig:
database:
connString: jdbc:derby:;databaseName=/tmp/hive;create=true
dbType: derby
credentialsSecret: mySecret
metastore:
roleGroups:
default:
replicas: 1
"#;
let hive: v1alpha1::HiveCluster = serde_yaml::from_str(input).expect("illegal test input");
let merged_config = hive
.merged_config(&role, &role.rolegroup_ref(&hive, "default"))
.unwrap();
assert_eq!(
merged_config.affinity,
StackableAffinity {
pod_affinity: None,
pod_anti_affinity: Some(PodAntiAffinity {
preferred_during_scheduling_ignored_during_execution: Some(vec![
WeightedPodAffinityTerm {
pod_affinity_term: PodAffinityTerm {
label_selector: Some(LabelSelector {
match_labels: Some(BTreeMap::from([
("app.kubernetes.io/name".to_string(), "hive".to_string(),),
(
"app.kubernetes.io/instance".to_string(),
"simple-hive".to_string(),
),
(
"app.kubernetes.io/component".to_string(),
"metastore".to_string(),
)
])),
..LabelSelector::default()
}),
topology_key: "kubernetes.io/hostname".to_string(),
..PodAffinityTerm::default()
},
weight: 70
}
]),
required_during_scheduling_ignored_during_execution: None,
}),
node_affinity: None,
node_selector: None,
}
);
}
}