Skip to content

Commit e09c8e8

Browse files
feat: Add the role-group as a node attribute
1 parent b9370ea commit e09c8e8

4 files changed

Lines changed: 21 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ All notable changes to this project will be documented in this file.
2727
- Helm: Allow Pod `priorityClassName` to be configured ([#34]).
2828
- Support log configuration and log aggregation ([#40]).
2929
- Ensure that the permissions of the configuration files are correct ([#47]).
30+
- Add the role-group as a node attribute ([#63]).
3031

3132
### Changed
3233

@@ -41,3 +42,4 @@ All notable changes to this project will be documented in this file.
4142
[#40]: https://github.com/stackabletech/opensearch-operator/pull/40
4243
[#47]: https://github.com/stackabletech/opensearch-operator/pull/47
4344
[#58]: https://github.com/stackabletech/opensearch-operator/pull/58
45+
[#63]: https://github.com/stackabletech/opensearch-operator/pull/63

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::{
1010
controller::OpenSearchRoleGroupConfig,
1111
crd::v1alpha1,
1212
framework::{
13-
ServiceName,
13+
RoleGroupName, ServiceName,
1414
builder::pod::container::{EnvVarName, EnvVarSet},
1515
role_group_utils,
1616
},
@@ -41,6 +41,10 @@ pub const CONFIG_OPTION_INITIAL_CLUSTER_MANAGER_NODES: &str =
4141
/// Type: string
4242
pub const CONFIG_OPTION_NETWORK_HOST: &str = "network.host";
4343

44+
/// The custom node attribute "role-group"
45+
/// Type: string
46+
pub const CONFIG_OPTION_NODE_ATTR_ROLE_GROUP: &str = "node.attr.role-group";
47+
4448
/// A descriptive name for the node.
4549
/// Type: string
4650
pub const CONFIG_OPTION_NODE_NAME: &str = "node.name";
@@ -61,6 +65,7 @@ pub const CONFIG_OPTION_PLUGINS_SECURITY_SSL_HTTP_ENABLED: &str =
6165
/// Configuration of an OpenSearch node based on the cluster and role-group configuration
6266
pub struct NodeConfig {
6367
cluster: ValidatedCluster,
68+
role_group_name: RoleGroupName,
6469
role_group_config: OpenSearchRoleGroupConfig,
6570
discovery_service_name: ServiceName,
6671
}
@@ -70,11 +75,13 @@ pub struct NodeConfig {
7075
impl NodeConfig {
7176
pub fn new(
7277
cluster: ValidatedCluster,
78+
role_group_name: RoleGroupName,
7379
role_group_config: OpenSearchRoleGroupConfig,
7480
discovery_service_name: ServiceName,
7581
) -> Self {
7682
Self {
7783
cluster,
84+
role_group_name,
7885
role_group_config,
7986
discovery_service_name,
8087
}
@@ -111,6 +118,10 @@ impl NodeConfig {
111118
CONFIG_OPTION_PLUGINS_SECURITY_NODES_DN.to_owned(),
112119
json!(["CN=generated certificate for pod".to_owned()]),
113120
);
121+
config.insert(
122+
CONFIG_OPTION_NODE_ATTR_ROLE_GROUP.to_owned(),
123+
json!(self.role_group_name),
124+
);
114125

115126
for (setting, value) in self
116127
.role_group_config
@@ -311,6 +322,8 @@ mod tests {
311322
let image: ProductImage = serde_json::from_str(r#"{"productVersion": "3.1.0"}"#)
312323
.expect("should be a valid ProductImage");
313324

325+
let role_group_name = RoleGroupName::from_str_unsafe("data");
326+
314327
let role_group_config = OpenSearchRoleGroupConfig {
315328
replicas: test_config.replicas,
316329
config: ValidatedOpenSearchConfig {
@@ -374,6 +387,7 @@ mod tests {
374387

375388
NodeConfig::new(
376389
cluster,
390+
role_group_name,
377391
role_group_config,
378392
ServiceName::from_str_unsafe("my-opensearch-cluster-manager"),
379393
)
@@ -391,6 +405,7 @@ mod tests {
391405
"cluster.name: \"my-opensearch-cluster\"\n",
392406
"discovery.type: \"zen\"\n",
393407
"network.host: \"0.0.0.0\"\n",
408+
"node.attr.role-group: \"data\"\n",
394409
"plugins.security.nodes_dn: [\"CN=generated certificate for pod\"]\n",
395410
"test: \"value\""
396411
)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ impl<'a> RoleGroupBuilder<'a> {
101101
cluster: cluster.clone(),
102102
node_config: NodeConfig::new(
103103
cluster.clone(),
104+
role_group_name.clone(),
104105
role_group_config.clone(),
105106
discovery_service_name,
106107
),

tests/templates/kuttl/smoke/10-assert.yaml.j2

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,7 @@ data:
652652
cluster.routing.allocation.disk.threshold_enabled: "false"
653653
discovery.type: "zen"
654654
network.host: "0.0.0.0"
655+
node.attr.role-group: "cluster-manager"
655656
node.store.allow_mmap: "false"
656657
plugins.security.allow_default_init_securityindex: "true"
657658
plugins.security.nodes_dn: ["CN=generated certificate for pod"]
@@ -687,6 +688,7 @@ data:
687688
cluster.routing.allocation.disk.threshold_enabled: "false"
688689
discovery.type: "zen"
689690
network.host: "0.0.0.0"
691+
node.attr.role-group: "data"
690692
node.store.allow_mmap: "false"
691693
plugins.security.allow_default_init_securityindex: "true"
692694
plugins.security.nodes_dn: ["CN=generated certificate for pod"]

0 commit comments

Comments
 (0)