Skip to content

Commit 467c3d5

Browse files
committed
refactor: move k8s resources to resource folder, config etc to build
1 parent 6c503b9 commit 467c3d5

21 files changed

Lines changed: 777 additions & 736 deletions

File tree

rust/operator-binary/src/operations/graceful_shutdown.rs renamed to rust/operator-binary/src/controller/build/graceful_shutdown.rs

File renamed without changes.
File renamed without changes.
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
pub mod config_map;
2-
pub mod discovery;
1+
//! Builders that turn a [`ValidatedCluster`](crate::controller::ValidatedCluster) into
2+
//! Kubernetes resources.
3+
4+
pub mod graceful_shutdown;
35
pub mod jvm;
6+
pub mod kerberos;
7+
pub mod opa;
48
pub mod properties;
9+
pub mod resource;
File renamed without changes.

rust/operator-binary/src/controller/build/properties/hbase_site.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@ use std::collections::BTreeMap;
77
use stackable_operator::v2::config_overrides::KeyValueConfigOverrides;
88

99
use crate::{
10-
controller::build::properties::build_xml_config,
10+
controller::build::{opa::HbaseOpaConfig, properties::build_xml_config},
1111
crd::{
1212
AnyServiceConfig, HBASE_CLUSTER_DISTRIBUTED, HBASE_MASTER_PORT, HBASE_MASTER_UI_PORT,
1313
HBASE_REGIONSERVER_PORT, HBASE_REGIONSERVER_UI_PORT, HBASE_ROOTDIR, HbaseRole,
1414
},
15-
security::opa::HbaseOpaConfig,
1615
};
1716

1817
/// Renders `hbase-site.xml`.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ pub(crate) mod test_support {
6969
use crate::{
7070
controller::{
7171
ValidatedCluster, dereference::DereferencedObjects, validate::validate_cluster,
72+
zookeeper::ZookeeperConnectionInformation,
7273
},
7374
crd::{AnyServiceConfig, HbaseRole, v1alpha1},
74-
zookeeper::ZookeeperConnectionInformation,
7575
};
7676

7777
/// A minimal three-role HbaseCluster used to drive the per-file builder tests.

rust/operator-binary/src/controller/build/config_map.rs renamed to rust/operator-binary/src/controller/build/resource/config_map.rs

File renamed without changes.

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

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,20 @@ use snafu::{ResultExt, Snafu};
44
use stackable_operator::{
55
builder::{configmap::ConfigMapBuilder, meta::ObjectMetaBuilder},
66
k8s_openapi::api::core::v1::ConfigMap,
7+
kube::Resource,
8+
kvp::ObjectLabels,
79
v2::{builder::meta::ownerreference_from_resource, config_file_writer::to_hadoop_xml},
810
};
911

1012
use crate::{
1113
controller::{ValidatedCluster, build::properties::ConfigFileName},
12-
crd::HbaseRole,
13-
hbase_controller::build_recommended_labels,
14+
crd::{APP_NAME, HbaseRole, OPERATOR_NAME},
1415
};
1516

17+
// The discovery `ConfigMap` is a cluster-wide object (not tied to a single role group), so it is
18+
// labelled with the region-server role and a `discovery` placeholder role-group.
19+
const DISCOVERY_ROLE_GROUP: &str = "discovery";
20+
1621
type Result<T, E = Error> = std::result::Result<T, E>;
1722

1823
#[derive(Snafu, Debug)]
@@ -46,7 +51,7 @@ pub fn build_discovery_config_map(cluster: &ValidatedCluster) -> Result<ConfigMa
4651
cluster,
4752
&cluster.image.app_version_label_value,
4853
&HbaseRole::RegionServer.to_string(),
49-
"discovery",
54+
DISCOVERY_ROLE_GROUP,
5055
))
5156
.context(ObjectMetaSnafu)?
5257
.build(),
@@ -58,3 +63,24 @@ pub fn build_discovery_config_map(cluster: &ValidatedCluster) -> Result<ConfigMa
5863
.build()
5964
.context(BuildConfigMapSnafu)
6065
}
66+
67+
/// Recommended labels for the cluster-wide discovery `ConfigMap`.
68+
fn build_recommended_labels<'a, R>(
69+
owner: &'a R,
70+
app_version: &'a str,
71+
role: &'a str,
72+
role_group: &'a str,
73+
) -> ObjectLabels<'a, R>
74+
where
75+
R: Resource,
76+
{
77+
ObjectLabels {
78+
owner,
79+
app_name: APP_NAME,
80+
app_version,
81+
operator_name: OPERATOR_NAME,
82+
controller_name: crate::controller::HBASE_CONTROLLER_NAME,
83+
role,
84+
role_group,
85+
}
86+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//! Builders that turn a [`ValidatedCluster`](crate::controller::ValidatedCluster) into
2+
//! Kubernetes resources.
3+
4+
pub mod config_map;
5+
pub mod discovery;
6+
pub mod pdb;
7+
pub mod service;
8+
pub mod statefulset;
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//! Build the per-role `PodDisruptionBudget` for the HbaseCluster.
2+
3+
use stackable_operator::{
4+
commons::pdb::PdbConfig, k8s_openapi::api::policy::v1::PodDisruptionBudget,
5+
v2::builder::pdb::pod_disruption_budget_builder_with_role,
6+
};
7+
8+
use crate::{
9+
controller::{ValidatedCluster, controller_name, operator_name, product_name},
10+
crd::HbaseRole,
11+
};
12+
13+
/// Builds the [`PodDisruptionBudget`] for the given `role`, or `None` if PDBs are disabled.
14+
pub fn build_pdb(
15+
pdb: &PdbConfig,
16+
cluster: &ValidatedCluster,
17+
role: &HbaseRole,
18+
) -> Option<PodDisruptionBudget> {
19+
if !pdb.enabled {
20+
return None;
21+
}
22+
let max_unavailable = pdb.max_unavailable.unwrap_or(match role {
23+
HbaseRole::Master => max_unavailable_masters(),
24+
HbaseRole::RegionServer => max_unavailable_region_servers(),
25+
HbaseRole::RestServer => max_unavailable_rest_servers(),
26+
});
27+
let pdb = pod_disruption_budget_builder_with_role(
28+
cluster,
29+
&product_name(),
30+
&ValidatedCluster::role_name(role),
31+
&operator_name(),
32+
&controller_name(),
33+
)
34+
.with_max_unavailable(max_unavailable)
35+
.build();
36+
37+
Some(pdb)
38+
}
39+
40+
fn max_unavailable_masters() -> u16 {
41+
1
42+
}
43+
44+
fn max_unavailable_region_servers() -> u16 {
45+
1
46+
}
47+
48+
fn max_unavailable_rest_servers() -> u16 {
49+
// RestServers are stateless, we only need to make sure we have two available, so we don't have a single point of failure.
50+
// However, users probably deploy multiple rest servers for both - availability and performance. As there is the use-case
51+
// of having multiple RestServers for availability reasons, we need to be restrictive and stick to our `maxUnavailable: 1`
52+
// for `Multiple replicas to increase availability` rolegroups guideline.
53+
1
54+
}

0 commit comments

Comments
 (0)