Skip to content

Commit c800342

Browse files
refactor!: Change CRD for rack awareness according to decision (#495)
* reafctor!: Change CRD for rack awareness according to decision * changelog * charts * Update rust/crd/src/lib.rs Co-authored-by: Nick <NickLarsenNZ@users.noreply.github.com> * fix: whitespace --------- Co-authored-by: Nick <NickLarsenNZ@users.noreply.github.com> Co-authored-by: Nick Larsen <nick.larsen@stackable.tech>
1 parent 7edd743 commit c800342

File tree

5 files changed

+37
-47
lines changed

5 files changed

+37
-47
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ All notable changes to this project will be documented in this file.
66

77
### Added
88

9-
- Added rack awareness support via topology provider implementation ([#429]).
9+
- Added rack awareness support via topology provider implementation ([#429], [#495]).
1010
- More CRD documentation ([#433]).
1111
- Support for exposing HDFS clusters to clients outside of Kubernetes ([#450]).
1212
- Helm: support labels in values.yaml ([#460]).
@@ -42,6 +42,7 @@ All notable changes to this project will be documented in this file.
4242
[#475]: https://github.com/stackabletech/hdfs-operator/pull/475
4343
[#491]: https://github.com/stackabletech/hdfs-operator/pull/491
4444
[#492]: https://github.com/stackabletech/hdfs-operator/pull/492
45+
[#495]: https://github.com/stackabletech/hdfs-operator/pull/495
4546

4647
## [23.11.0] - 2023-11-24
4748

deploy/helm/hdfs-operator/crds/crds.yaml

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,19 +86,18 @@ spec:
8686
rackAwareness:
8787
description: Configuration to control HDFS topology (rack) awareness feature
8888
items:
89+
oneOf:
90+
- required:
91+
- nodeLabel
92+
- required:
93+
- podLabel
8994
properties:
90-
labelName:
91-
description: Name of the label that will be used to resolve a datanode to a topology zone.
95+
nodeLabel:
96+
description: Name of the label on the Kubernetes Node (where the Pod is placed on) used to resolve a datanode to a topology zone.
9297
type: string
93-
labelType:
94-
description: Name of the label type that will be typically either `node` or `pod`, used to create a topology out of datanodes.
95-
enum:
96-
- node
97-
- pod
98+
podLabel:
99+
description: Name of the label on the Kubernetes Pod used to resolve a datanode to a topology zone.
98100
type: string
99-
required:
100-
- labelName
101-
- labelType
102101
type: object
103102
nullable: true
104103
type: array

docs/modules/hdfs/pages/usage-guide/operations/rack-awareness.adoc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,8 @@ metadata:
2323
spec:
2424
clusterConfig:
2525
rackAwareness:
26-
- labelType: node
27-
labelName: topology.kubernetes.io/zone
28-
- labelType: pod
29-
labelName: app.kubernetes.io/role-group
26+
- nodeLabel: topology.kubernetes.io/zone
27+
- podLabel: app.kubernetes.io/role-group
3028
nameNodes:
3129
...
3230
----

rust/crd/src/lib.rs

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -184,33 +184,26 @@ pub struct HdfsClusterConfig {
184184
pub rack_awareness: Option<Vec<TopologyLabel>>,
185185
}
186186

187-
#[derive(Clone, Debug, Default, Deserialize, Eq, Hash, JsonSchema, PartialEq, Serialize)]
187+
#[derive(Clone, Debug, Deserialize, Eq, Hash, JsonSchema, PartialEq, Serialize)]
188188
#[serde(rename_all = "camelCase")]
189-
pub struct TopologyLabel {
190-
/// Name of the label type that will be typically either `node` or `pod`, used to create a
191-
/// topology out of datanodes.
192-
label_type: TopologyLabelType,
189+
pub enum TopologyLabel {
190+
/// Name of the label on the Kubernetes Node (where the Pod is placed on) used to resolve a datanode to a topology
191+
/// zone.
192+
NodeLabel(String),
193193

194-
/// Name of the label that will be used to resolve a datanode to a topology zone.
195-
label_name: String,
194+
/// Name of the label on the Kubernetes Pod used to resolve a datanode to a topology zone.
195+
PodLabel(String),
196196
}
197197

198198
impl TopologyLabel {
199199
pub fn to_config(&self) -> String {
200-
format!("{}:{}", self.label_type, self.label_name)
200+
match &self {
201+
TopologyLabel::NodeLabel(l) => format!("Node:{l}"),
202+
TopologyLabel::PodLabel(l) => format!("Pod:{l}"),
203+
}
201204
}
202205
}
203206

204-
#[derive(
205-
Clone, Debug, Default, Display, Deserialize, Eq, Hash, JsonSchema, PartialEq, Serialize,
206-
)]
207-
#[serde(rename_all = "lowercase")]
208-
pub enum TopologyLabelType {
209-
#[default]
210-
Node,
211-
Pod,
212-
}
213-
214207
fn default_dfs_replication_factor() -> u8 {
215208
DEFAULT_DFS_REPLICATION_FACTOR
216209
}
@@ -833,8 +826,7 @@ impl HdfsCluster {
833826
self.spec
834827
.cluster_config
835828
.rack_awareness
836-
.clone()
837-
.filter(|label_list| !label_list.is_empty())
829+
.as_ref()
838830
.map(|label_list| {
839831
label_list
840832
.iter()
@@ -1483,8 +1475,7 @@ spec:
14831475
clusterConfig:
14841476
zookeeperConfigMapName: hdfs-zk
14851477
rackAwareness:
1486-
- labelType: node
1487-
labelName: kubernetes.io/zone
1478+
- nodeLabel: kubernetes.io/zone
14881479
nameNodes:
14891480
roleGroups:
14901481
default:
@@ -1512,7 +1503,9 @@ spec:
15121503
default:
15131504
replicas: 1";
15141505

1515-
let hdfs: HdfsCluster = serde_yaml::from_str(cr).unwrap();
1506+
let deserializer = serde_yaml::Deserializer::from_str(cr);
1507+
let hdfs: HdfsCluster =
1508+
serde_yaml::with::singleton_map_recursive::deserialize(deserializer).unwrap();
15161509
let role = HdfsRole::DataNode;
15171510
let config = &role.merged_config(&hdfs, "default").unwrap();
15181511
let resources = &config.as_datanode().unwrap().resources;
@@ -1686,10 +1679,8 @@ spec:
16861679
clusterConfig:
16871680
zookeeperConfigMapName: hdfs-zk
16881681
rackAwareness:
1689-
- labelType: node
1690-
labelName: kubernetes.io/zone
1691-
- labelType: pod
1692-
labelName: app.kubernetes.io/role-group
1682+
- nodeLabel: kubernetes.io/zone
1683+
- podLabel: app.kubernetes.io/role-group
16931684
nameNodes:
16941685
roleGroups:
16951686
default:
@@ -1703,7 +1694,10 @@ spec:
17031694
default:
17041695
replicas: 1";
17051696

1706-
let hdfs: HdfsCluster = serde_yaml::from_str(cr).unwrap();
1697+
let deserializer = serde_yaml::Deserializer::from_str(cr);
1698+
let hdfs: HdfsCluster =
1699+
serde_yaml::with::singleton_map_recursive::deserialize(deserializer).unwrap();
1700+
17071701
let rack_awareness = hdfs.rackawareness_config();
17081702
// test the expected value to be used as an env-var: the mapper will use this to
17091703
// convert to an HDFS-internal label

tests/templates/kuttl/topology-provider/11-install-hdfs.yaml.j2

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@ commands:
1616
clusterConfig:
1717
zookeeperConfigMapName: hdfs-zk
1818
rackAwareness:
19-
- labelType: node
20-
labelName: kubernetes.io/hostname
21-
- labelType: pod
22-
labelName: app.kubernetes.io/role-group
19+
- nodeLabel: kubernetes.io/hostname
20+
- podLabel: app.kubernetes.io/role-group
2321
dfsReplication: 1
2422
authentication:
2523
tlsSecretClass: tls

0 commit comments

Comments
 (0)