Skip to content

Commit 218b2e0

Browse files
committed
refactor: add clusteroperation & object overrides to ValidatedCluster / ValidatedZnode
1 parent a0281a2 commit 218b2e0

4 files changed

Lines changed: 40 additions & 17 deletions

File tree

rust/operator-binary/src/zk_controller.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,8 @@ pub async fn reconcile_zk(
238238
&validated_cluster.name,
239239
&validated_cluster.namespace,
240240
&validated_cluster.uid,
241-
ClusterResourceApplyStrategy::from(&zk.spec.cluster_operation),
242-
&zk.spec.object_overrides,
241+
ClusterResourceApplyStrategy::from(&validated_cluster.cluster_operation),
242+
&validated_cluster.object_overrides,
243243
);
244244

245245
let (rbac_sa, rbac_rolebinding) = build_rbac_resources(

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@ use std::{collections::BTreeMap, str::FromStr};
1212
use snafu::{OptionExt, ResultExt, Snafu};
1313
use stackable_operator::{
1414
cli::OperatorEnvironmentOptions,
15-
commons::product_image_selection::{self, ResolvedProductImage},
15+
commons::{
16+
cluster_operation::ClusterOperation,
17+
product_image_selection::{self, ResolvedProductImage},
18+
},
1619
config::fragment,
20+
deep_merger::ObjectOverrides,
1721
k8s_openapi::{api::core::v1::PodTemplateSpec, apimachinery::pkg::apis::meta::v1::ObjectMeta},
1822
kube::{Resource, ResourceExt},
1923
kvp::Labels,
@@ -213,6 +217,13 @@ pub struct ValidatedCluster {
213217
pub cluster_config: ValidatedClusterConfig,
214218
pub role_group_configs:
215219
BTreeMap<ZookeeperRole, BTreeMap<RoleGroupName, ValidatedRoleGroupConfig>>,
220+
/// The cluster's operation settings (pause/stop), from which the
221+
/// [`ClusterResourceApplyStrategy`](stackable_operator::cluster_resources::ClusterResourceApplyStrategy)
222+
/// is derived. Carried here so the apply step does not reach into the cluster spec.
223+
pub cluster_operation: ClusterOperation,
224+
/// Object overrides applied to the cluster's resources, carried so the apply step does not reach
225+
/// into the raw [`v1alpha1::ZookeeperCluster`].
226+
pub object_overrides: ObjectOverrides,
216227
}
217228

218229
impl ValidatedCluster {
@@ -228,6 +239,8 @@ impl ValidatedCluster {
228239
ZookeeperRole,
229240
BTreeMap<RoleGroupName, ValidatedRoleGroupConfig>,
230241
>,
242+
cluster_operation: ClusterOperation,
243+
object_overrides: ObjectOverrides,
231244
) -> Self {
232245
Self {
233246
metadata: ObjectMeta {
@@ -243,6 +256,8 @@ impl ValidatedCluster {
243256
product_version,
244257
cluster_config,
245258
role_group_configs,
259+
cluster_operation,
260+
object_overrides,
246261
}
247262
}
248263

@@ -470,6 +485,8 @@ pub fn validate(
470485
listener_class,
471486
},
472487
role_group_configs,
488+
zk.spec.cluster_operation.clone(),
489+
zk.spec.object_overrides.clone(),
473490
))
474491
}
475492

rust/operator-binary/src/znode_controller.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -233,14 +233,7 @@ pub async fn reconcile_znode(
233233
let validated_znode =
234234
validate::validate(&znode, &dereferenced, &ctx.operator_environment)
235235
.context(ValidateClusterSnafu)?;
236-
reconcile_apply(
237-
client,
238-
&znode,
239-
&validated_znode,
240-
dereferenced.zk,
241-
&znode_path,
242-
)
243-
.await
236+
reconcile_apply(client, &validated_znode, dereferenced.zk, &znode_path).await
244237
}
245238
finalizer::Event::Cleanup(_znode) => {
246239
let dereferenced = match dereferenced_objects {
@@ -270,7 +263,6 @@ pub async fn reconcile_znode(
270263

271264
async fn reconcile_apply(
272265
client: &stackable_operator::client::Client,
273-
znode: &v1alpha1::ZookeeperZnode,
274266
validated_znode: &validate::ValidatedZnode,
275267
zk: v1alpha1::ZookeeperCluster,
276268
znode_path: &str,
@@ -279,11 +271,14 @@ async fn reconcile_apply(
279271
APP_NAME,
280272
OPERATOR_NAME,
281273
ZNODE_CONTROLLER_NAME,
282-
&znode.object_ref(&()),
283-
ClusterResourceApplyStrategy::from(&zk.spec.cluster_operation),
284-
&znode.spec.object_overrides,
274+
&validated_znode.object_ref(&()),
275+
ClusterResourceApplyStrategy::from(&validated_znode.cluster_operation),
276+
&validated_znode.object_overrides,
285277
)
286-
.context(ZnodeMissingExpectedKeysSnafu { znode })?;
278+
.with_context(|_| ZnodeMissingExpectedKeysSnafu {
279+
znode: ObjectRef::<v1alpha1::ZookeeperZnode>::new(&validated_znode.name)
280+
.within(validated_znode.namespace.as_ref()),
281+
})?;
287282

288283
znode_mgmt::ensure_znode_exists(
289284
&zk_mgmt_addr(

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ use std::str::FromStr;
88
use snafu::{OptionExt, ResultExt, Snafu};
99
use stackable_operator::{
1010
cli::OperatorEnvironmentOptions,
11-
commons::product_image_selection,
11+
commons::{cluster_operation::ClusterOperation, product_image_selection},
12+
deep_merger::ObjectOverrides,
1213
k8s_openapi::apimachinery::pkg::apis::meta::v1::ObjectMeta,
1314
kube::Resource,
1415
kvp::LabelValue,
@@ -83,6 +84,14 @@ pub struct ValidatedZnode {
8384
/// `app.kubernetes.io/version` label.
8485
pub product_version: ProductVersion,
8586
pub zookeeper_security: ZookeeperSecurity,
87+
/// The parent cluster's operation settings (pause/stop), from which the
88+
/// [`ClusterResourceApplyStrategy`](stackable_operator::cluster_resources::ClusterResourceApplyStrategy)
89+
/// for the znode's resources is derived. Carried here so the apply step does not reach into the
90+
/// cluster spec.
91+
pub cluster_operation: ClusterOperation,
92+
/// Object overrides applied to the znode's resources, carried so the apply step does not reach
93+
/// into the raw [`v1alpha1::ZookeeperZnode`].
94+
pub object_overrides: ObjectOverrides,
8695
}
8796

8897
impl HasName for ValidatedZnode {
@@ -187,5 +196,7 @@ pub fn validate(
187196
uid,
188197
product_version,
189198
zookeeper_security,
199+
cluster_operation: dereferenced_objects.zk.spec.cluster_operation.clone(),
200+
object_overrides: znode.spec.object_overrides.clone(),
190201
})
191202
}

0 commit comments

Comments
 (0)