-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathservice.rs
More file actions
100 lines (96 loc) · 3.34 KB
/
Copy pathservice.rs
File metadata and controls
100 lines (96 loc) · 3.34 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
use stackable_operator::{
k8s_openapi::api::core::v1::{Service, ServicePort, ServiceSpec},
v2::{
builder::service::{Scheme, Scraping, prometheus_annotations, prometheus_labels},
types::operator::RoleGroupName,
},
};
use crate::{
controller::{build::security::service_ports, validate::ValidatedCluster},
crd::{DruidRole, METRICS_PORT, METRICS_PORT_NAME},
};
/// The rolegroup headless [`Service`] is a service that allows direct access to the instances of a certain rolegroup
/// This is mostly useful for internal communication between peers, or for clients that perform client-side load balancing.
pub fn build_rolegroup_headless_service(
cluster: &ValidatedCluster,
druid_role: &DruidRole,
role_group_name: &RoleGroupName,
) -> Service {
Service {
metadata: cluster
.object_meta(
cluster
.role_group_resource_names(druid_role, role_group_name)
.headless_service_name()
.to_string(),
druid_role,
role_group_name,
)
.build(),
spec: Some(ServiceSpec {
// Internal communication does not need to be exposed
type_: Some("ClusterIP".to_string()),
cluster_ip: Some("None".to_string()),
ports: Some(service_ports(
&cluster.cluster_config.druid_tls_security,
druid_role,
)),
selector: Some(
cluster
.role_group_selector(druid_role, role_group_name)
.into(),
),
publish_not_ready_addresses: Some(true),
..ServiceSpec::default()
}),
status: None,
}
}
/// The rolegroup metrics [`Service`] is a service that exposes metrics and a prometheus scraping label.
pub fn build_rolegroup_metrics_service(
cluster: &ValidatedCluster,
druid_role: &DruidRole,
role_group_name: &RoleGroupName,
) -> Service {
Service {
metadata: cluster
.object_meta(
cluster
.role_group_resource_names(druid_role, role_group_name)
.metrics_service_name()
.to_string(),
druid_role,
role_group_name,
)
.with_labels(prometheus_labels(&Scraping::Enabled))
.with_annotations(prometheus_annotations(
&Scraping::Enabled,
&Scheme::Http,
"/metrics",
&METRICS_PORT,
))
.build(),
spec: Some(ServiceSpec {
// Internal communication does not need to be exposed
type_: Some("ClusterIP".to_string()),
cluster_ip: Some("None".to_string()),
ports: Some(metrics_service_ports()),
selector: Some(
cluster
.role_group_selector(druid_role, role_group_name)
.into(),
),
publish_not_ready_addresses: Some(true),
..ServiceSpec::default()
}),
status: None,
}
}
fn metrics_service_ports() -> Vec<ServicePort> {
vec![ServicePort {
name: Some(METRICS_PORT_NAME.to_string()),
port: METRICS_PORT.into(),
protocol: Some("TCP".to_string()),
..ServicePort::default()
}]
}