Skip to content

Commit 4f982b5

Browse files
committed
fix: use rolegroup global and discovery placeholders
1 parent 2da9d6b commit 4f982b5

3 files changed

Lines changed: 20 additions & 21 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
//! Build steps that turn the [`ValidatedCluster`](super::ValidatedCluster) into
22
//! Kubernetes resource specifications.
33
4+
use std::str::FromStr;
5+
6+
use crate::controller::RoleGroupName;
7+
48
pub mod properties;
59
pub mod resource;
10+
11+
// Placeholder role-group name for the recommended labels of the role-level `Service`, which is not
12+
// bound to a single role group. `global` matches the historical `app.kubernetes.io/role-group`
13+
// value.
14+
stackable_operator::constant!(pub(crate) PLACEHOLDER_ROLE_LEVEL_ROLE_GROUP: RoleGroupName = "global");
15+
16+
// Placeholder role-group name for the recommended labels of the discovery `ConfigMap`, which is a
17+
// cluster-level object not bound to a single role group.
18+
stackable_operator::constant!(pub(crate) PLACEHOLDER_DISCOVERY_ROLE_GROUP: RoleGroupName = "discovery");

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

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
11
//! Builds the discovery [`ConfigMap`] clients use to connect to an `OpaCluster`.
2-
//!
3-
//! The content comes entirely from the [`ValidatedCluster`] (plus the externally-resolved role
4-
//! service and `cluster_info`).
5-
6-
use std::str::FromStr;
7-
82
use snafu::{ResultExt, Snafu};
93
use stackable_operator::{
104
builder::configmap::ConfigMapBuilder, k8s_openapi::api::core::v1::ConfigMap,
115
utils::cluster_info::KubernetesClusterInfo,
126
};
137

148
use super::service::{APP_PORT, APP_TLS_PORT};
15-
use crate::controller::{RoleGroupName, ValidatedCluster};
9+
use crate::controller::{ValidatedCluster, build::PLACEHOLDER_DISCOVERY_ROLE_GROUP};
1610

1711
#[derive(Snafu, Debug)]
1812
pub enum Error {
@@ -46,10 +40,7 @@ pub fn build_discovery_config_map(
4640
// Discovery is a cluster-level object (named after the cluster); `discovery` is used as a
4741
// placeholder role-group name for the recommended labels.
4842
let metadata = cluster
49-
.object_meta(
50-
cluster.name.to_string(),
51-
&RoleGroupName::from_str("discovery").expect("'discovery' is a valid role group name"),
52-
)
43+
.object_meta(cluster.name.to_string(), &PLACEHOLDER_DISCOVERY_ROLE_GROUP)
5344
.build();
5445

5546
let mut cm_builder = ConfigMapBuilder::new();

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

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,28 @@
1-
use std::{collections::BTreeMap, str::FromStr};
1+
use std::collections::BTreeMap;
22

33
use stackable_operator::{
44
k8s_openapi::api::core::v1::{Service, ServicePort, ServiceSpec},
55
kvp::{Annotations, Labels},
66
v2::types::common::Port,
77
};
88

9-
use crate::controller::{RoleGroupName, ValidatedCluster};
9+
use crate::controller::{
10+
RoleGroupName, ValidatedCluster, build::PLACEHOLDER_ROLE_LEVEL_ROLE_GROUP,
11+
};
1012

1113
pub const APP_PORT: Port = Port(8081);
1214
pub const APP_TLS_PORT: Port = Port(8443);
1315
pub const APP_PORT_NAME: &str = "http";
1416
pub const APP_TLS_PORT_NAME: &str = "https";
1517
pub const METRICS_PORT_NAME: &str = "metrics";
1618

17-
/// The role-level `Service` and the discovery `ConfigMap` are not bound to a single role group, but
18-
/// the recommended labels require one. `global` is used as a placeholder, matching the historical
19-
/// `app.kubernetes.io/role-group` value.
20-
fn role_level_role_group_name() -> RoleGroupName {
21-
RoleGroupName::from_str("global").expect("'global' is a valid role group name")
22-
}
23-
2419
/// The server-role service is the primary endpoint that should be used by clients that do not perform internal load balancing,
2520
/// including targets outside of the cluster.
2621
pub(crate) fn build_server_role_service(cluster: &ValidatedCluster) -> Service {
2722
let metadata = cluster
2823
.object_meta(
2924
cluster.server_role_service_name(),
30-
&role_level_role_group_name(),
25+
&PLACEHOLDER_ROLE_LEVEL_ROLE_GROUP,
3126
)
3227
.build();
3328

0 commit comments

Comments
 (0)