Skip to content

Commit 73544b4

Browse files
committed
fix: use v2 daemonset name & prometheus annotations and label helper
1 parent 1ccdabf commit 73544b4

3 files changed

Lines changed: 19 additions & 35 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ All notable changes to this project will be documented in this file.
1212

1313
### Changed
1414

15-
- Bump `stackable-operator` to 0.111.0 and `snafu` to 0.9 ([#818], [#830]).
15+
- Bump `stackable-operator` to 0.112.0 and `snafu` to 0.9 ([#818], [#830], [#842]).
1616
- Set `maxSurge=1` and `maxUnavailable=0` on the OPA DaemonSet rolling update strategy to eliminate
1717
availability gaps during rolling updates ([#819]).
1818
- Document Helm deployed RBAC permissions and remove unnecessary permissions ([#820]).

rust/operator-binary/src/controller/build/resource/daemonset.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -581,14 +581,11 @@ pub fn build_server_rolegroup_daemonset(
581581
let mut pod_template = pb.build_template();
582582
pod_template.merge_from(rolegroup_config.pod_overrides.clone());
583583

584-
// TODO(@maltesander): `ResourceNames` has no `DaemonSet` helper (OPA is the only DaemonSet operator), so the
585-
// (identical) qualified role-group name backing the `StatefulSet` name is reused.
586-
// Should be replaced with upstream fix.
587584
let metadata = cluster
588585
.object_meta(
589586
cluster
590587
.resource_names(role_group_name)
591-
.stateful_set_name()
588+
.daemon_set_name()
592589
.to_string(),
593590
role_group_name,
594591
)

rust/operator-binary/src/controller/build/resource/service.rs

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ use std::collections::BTreeMap;
22

33
use stackable_operator::{
44
k8s_openapi::api::core::v1::{Service, ServicePort, ServiceSpec},
5-
kvp::{Annotations, Labels},
6-
v2::types::common::Port,
5+
v2::{
6+
builder::service::{Scheme, Scraping, prometheus_annotations, prometheus_labels},
7+
types::common::Port,
8+
},
79
};
810

911
use crate::controller::{
@@ -107,6 +109,11 @@ pub(crate) fn build_rolegroup_metrics_service(
107109
role_group_name: &RoleGroupName,
108110
) -> Service {
109111
let tls_enabled = cluster.is_tls_enabled();
112+
let (scheme, port) = if tls_enabled {
113+
(Scheme::Https, APP_TLS_PORT)
114+
} else {
115+
(Scheme::Http, APP_PORT)
116+
};
110117
let metadata = cluster
111118
.object_meta(
112119
cluster
@@ -115,8 +122,14 @@ pub(crate) fn build_rolegroup_metrics_service(
115122
.to_string(),
116123
role_group_name,
117124
)
118-
.with_labels(prometheus_labels())
119-
.with_annotations(prometheus_annotations(tls_enabled))
125+
.with_labels(prometheus_labels(&Scraping::Enabled))
126+
// The metrics are served on the same port as the HTTP/HTTPS traffic, under `/metrics`.
127+
.with_annotations(prometheus_annotations(
128+
&Scraping::Enabled,
129+
&scheme,
130+
"/metrics",
131+
&port,
132+
))
120133
.build();
121134

122135
let service_spec = headless_cluster_ip_service_spec(
@@ -159,32 +172,6 @@ fn metrics_service_port(tls_enabled: bool) -> ServicePort {
159172
}
160173
}
161174

162-
/// Common labels for Prometheus
163-
fn prometheus_labels() -> Labels {
164-
Labels::try_from([("prometheus.io/scrape", "true")]).expect("should be a valid label")
165-
}
166-
167-
/// Common annotations for Prometheus
168-
///
169-
/// These annotations can be used in a ServiceMonitor.
170-
///
171-
/// see also <https://github.com/prometheus-community/helm-charts/blob/prometheus-27.32.0/charts/prometheus/values.yaml#L983-L1036>
172-
fn prometheus_annotations(tls_enabled: bool) -> Annotations {
173-
let (port, scheme) = if tls_enabled {
174-
(APP_TLS_PORT, "https")
175-
} else {
176-
(APP_PORT, "http")
177-
};
178-
179-
Annotations::try_from([
180-
("prometheus.io/path".to_owned(), "/metrics".to_owned()),
181-
("prometheus.io/port".to_owned(), port.to_string()),
182-
("prometheus.io/scheme".to_owned(), scheme.to_owned()),
183-
("prometheus.io/scrape".to_owned(), "true".to_owned()),
184-
])
185-
.expect("should be valid annotations")
186-
}
187-
188175
#[cfg(test)]
189176
mod tests {
190177
use serde_json::json;

0 commit comments

Comments
 (0)