Skip to content

Commit 006ee58

Browse files
committed
move validated struct to controller, add dereferenced fields to validated cluster struct
1 parent 979d647 commit 006ee58

4 files changed

Lines changed: 31 additions & 16 deletions

File tree

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

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@ use std::{
66
use product_config::{ProductConfigManager, types::PropertyNameKind};
77
use snafu::{ResultExt, Snafu};
88
use stackable_operator::{
9-
commons::product_image_selection::{self, ResolvedProductImage},
9+
commons::product_image_selection::{self},
1010
product_config_utils::{transform_all_roles_to_config, validate_all_roles_and_groups_config},
1111
role_utils::GenericRoleConfig,
1212
};
1313

1414
use crate::{
1515
crd::{AnyServiceConfig, HbaseRole, v1alpha1},
16-
hbase_controller::CONTAINER_IMAGE_BASE_NAME,
16+
hbase_controller::{CONTAINER_IMAGE_BASE_NAME, ValidatedCluster},
17+
security::opa::HbaseOpaConfig,
18+
zookeeper::ZookeeperConnectionInformation,
1719
};
1820

1921
#[derive(Snafu, Debug)]
@@ -59,21 +61,14 @@ pub struct ValidatedRoleGroupConfig {
5961
pub product_config_properties: HashMap<PropertyNameKind, BTreeMap<String, String>>,
6062
}
6163

62-
/// The validated cluster: proves that product-config validation and config merging
63-
/// succeeded for every role and role group before any resources are created.
64-
#[derive(Clone, Debug)]
65-
pub struct ValidatedHbaseCluster {
66-
pub image: ResolvedProductImage,
67-
pub role_groups: BTreeMap<HbaseRole, BTreeMap<String, ValidatedRoleGroupConfig>>,
68-
pub role_configs: BTreeMap<HbaseRole, ValidatedRoleConfig>,
69-
}
70-
7164
pub fn validate_cluster(
7265
hbase: &v1alpha1::HbaseCluster,
7366
image_repository: &str,
7467
pkg_version: &str,
7568
product_config_manager: &ProductConfigManager,
76-
) -> Result<ValidatedHbaseCluster, Error> {
69+
zookeeper_connection_information: ZookeeperConnectionInformation,
70+
hbase_opa_config: Option<HbaseOpaConfig>,
71+
) -> Result<ValidatedCluster, Error> {
7772
let resolved_product_image = hbase
7873
.spec
7974
.image
@@ -130,9 +125,11 @@ pub fn validate_cluster(
130125
role_groups.insert(hbase_role, group_configs);
131126
}
132127

133-
Ok(ValidatedHbaseCluster {
128+
Ok(ValidatedCluster {
134129
image: resolved_product_image,
135130
role_groups,
136131
role_configs,
132+
zookeeper_connection_information,
133+
hbase_opa_config,
137134
})
138135
}

rust/operator-binary/src/hbase_controller.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ use crate::{
7171
construct_global_jvm_args, construct_hbase_heapsize_env,
7272
construct_role_specific_non_heap_jvm_args,
7373
},
74+
controller::validate::{ValidatedRoleConfig, ValidatedRoleGroupConfig},
7475
crd::{
7576
APP_NAME, AnyServiceConfig, Container, HBASE_ENV_SH, HBASE_MASTER_PORT,
7677
HBASE_MASTER_UI_PORT, HBASE_REGIONSERVER_PORT, HBASE_REGIONSERVER_UI_PORT, HBASE_SITE_XML,
@@ -111,6 +112,19 @@ pub struct Ctx {
111112
pub operator_environment: OperatorEnvironmentOptions,
112113
}
113114

115+
/// The validated cluster: proves that product-config validation and config merging
116+
/// succeeded for every role and role group before any resources are created.
117+
/// Placed in the controller so that subsequent steps that reference this struct
118+
/// only depend on the controller.
119+
#[derive(Clone, Debug)]
120+
pub struct ValidatedCluster {
121+
pub image: ResolvedProductImage,
122+
pub role_groups: BTreeMap<HbaseRole, BTreeMap<String, ValidatedRoleGroupConfig>>,
123+
pub role_configs: BTreeMap<HbaseRole, ValidatedRoleConfig>,
124+
pub zookeeper_connection_information: ZookeeperConnectionInformation,
125+
pub hbase_opa_config: Option<HbaseOpaConfig>,
126+
}
127+
114128
#[derive(Snafu, Debug, EnumDiscriminants)]
115129
#[strum_discriminants(derive(IntoStaticStr))]
116130
pub enum Error {
@@ -307,6 +321,8 @@ pub async fn reconcile_hbase(
307321
&ctx.operator_environment.image_repository,
308322
crate::built_info::PKG_VERSION,
309323
&ctx.product_config,
324+
dereferenced.zookeeper_connection_information,
325+
dereferenced.hbase_opa_config,
310326
)
311327
.context(ValidateSnafu)?;
312328

@@ -354,10 +370,10 @@ pub async fn reconcile_hbase(
354370
&client.kubernetes_cluster_info,
355371
&rolegroup,
356372
&validated_rg_config.product_config_properties,
357-
&dereferenced.zookeeper_connection_information,
373+
&validated.zookeeper_connection_information,
358374
&validated_rg_config.merged_config,
359375
&validated.image,
360-
dereferenced.hbase_opa_config.as_ref(),
376+
validated.hbase_opa_config.as_ref(),
361377
)?;
362378
let rg_statefulset = build_rolegroup_statefulset(
363379
hbase,
@@ -418,7 +434,7 @@ pub async fn reconcile_hbase(
418434
let discovery_cm = build_discovery_configmap(
419435
hbase,
420436
&client.kubernetes_cluster_info,
421-
&dereferenced.zookeeper_connection_information,
437+
&validated.zookeeper_connection_information,
422438
&validated.image,
423439
)
424440
.context(BuildDiscoveryConfigMapSnafu)?;

rust/operator-binary/src/security/opa.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub enum Error {
1919

2020
type Result<T, E = Error> = std::result::Result<T, E>;
2121

22+
#[derive(Clone, Debug)]
2223
pub struct HbaseOpaConfig {
2324
authorization_connection_string: String,
2425
dry_run: bool,

rust/operator-binary/src/zookeeper.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ pub enum Error {
4343
type Result<T, E = Error> = std::result::Result<T, E>;
4444

4545
/// Contains the information as exposed by the Zookeeper/Znode discovery CM (should work with both)
46+
#[derive(Clone, Debug)]
4647
pub struct ZookeeperConnectionInformation {
4748
/// E.g. `simple-zk-server-default-0.simple-zk-server-default.default.svc.cluster.local:2282,simple-zk-server-default-1.simple-zk-server-default.default.svc.cluster.local:2282,simple-zk-server-default-2.simple-zk-server-default.default.svc.cluster.local:2282`
4849
hosts: String,

0 commit comments

Comments
 (0)