Skip to content

Commit ad56b85

Browse files
adwk67claude
andcommitted
refactor: move product image resolution from dereference to validate
Image resolution is a pure computation, not an I/O dereference, so it belongs in validate_cluster alongside the other config validation. This aligns with the pattern used by the trino and airflow operators. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent d1b35fc commit ad56b85

3 files changed

Lines changed: 24 additions & 30 deletions

File tree

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

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
use snafu::{ResultExt, Snafu};
2-
use stackable_operator::commons::product_image_selection::{self, ResolvedProductImage};
32

43
use crate::{
54
crd::v1alpha1, security::opa::HbaseOpaConfig, zookeeper::ZookeeperConnectionInformation,
65
};
76

87
#[derive(Snafu, Debug)]
98
pub enum Error {
10-
#[snafu(display("failed to resolve product image"))]
11-
ResolveProductImage {
12-
source: product_image_selection::Error,
13-
},
14-
159
#[snafu(display("failed to retrieve zookeeper connection information"))]
1610
RetrieveZookeeperConnectionInformation { source: crate::zookeeper::Error },
1711

@@ -21,24 +15,14 @@ pub enum Error {
2115

2216
/// External references resolved during the dereference step.
2317
pub struct DereferencedObjects {
24-
pub resolved_product_image: ResolvedProductImage,
2518
pub zookeeper_connection_information: ZookeeperConnectionInformation,
2619
pub hbase_opa_config: Option<HbaseOpaConfig>,
2720
}
2821

2922
pub async fn dereference(
3023
client: &stackable_operator::client::Client,
3124
hbase: &v1alpha1::HbaseCluster,
32-
image_base_name: &str,
33-
image_repository: &str,
34-
pkg_version: &str,
3525
) -> Result<DereferencedObjects, Error> {
36-
let resolved_product_image = hbase
37-
.spec
38-
.image
39-
.resolve(image_base_name, image_repository, pkg_version)
40-
.context(ResolveProductImageSnafu)?;
41-
4226
let zookeeper_connection_information = ZookeeperConnectionInformation::retrieve(hbase, client)
4327
.await
4428
.context(RetrieveZookeeperConnectionInformationSnafu)?;
@@ -53,7 +37,6 @@ pub async fn dereference(
5337
};
5438

5539
Ok(DereferencedObjects {
56-
resolved_product_image,
5740
zookeeper_connection_information,
5841
hbase_opa_config,
5942
})

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

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

14-
use super::dereference::DereferencedObjects;
1514
use crate::crd::{AnyServiceConfig, HbaseRole, v1alpha1};
1615

1716
#[derive(Snafu, Debug)]
1817
pub enum Error {
18+
#[snafu(display("failed to resolve product image"))]
19+
ResolveProductImage {
20+
source: product_image_selection::Error,
21+
},
22+
1923
#[snafu(display("invalid role properties"))]
2024
RoleProperties { source: crate::crd::Error },
2125

@@ -63,13 +67,21 @@ pub struct ValidatedHbaseCluster {
6367

6468
pub fn validate_cluster(
6569
hbase: &v1alpha1::HbaseCluster,
66-
dereferenced: &DereferencedObjects,
70+
image_base_name: &str,
71+
image_repository: &str,
72+
pkg_version: &str,
6773
product_config_manager: &ProductConfigManager,
6874
) -> Result<ValidatedHbaseCluster, Error> {
75+
let resolved_product_image = hbase
76+
.spec
77+
.image
78+
.resolve(image_base_name, image_repository, pkg_version)
79+
.context(ResolveProductImageSnafu)?;
80+
6981
let roles = hbase.build_role_properties().context(RolePropertiesSnafu)?;
7082

7183
let validated_config = validate_all_roles_and_groups_config(
72-
&dereferenced.resolved_product_image.product_version,
84+
&resolved_product_image.product_version,
7385
&transform_all_roles_to_config(hbase, &roles).context(GenerateProductConfigSnafu)?,
7486
product_config_manager,
7587
false,
@@ -117,7 +129,7 @@ pub fn validate_cluster(
117129
}
118130

119131
Ok(ValidatedHbaseCluster {
120-
image: dereferenced.resolved_product_image.clone(),
132+
image: resolved_product_image,
121133
role_groups,
122134
role_configs,
123135
})

rust/operator-binary/src/hbase_controller.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -298,19 +298,18 @@ pub async fn reconcile_hbase(
298298

299299
let client = &ctx.client;
300300

301-
let dereferenced = crate::controller::dereference::dereference(
302-
client,
301+
let dereferenced = crate::controller::dereference::dereference(client, hbase)
302+
.await
303+
.context(DereferenceSnafu)?;
304+
305+
let validated = crate::controller::validate::validate_cluster(
303306
hbase,
304307
CONTAINER_IMAGE_BASE_NAME,
305308
&ctx.operator_environment.image_repository,
306309
crate::built_info::PKG_VERSION,
310+
&ctx.product_config,
307311
)
308-
.await
309-
.context(DereferenceSnafu)?;
310-
311-
let validated =
312-
crate::controller::validate::validate_cluster(hbase, &dereferenced, &ctx.product_config)
313-
.context(ValidateSnafu)?;
312+
.context(ValidateSnafu)?;
314313

315314
let mut cluster_resources = ClusterResources::new(
316315
APP_NAME,

0 commit comments

Comments
 (0)