Skip to content

Commit ed57da5

Browse files
maltesanderclaude
andcommitted
refactor: resolve namenode/journalnode pod refs during validation
Move the pod_refs lookups for namenodes and journalnodes out of reconcile_hdfs and into validate_cluster, storing the results on ValidatedCluster. Build steps that already receive the validated cluster (config_map and hdfs_site) now read the refs from it instead of taking them as separate parameters. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 5b22234 commit ed57da5

6 files changed

Lines changed: 29 additions & 28 deletions

File tree

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::{
1616
ConfigFileName, core_site, hadoop_policy, hdfs_site, security_properties, ssl_client,
1717
ssl_server,
1818
},
19-
crd::{HdfsNodeRole, HdfsPodRef, v1alpha1},
19+
crd::{HdfsNodeRole, v1alpha1},
2020
hdfs_controller::ValidatedCluster,
2121
product_logging::extend_role_group_config_map,
2222
};
@@ -62,8 +62,6 @@ pub fn build_rolegroup_config_map(
6262
cluster_info: &KubernetesClusterInfo,
6363
metadata: &ObjectMetaBuilder,
6464
rolegroup_ref: &RoleGroupRef<v1alpha1::HdfsCluster>,
65-
namenode_podrefs: &[HdfsPodRef],
66-
journalnode_podrefs: &[HdfsPodRef],
6765
) -> Result<ConfigMap> {
6866
tracing::info!("Setting up ConfigMap for {:?}", rolegroup_ref);
6967

@@ -88,8 +86,6 @@ pub fn build_rolegroup_config_map(
8886
cluster,
8987
cluster_info,
9088
merged_config,
91-
namenode_podrefs,
92-
journalnode_podrefs,
9389
config_overrides.hdfs_site_xml.clone(),
9490
);
9591
let core_site_xml = core_site::build(

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

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@ use stackable_operator::{
77
};
88

99
use crate::{
10-
config::HdfsSiteConfigBuilder,
11-
controller::build::properties::resolved_overrides,
12-
crd::{AnyNodeConfig, HdfsPodRef},
13-
hdfs_controller::ValidatedCluster,
10+
config::HdfsSiteConfigBuilder, controller::build::properties::resolved_overrides,
11+
crd::AnyNodeConfig, hdfs_controller::ValidatedCluster,
1412
};
1513

1614
/// Renders `hdfs-site.xml`: operator defaults, HA wiring derived from the pod
@@ -19,11 +17,11 @@ pub fn build(
1917
cluster: &ValidatedCluster,
2018
cluster_info: &KubernetesClusterInfo,
2119
merged_config: &AnyNodeConfig,
22-
namenode_podrefs: &[HdfsPodRef],
23-
journalnode_podrefs: &[HdfsPodRef],
2420
overrides: KeyValueConfigOverrides,
2521
) -> String {
2622
let cluster_config = &cluster.cluster_config;
23+
let namenode_podrefs = &cluster.namenode_podrefs;
24+
let journalnode_podrefs = &cluster.journalnode_podrefs;
2725
// IMPORTANT: these folders must be under the volume mount point, otherwise they will not
2826
// be formatted by the namenode, or used by the other services.
2927
// See also: https://github.com/apache-spark-on-k8s/kubernetes-HDFS/commit/aef9586ecc8551ca0f0a468c3b917d8c38f494a0
@@ -133,8 +131,6 @@ mod tests {
133131
&validated_cluster(),
134132
&cluster_info(),
135133
&merged,
136-
&[],
137-
&[],
138134
config_overrides(&[]),
139135
);
140136
assert!(
@@ -154,8 +150,6 @@ mod tests {
154150
&validated_cluster(),
155151
&cluster_info(),
156152
&merged,
157-
&[],
158-
&[],
159153
config_overrides(&[("dfs.replication", "5")]),
160154
);
161155
assert!(

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ apiVersion: hdfs.stackable.tech/v1alpha1
9494
kind: HdfsCluster
9595
metadata:
9696
name: hdfs
97+
namespace: default
9798
spec:
9899
image:
99100
productVersion: 3.4.0

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ pub enum Error {
4242

4343
#[snafu(display("failed to resolve and merge config for role and role group"))]
4444
FailedToResolveConfig { source: crate::crd::Error },
45+
46+
#[snafu(display("failed to create pod references"))]
47+
CreatePodReferences { source: crate::crd::Error },
4548
}
4649

4750
pub fn validate_cluster(
@@ -103,12 +106,23 @@ pub fn validate_cluster(
103106
role_groups.insert(hdfs_role, group_configs);
104107
}
105108

109+
// A list of all name and journal nodes across all role groups is needed for all
110+
// ConfigMaps and initialization checks.
111+
let namenode_podrefs = hdfs
112+
.pod_refs(&HdfsNodeRole::Name)
113+
.context(CreatePodReferencesSnafu)?;
114+
let journalnode_podrefs = hdfs
115+
.pod_refs(&HdfsNodeRole::Journal)
116+
.context(CreatePodReferencesSnafu)?;
117+
106118
Ok(ValidatedCluster {
107119
name: ClusterName::from_str(&hdfs.name_any()).context(InvalidClusterNameSnafu)?,
108120
image: resolved_product_image,
109121
cluster_config: ValidatedClusterConfig::resolve(hdfs, hdfs_opa_config),
110122
role_groups,
111123
role_configs,
124+
namenode_podrefs,
125+
journalnode_podrefs,
112126
})
113127
}
114128

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,6 +1161,7 @@ impl HdfsNodeRole {
11611161
/// Reference to a single `Pod` that is a component of a [`HdfsCluster`]
11621162
///
11631163
/// Used for service discovery.
1164+
#[derive(Clone, Debug)]
11641165
pub struct HdfsPodRef {
11651166
pub namespace: String,
11661167
pub role_group_service_name: String,

rust/operator-binary/src/hdfs_controller.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ pub struct ValidatedCluster {
7777
pub cluster_config: ValidatedClusterConfig,
7878
pub role_groups: BTreeMap<HdfsNodeRole, BTreeMap<String, ValidatedRoleGroupConfig>>,
7979
pub role_configs: BTreeMap<HdfsNodeRole, ValidatedRoleConfig>,
80+
/// Pod references for all namenodes across all role groups. Needed for all
81+
/// ConfigMaps and initialization checks. Resolved once during validation.
82+
pub namenode_podrefs: Vec<HdfsPodRef>,
83+
/// Pod references for all journalnodes across all role groups. Resolved once
84+
/// during validation.
85+
pub journalnode_podrefs: Vec<HdfsPodRef>,
8086
}
8187

8288
/// Cluster-wide settings resolved once during validation, so the build steps no
@@ -205,9 +211,6 @@ pub enum Error {
205211
source: stackable_operator::cluster_resources::Error,
206212
},
207213

208-
#[snafu(display("failed to create pod references"))]
209-
CreatePodReferences { source: crate::crd::Error },
210-
211214
#[snafu(display("failed to create cluster event"))]
212215
FailedToCreateClusterEvent { source: crate::event::Error },
213216

@@ -296,13 +299,6 @@ pub async fn reconcile_hdfs(
296299
let resolved_product_image = &validated.image;
297300

298301
let hdfs_obj_ref = hdfs.object_ref(&());
299-
// A list of all name and journal nodes across all role groups is needed for all ConfigMaps and initialization checks.
300-
let namenode_podrefs = hdfs
301-
.pod_refs(&HdfsNodeRole::Name)
302-
.context(CreatePodReferencesSnafu)?;
303-
let journalnode_podrefs = hdfs
304-
.pod_refs(&HdfsNodeRole::Journal)
305-
.context(CreatePodReferencesSnafu)?;
306302

307303
let mut cluster_resources = ClusterResources::new(
308304
APP_NAME,
@@ -409,8 +405,6 @@ pub async fn reconcile_hdfs(
409405
&client.kubernetes_cluster_info,
410406
metadata,
411407
&rolegroup_ref,
412-
&namenode_podrefs,
413-
&journalnode_podrefs,
414408
)
415409
.context(BuildRoleGroupConfigMapSnafu)?;
416410

@@ -423,7 +417,7 @@ pub async fn reconcile_hdfs(
423417
resolved_product_image,
424418
Some(env_overrides),
425419
merged_config,
426-
&namenode_podrefs,
420+
&validated.namenode_podrefs,
427421
&rbac_sa,
428422
)?;
429423

@@ -686,6 +680,7 @@ apiVersion: hdfs.stackable.tech/v1alpha1
686680
kind: HdfsCluster
687681
metadata:
688682
name: hdfs
683+
namespace: default
689684
spec:
690685
image:
691686
productVersion: 3.4.0

0 commit comments

Comments
 (0)