@@ -7,52 +7,24 @@ use super::ValidatedCluster;
77use crate :: {
88 controller:: OpenSearchRoleGroupConfig ,
99 crd:: v1alpha1,
10- framework:: { builder:: pod:: container:: EnvVarSet , role_group_utils} ,
10+ framework:: {
11+ builder:: pod:: container:: { EnvVarName , EnvVarSet } ,
12+ role_group_utils,
13+ } ,
1114} ;
1215
1316pub const CONFIGURATION_FILE_OPENSEARCH_YML : & str = "opensearch.yml" ;
1417
15- // TODO Document how to enter config_overrides of various types, e.g. string, list, boolean,
16- // object, ...
17-
18- // Configuration file format
19- //
20- // This is not well documented.
21- //
22- // A list setting can be written as
23- // - a comma-separated list, e.g.
24- // ```
25- // setting: a,b,c
26- // ```
27- // Commas in the values cannot be escaped.
28- // - a JSON list, e.g.
29- // ```
30- // setting: ["a", "b", "c"]
31- // ```
32- // - a YAML list, e.g.
33- // ```
34- // setting:
35- // - a
36- // - b
37- // - c
38- // ```
39- // - a (legacy) flat list, e.g.
40- // ```
41- // setting.0: a
42- // setting.1: b
43- // setting.2: b
44- // ```
45-
4618/// type: string
4719pub const CONFIG_OPTION_CLUSTER_NAME : & str = "cluster.name" ;
4820
49- /// type: list of strings
21+ /// type: (comma-separated) list of strings
5022pub const CONFIG_OPTION_DISCOVERY_SEED_HOSTS : & str = "discovery.seed_hosts" ;
5123
5224/// type: string
5325pub const CONFIG_OPTION_DISCOVERY_TYPE : & str = "discovery.type" ;
5426
55- /// type: list of strings
27+ /// type: (comma-separated) list of strings
5628pub const CONFIG_OPTION_INITIAL_CLUSTER_MANAGER_NODES : & str =
5729 "cluster.initial_cluster_manager_nodes" ;
5830
@@ -62,10 +34,10 @@ pub const CONFIG_OPTION_NETWORK_HOST: &str = "network.host";
6234/// type: string
6335pub const CONFIG_OPTION_NODE_NAME : & str = "node.name" ;
6436
65- /// type: list of strings
37+ /// type: (comma-separated) list of strings
6638pub const CONFIG_OPTION_NODE_ROLES : & str = "node.roles" ;
6739
68- /// type: list of strings
40+ /// type: (comma-separated) list of strings
6941pub const CONFIG_OPTION_PLUGINS_SECURITY_NODES_DN : & str = "plugins.security.nodes_dn" ;
7042
7143pub struct NodeConfig {
@@ -156,17 +128,20 @@ impl NodeConfig {
156128 EnvVarSet :: new ( )
157129 // Set the OpenSearch node name to the Pod name.
158130 // The node name is used e.g. for `{INITIAL_CLUSTER_MANAGER_NODES}`.
159- . with_field_path ( CONFIG_OPTION_NODE_NAME , FieldPathEnvVar :: Name )
131+ . with_field_path (
132+ EnvVarName :: from_str_unsafe ( CONFIG_OPTION_NODE_NAME ) ,
133+ FieldPathEnvVar :: Name ,
134+ )
160135 . with_value (
161- CONFIG_OPTION_DISCOVERY_SEED_HOSTS ,
136+ EnvVarName :: from_str_unsafe ( CONFIG_OPTION_DISCOVERY_SEED_HOSTS ) ,
162137 & self . discovery_service_name ,
163138 )
164139 . with_value (
165- CONFIG_OPTION_INITIAL_CLUSTER_MANAGER_NODES ,
140+ EnvVarName :: from_str_unsafe ( CONFIG_OPTION_INITIAL_CLUSTER_MANAGER_NODES ) ,
166141 self . initial_cluster_manager_nodes ( ) ,
167142 )
168143 . with_value (
169- CONFIG_OPTION_NODE_ROLES ,
144+ EnvVarName :: from_str_unsafe ( CONFIG_OPTION_NODE_ROLES ) ,
170145 self . role_group_config
171146 . config
172147 . node_roles
@@ -177,7 +152,7 @@ impl NodeConfig {
177152 // is safe.
178153 . join ( "," ) ,
179154 )
180- . with_values ( self . role_group_config . env_overrides . clone ( ) )
155+ . merge ( self . role_group_config . env_overrides . clone ( ) )
181156 }
182157
183158 fn to_yaml ( kv : serde_json:: Map < String , Value > ) -> String {
@@ -274,7 +249,7 @@ mod tests {
274249 affinity:: StackableAffinity , product_image_selection:: ProductImage ,
275250 resources:: Resources ,
276251 } ,
277- k8s_openapi:: api:: core:: v1:: { EnvVar , EnvVarSource , ObjectFieldSelector , PodTemplateSpec } ,
252+ k8s_openapi:: api:: core:: v1:: PodTemplateSpec ,
278253 kube:: api:: ObjectMeta ,
279254 role_utils:: GenericRoleConfig ,
280255 } ;
@@ -350,7 +325,8 @@ mod tests {
350325 listener_class : "cluster-internal" . to_string ( ) ,
351326 } ,
352327 config_overrides : HashMap :: default ( ) ,
353- env_overrides : [ ( "TEST" . to_owned ( ) , "value" . to_owned ( ) ) ] . into ( ) ,
328+ env_overrides : EnvVarSet :: new ( )
329+ . with_value ( EnvVarName :: from_str_unsafe ( "TEST" ) , "value" ) ,
354330 cli_overrides : BTreeMap :: default ( ) ,
355331 pod_overrides : PodTemplateSpec :: default ( ) ,
356332 product_specific_common_config : GenericProductSpecificCommonConfig :: default ( ) ,
@@ -364,44 +340,23 @@ mod tests {
364340
365341 let env_vars = node_config. environment_variables ( ) ;
366342
367- // TODO Test EnvVarSet and compare EnvVarSets
368343 assert_eq ! (
369- vec![
370- EnvVar {
371- name: "TEST" . to_owned( ) ,
372- value: Some ( "value" . to_owned( ) ) ,
373- value_from: None
374- } ,
375- EnvVar {
376- name: "cluster.initial_cluster_manager_nodes" . to_owned( ) ,
377- value: Some ( "" . to_owned( ) ) ,
378- value_from: None
379- } ,
380- EnvVar {
381- name: "discovery.seed_hosts" . to_owned( ) ,
382- value: Some ( "my-opensearch-cluster-manager" . to_owned( ) ) ,
383- value_from: None
384- } ,
385- EnvVar {
386- name: "node.name" . to_owned( ) ,
387- value: None ,
388- value_from: Some ( EnvVarSource {
389- config_map_key_ref: None ,
390- field_ref: Some ( ObjectFieldSelector {
391- api_version: None ,
392- field_path: "metadata.name" . to_owned( )
393- } ) ,
394- resource_field_ref: None ,
395- secret_key_ref: None
396- } )
397- } ,
398- EnvVar {
399- name: "node.roles" . to_owned( ) ,
400- value: Some ( "" . to_owned( ) ) ,
401- value_from: None
402- }
403- ] ,
404- <EnvVarSet as Into <Vec <EnvVar >>>:: into( env_vars)
344+ EnvVarSet :: new( )
345+ . with_value( EnvVarName :: from_str_unsafe( "TEST" ) , "value" , )
346+ . with_value(
347+ EnvVarName :: from_str_unsafe( "cluster.initial_cluster_manager_nodes" ) ,
348+ "" ,
349+ )
350+ . with_value(
351+ EnvVarName :: from_str_unsafe( "discovery.seed_hosts" ) ,
352+ "my-opensearch-cluster-manager" ,
353+ )
354+ . with_field_path(
355+ EnvVarName :: from_str_unsafe( "node.name" ) ,
356+ FieldPathEnvVar :: Name
357+ )
358+ . with_value( EnvVarName :: from_str_unsafe( "node.roles" ) , "" , ) ,
359+ env_vars
405360 ) ;
406361 }
407362}
0 commit comments