Skip to content

Commit d1d7f0c

Browse files
committed
refactor: remove raw cluster references from k8s resources
1 parent 4097911 commit d1d7f0c

7 files changed

Lines changed: 54 additions & 75 deletions

File tree

rust/operator-binary/src/controller/build/kerberos.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ use stackable_operator::{
1616
utils::cluster_info::KubernetesClusterInfo,
1717
};
1818

19-
use crate::crd::{TLS_STORE_DIR, TLS_STORE_PASSWORD, TLS_STORE_VOLUME_NAME, v1alpha1};
19+
use crate::{
20+
controller::ValidatedCluster,
21+
crd::{TLS_STORE_DIR, TLS_STORE_PASSWORD, TLS_STORE_VOLUME_NAME, v1alpha1},
22+
};
2023

2124
/// Mount path of the Kerberos secret volume (keytab + `krb5.conf`).
2225
pub const STACKABLE_KERBEROS_DIR: &str = "/stackable/kerberos";
@@ -177,20 +180,20 @@ pub fn kerberos_ssl_client_settings(hbase: &v1alpha1::HbaseCluster) -> BTreeMap<
177180
}
178181

179182
pub fn add_kerberos_pod_config(
180-
hbase: &v1alpha1::HbaseCluster,
183+
cluster: &ValidatedCluster,
181184
metrics_service_name: &str,
182185
cb: &mut ContainerBuilder,
183186
pb: &mut PodBuilder,
184187
requested_secret_lifetime: Duration,
185188
) -> Result<(), Error> {
186-
if let Some(kerberos_secret_class) = hbase.kerberos_secret_class() {
189+
if let Some(kerberos_secret_class) = cluster.cluster_config.kerberos_secret_class.clone() {
187190
// Mount keytab
188191
let kerberos_secret_operator_volume = SecretOperatorVolumeSourceBuilder::new(
189192
kerberos_secret_class,
190193
// We need both public (krb5.conf) and private (keytab) parts.
191194
SecretClassVolumeProvisionParts::PublicPrivate,
192195
)
193-
.with_service_scope(hbase.name_any())
196+
.with_service_scope(cluster.name.to_string())
194197
.with_kerberos_service_name(kerberos_service_name())
195198
.with_kerberos_service_name("HTTP")
196199
.build()
@@ -208,7 +211,7 @@ pub fn add_kerberos_pod_config(
208211
cb.add_env_var("KRB5_CONFIG", KRB5_CONFIG_PATH);
209212
}
210213

211-
if let Some(https_secret_class) = hbase.https_secret_class() {
214+
if let Some(https_secret_class) = cluster.cluster_config.https_secret_class.clone() {
212215
// Mount TLS keystore
213216
pb.add_volume(
214217
VolumeBuilder::new(TLS_STORE_VOLUME_NAME)

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

Lines changed: 13 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use stackable_operator::{
77

88
use crate::{
99
controller::{RoleGroupName, ValidatedCluster},
10-
crd::{HbaseRole, v1alpha1},
10+
crd::HbaseRole,
1111
};
1212

1313
/// The rolegroup [`Service`] is a headless service that allows direct access to the instances of a
@@ -16,13 +16,12 @@ use crate::{
1616
/// This is mostly useful for internal communication between peers, or for clients that perform
1717
/// client-side load balancing.
1818
pub fn build_rolegroup_service(
19-
hbase: &v1alpha1::HbaseCluster,
2019
cluster: &ValidatedCluster,
2120
hbase_role: &HbaseRole,
2221
role_group_name: &RoleGroupName,
2322
) -> Service {
2423
let ports = hbase_role
25-
.ports(hbase)
24+
.ports(cluster.has_https_enabled())
2625
.into_iter()
2726
.map(|(name, value)| ServicePort {
2827
name: Some(name),
@@ -63,7 +62,6 @@ pub fn build_rolegroup_service(
6362
/// The rolegroup metrics [`Service`] is a service that exposes metrics and a prometheus scraping
6463
/// label.
6564
pub fn build_rolegroup_metrics_service(
66-
hbase: &v1alpha1::HbaseCluster,
6765
cluster: &ValidatedCluster,
6866
hbase_role: &HbaseRole,
6967
role_group_name: &RoleGroupName,
@@ -86,7 +84,10 @@ pub fn build_rolegroup_metrics_service(
8684
role_group_name,
8785
)
8886
.with_labels(prometheus_labels())
89-
.with_annotations(prometheus_annotations(hbase, hbase_role))
87+
.with_annotations(prometheus_annotations(
88+
cluster.has_https_enabled(),
89+
hbase_role,
90+
))
9091
.build(),
9192
spec: Some(ServiceSpec {
9293
// Internal communication does not need to be exposed
@@ -115,7 +116,7 @@ fn prometheus_labels() -> Labels {
115116
/// These annotations can be used in a ServiceMonitor.
116117
///
117118
/// see also <https://github.com/prometheus-community/helm-charts/blob/prometheus-27.32.0/charts/prometheus/values.yaml#L983-L1036>
118-
fn prometheus_annotations(hbase: &v1alpha1::HbaseCluster, hbase_role: &HbaseRole) -> Annotations {
119+
fn prometheus_annotations(https_enabled: bool, hbase_role: &HbaseRole) -> Annotations {
119120
Annotations::try_from([
120121
("prometheus.io/path".to_owned(), "/prometheus".to_owned()),
121122
(
@@ -124,7 +125,7 @@ fn prometheus_annotations(hbase: &v1alpha1::HbaseCluster, hbase_role: &HbaseRole
124125
),
125126
(
126127
"prometheus.io/scheme".to_owned(),
127-
if hbase.has_https_enabled() {
128+
if https_enabled {
128129
"https".to_owned()
129130
} else {
130131
"http".to_owned()
@@ -143,50 +144,13 @@ mod test {
143144
use crate::test_utils;
144145

145146
#[rstest]
146-
#[case("2.6.3", HbaseRole::Master, vec!["master", "ui-http"])]
147-
#[case("2.6.3", HbaseRole::RegionServer, vec!["regionserver", "ui-http"])]
148-
#[case("2.6.3", HbaseRole::RestServer, vec!["rest-http", "ui-http"])]
149-
#[case("2.6.4", HbaseRole::Master, vec!["master", "ui-http"])]
150-
#[case("2.6.4", HbaseRole::RegionServer, vec!["regionserver", "ui-http"])]
151-
#[case("2.6.4", HbaseRole::RestServer, vec!["rest-http", "ui-http"])]
152-
fn test_rolegroup_service_ports(
153-
#[case] hbase_version: &str,
154-
#[case] role: HbaseRole,
155-
#[case] expected_ports: Vec<&str>,
156-
) {
157-
let input = format!(
158-
"
159-
apiVersion: hbase.stackable.tech/v1alpha1
160-
kind: HbaseCluster
161-
metadata:
162-
name: hbase
163-
uid: c2e98fc1-6b88-4d11-9381-52530e3f431e
164-
spec:
165-
image:
166-
productVersion: {hbase_version}
167-
clusterConfig:
168-
hdfsConfigMapName: simple-hdfs
169-
zookeeperConfigMapName: simple-znode
170-
masters:
171-
roleGroups:
172-
default:
173-
replicas: 1
174-
regionServers:
175-
roleGroups:
176-
default:
177-
replicas: 1
178-
restServers:
179-
roleGroups:
180-
default:
181-
replicas: 1
182-
"
183-
);
184-
let hbase: v1alpha1::HbaseCluster =
185-
serde_yaml::from_str(&input).expect("illegal test input");
186-
147+
#[case(HbaseRole::Master, vec!["master", "ui-http"])]
148+
#[case(HbaseRole::RegionServer, vec!["regionserver", "ui-http"])]
149+
#[case(HbaseRole::RestServer, vec!["rest-http", "ui-http"])]
150+
fn test_rolegroup_service_ports(#[case] role: HbaseRole, #[case] expected_ports: Vec<&str>) {
187151
let cluster = test_utils::validated_cluster();
188152
let role_group_name = test_utils::role_group_name("default");
189-
let service = build_rolegroup_service(&hbase, &cluster, &role, &role_group_name);
153+
let service = build_rolegroup_service(&cluster, &role, &role_group_name);
190154

191155
assert_eq!(
192156
expected_ports,

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ use crate::{
4343
properties::logging::{MAX_HBASE_LOG_FILES_SIZE, STACKABLE_LOG_DIR},
4444
},
4545
},
46-
crd::{CONFIG_DIR_NAME, HbaseRole, LISTENER_VOLUME_DIR, LISTENER_VOLUME_NAME, v1alpha1},
46+
crd::{CONFIG_DIR_NAME, HbaseRole, LISTENER_VOLUME_DIR, LISTENER_VOLUME_NAME},
4747
};
4848

4949
stackable_operator::constant!(VECTOR_CONTAINER_NAME: ContainerName = "vector");
@@ -98,7 +98,6 @@ type Result<T, E = Error> = std::result::Result<T, E>;
9898
/// The [`Pod`](stackable_operator::k8s_openapi::api::core::v1::Pod)s are accessible through the
9999
/// corresponding headless [`Service`](stackable_operator::k8s_openapi::api::core::v1::Service).
100100
pub fn build_rolegroup_statefulset(
101-
hbase: &v1alpha1::HbaseCluster,
102101
cluster: &ValidatedCluster,
103102
hbase_role: &HbaseRole,
104103
role_group_name: &RoleGroupName,
@@ -109,9 +108,10 @@ pub fn build_rolegroup_statefulset(
109108
let merged_config = &validated_rg_config.config.config;
110109
let logging = &validated_rg_config.config.logging;
111110
let resource_names = cluster.resource_names(hbase_role, role_group_name);
111+
let https_enabled = cluster.has_https_enabled();
112112

113113
let ports = hbase_role
114-
.ports(hbase)
114+
.ports(https_enabled)
115115
.into_iter()
116116
.map(|(name, value)| ContainerPort {
117117
name: Some(name),
@@ -123,7 +123,7 @@ pub fn build_rolegroup_statefulset(
123123

124124
let probe_template = Probe {
125125
tcp_socket: Some(TCPSocketAction {
126-
port: IntOrString::String(hbase_role.data_port_name(hbase)),
126+
port: IntOrString::String(hbase_role.data_port_name(https_enabled)),
127127
..TCPSocketAction::default()
128128
}),
129129
..Probe::default()
@@ -185,8 +185,8 @@ pub fn build_rolegroup_statefulset(
185185
entrypoint = "/stackable/hbase/bin/hbase-entrypoint.sh".to_string(),
186186
role = role_name,
187187
port = hbase_role.data_port(),
188-
port_name = hbase_role.data_port_name(hbase),
189-
ui_port_name = HbaseRole::ui_port_name(hbase.has_https_enabled()),
188+
port_name = hbase_role.data_port_name(https_enabled),
189+
ui_port_name = HbaseRole::ui_port_name(https_enabled),
190190
}])
191191
.add_env_vars(merged_env)
192192
// Needed for the `containerdebug` process to log it's tracing information to.
@@ -234,7 +234,7 @@ pub fn build_rolegroup_statefulset(
234234
.add_volume(Volume {
235235
name: HDFS_DISCOVERY_VOLUME_NAME.to_string(),
236236
config_map: Some(ConfigMapVolumeSource {
237-
name: hbase.spec.cluster_config.hdfs_config_map_name.clone(),
237+
name: cluster.cluster_config.hdfs_config_map_name.clone(),
238238
..Default::default()
239239
}),
240240
..Default::default()
@@ -273,7 +273,7 @@ pub fn build_rolegroup_statefulset(
273273
add_graceful_shutdown_config(merged_config, &mut pod_builder).context(GracefulShutdownSnafu)?;
274274
if cluster.has_kerberos_enabled() {
275275
add_kerberos_pod_config(
276-
hbase,
276+
cluster,
277277
resource_names.metrics_service_name().as_ref(),
278278
&mut hbase_container,
279279
&mut pod_builder,

rust/operator-binary/src/controller/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,11 @@ impl ValidatedCluster {
185185
pub fn has_kerberos_enabled(&self) -> bool {
186186
self.cluster_config.kerberos_enabled
187187
}
188+
189+
/// Whether HTTPS is enabled for this cluster.
190+
pub fn has_https_enabled(&self) -> bool {
191+
self.cluster_config.https_enabled
192+
}
188193
}
189194

190195
impl Resource for ValidatedCluster {
@@ -240,6 +245,14 @@ pub struct ValidatedClusterConfig {
240245
// Pre-resolved OPA connection configuration.
241246
pub hbase_opa_config: Option<HbaseOpaConfig>,
242247
pub kerberos_enabled: bool,
248+
/// Whether HTTPS is enabled (a TLS `SecretClass` was configured).
249+
pub https_enabled: bool,
250+
/// The Kerberos `SecretClass` name, if Kerberos is enabled.
251+
pub kerberos_secret_class: Option<String>,
252+
/// The HTTPS/TLS `SecretClass` name, if HTTPS is enabled.
253+
pub https_secret_class: Option<String>,
254+
/// The HDFS discovery ConfigMap name the cluster connects to.
255+
pub hdfs_config_map_name: String,
243256
// Pre-resolved kerberos properties for hbase-site.xml (empty when kerberos is disabled).
244257
pub hbase_site_kerberos_config: BTreeMap<String, String>,
245258
// Pre-resolved kerberos properties for the discovery `hbase-site.xml` exposed to clients

rust/operator-binary/src/controller/validate.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,10 @@ pub fn validate_cluster(
243243
zookeeper_connection_information: dereferenced_objects.zookeeper_connection_information,
244244
hbase_opa_config: dereferenced_objects.hbase_opa_config,
245245
kerberos_enabled: hbase.has_kerberos_enabled(),
246+
https_enabled: hbase.has_https_enabled(),
247+
kerberos_secret_class: hbase.kerberos_secret_class(),
248+
https_secret_class: hbase.https_secret_class(),
249+
hdfs_config_map_name: hbase.spec.cluster_config.hdfs_config_map_name.clone(),
246250
hbase_site_kerberos_config,
247251
discovery_kerberos_config,
248252
ssl_server_settings,

rust/operator-binary/src/crd/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -361,11 +361,11 @@ impl HbaseRole {
361361
///
362362
/// Hbase versions 2.6.* will have two ports for each role. The metrics are available on the
363363
/// UI port.
364-
pub fn ports(&self, hbase: &v1alpha1::HbaseCluster) -> Vec<(String, u16)> {
364+
pub fn ports(&self, https_enabled: bool) -> Vec<(String, u16)> {
365365
vec![
366-
(self.data_port_name(hbase), self.data_port()),
366+
(self.data_port_name(https_enabled), self.data_port()),
367367
(
368-
Self::ui_port_name(hbase.has_https_enabled()).to_string(),
368+
Self::ui_port_name(https_enabled).to_string(),
369369
self.ui_port(),
370370
),
371371
]
@@ -379,11 +379,11 @@ impl HbaseRole {
379379
}
380380
}
381381

382-
pub fn data_port_name(&self, hbase: &v1alpha1::HbaseCluster) -> String {
382+
pub fn data_port_name(&self, https_enabled: bool) -> String {
383383
match self {
384384
HbaseRole::Master | HbaseRole::RegionServer => self.to_string(),
385385
HbaseRole::RestServer => {
386-
if hbase.has_https_enabled() {
386+
if https_enabled {
387387
HBASE_REST_PORT_NAME_HTTPS.to_owned()
388388
} else {
389389
HBASE_REST_PORT_NAME_HTTP.to_owned()

rust/operator-binary/src/hbase_controller.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -205,20 +205,15 @@ pub async fn reconcile_hbase(
205205
for (hbase_role, role_group_configs) in &validated_cluster.role_group_configs {
206206
for (role_group_name, validated_rg_config) in role_group_configs {
207207
let rg_service =
208-
build_rolegroup_service(hbase, &validated_cluster, hbase_role, role_group_name);
208+
build_rolegroup_service(&validated_cluster, hbase_role, role_group_name);
209209

210-
let rg_metrics_service = build_rolegroup_metrics_service(
211-
hbase,
212-
&validated_cluster,
213-
hbase_role,
214-
role_group_name,
215-
);
210+
let rg_metrics_service =
211+
build_rolegroup_metrics_service(&validated_cluster, hbase_role, role_group_name);
216212

217213
let rg_configmap =
218214
build_rolegroup_config_map(&validated_cluster, hbase_role, role_group_name)
219215
.context(BuildRolegroupConfigMapSnafu)?;
220216
let rg_statefulset = build_rolegroup_statefulset(
221-
hbase,
222217
&validated_cluster,
223218
hbase_role,
224219
role_group_name,

0 commit comments

Comments
 (0)