-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathaffinity.rs
More file actions
109 lines (102 loc) · 4.12 KB
/
Copy pathaffinity.rs
File metadata and controls
109 lines (102 loc) · 4.12 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
100
101
102
103
104
105
106
107
108
109
use stackable_operator::{
commons::affinity::{StackableAffinityFragment, affinity_between_role_pods},
k8s_openapi::api::core::v1::PodAntiAffinity,
};
use crate::crd::{APP_NAME, SupersetRole};
pub fn get_affinity(cluster_name: &str, role: &SupersetRole) -> 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 stackable_operator::{
commons::affinity::StackableAffinity,
config::fragment,
k8s_openapi::{
api::core::v1::{PodAffinityTerm, PodAntiAffinity, WeightedPodAffinityTerm},
apimachinery::pkg::apis::meta::v1::LabelSelector,
},
kube::ResourceExt,
utils::yaml_from_str_singleton_map,
};
use super::*;
use crate::crd::v1alpha1;
#[test]
fn test_affinity_defaults() {
let input = r#"
apiVersion: superset.stackable.tech/v1alpha1
kind: SupersetCluster
metadata:
name: simple-superset
spec:
image:
productVersion: 6.1.0
clusterConfig:
credentialsSecret: superset-admin-credentials
metadataDatabase:
postgresql:
host: superset-postgresql
database: superset
credentialsSecretName: superset-postgresql-credentials
nodes:
roleGroups:
default:
replicas: 1
"#;
let superset: v1alpha1::SupersetCluster =
yaml_from_str_singleton_map(input).expect("illegal test input");
// The role group carries no resource/affinity overrides, so the merged config is just the
// validated default config.
let merged_config: v1alpha1::SupersetConfig = fragment::validate(
v1alpha1::SupersetConfig::default_config(&superset.name_any(), &SupersetRole::Node),
)
.expect("default config should validate");
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_expressions: None,
match_labels: Some(BTreeMap::from([
(
"app.kubernetes.io/name".to_string(),
"superset".to_string(),
),
(
"app.kubernetes.io/instance".to_string(),
"simple-superset".to_string(),
),
(
"app.kubernetes.io/component".to_string(),
"node".to_string(),
)
]))
}),
topology_key: "kubernetes.io/hostname".to_string(),
..PodAffinityTerm::default()
},
weight: 70
}
]),
required_during_scheduling_ignored_during_execution: None,
}),
node_affinity: None,
node_selector: None,
}
);
}
}