33use std:: str:: FromStr ;
44
55use serde_json:: { Value , json} ;
6- use stackable_operator:: builder:: pod:: container:: FieldPathEnvVar ;
6+ use stackable_operator:: {
7+ builder:: pod:: container:: FieldPathEnvVar , commons:: networking:: DomainName ,
8+ } ;
79
810use super :: ValidatedCluster ;
911use crate :: {
@@ -32,6 +34,11 @@ pub const CONFIG_OPTION_DISCOVERY_SEED_HOSTS: &str = "discovery.seed_hosts";
3234/// Type: string
3335pub const CONFIG_OPTION_DISCOVERY_TYPE : & str = "discovery.type" ;
3436
37+ /// Specifies an address or addresses that an OpenSearch node publishes to other nodes for HTTP
38+ /// communication.
39+ /// Type: (comma-separated) list of strings
40+ pub const CONFIG_OPTION_HTTP_PUBLISH_HOST : & str = "http.publish_host" ;
41+
3542/// A list of cluster-manager-eligible nodes used to bootstrap the cluster.
3643/// Type: (comma-separated) list of strings
3744pub const CONFIG_OPTION_INITIAL_CLUSTER_MANAGER_NODES : & str =
@@ -41,6 +48,11 @@ pub const CONFIG_OPTION_INITIAL_CLUSTER_MANAGER_NODES: &str =
4148/// Type: string
4249pub const CONFIG_OPTION_NETWORK_HOST : & str = "network.host" ;
4350
51+ /// Specifies an address or addresses that an OpenSearch node publishes to other nodes in the
52+ /// cluster so that they can connect to it.
53+ /// Type: (comma-separated) list of strings
54+ pub const CONFIG_OPTION_NETWORK_PUBLISH_HOST : & str = "network.publish_host" ;
55+
4456/// The custom node attribute "role-group"
4557/// Type: string
4658pub const CONFIG_OPTION_NODE_ATTR_ROLE_GROUP : & str = "node.attr.role-group" ;
@@ -97,6 +109,11 @@ pub const CONFIG_OPTION_PLUGINS_SECURITY_SSL_TRANSPORT_PEMKEY_FILEPATH: &str =
97109pub const CONFIG_OPTION_PLUGINS_SECURITY_SSL_TRANSPORT_PEMTRUSTEDCAS_FILEPATH : & str =
98110 "plugins.security.ssl.transport.pemtrustedcas_filepath" ;
99111
112+ /// Specifies an address or addresses that an OpenSearch node publishes to other nodes for
113+ /// transport communication.
114+ /// Type: (comma-separated) list of strings
115+ pub const CONFIG_OPTION_TRANSPORT_PUBLISH_HOST : & str = "transport.publish_host" ;
116+
100117const DEFAULT_OPENSEARCH_HOME : & str = "/stackable/opensearch" ;
101118
102119/// Configuration of an OpenSearch node based on the cluster and role-group configuration
@@ -105,6 +122,8 @@ pub struct NodeConfig {
105122 role_group_name : RoleGroupName ,
106123 role_group_config : OpenSearchRoleGroupConfig ,
107124 pub seed_nodes_service_name : ServiceName ,
125+ cluster_domain_name : DomainName ,
126+ headless_service_name : ServiceName ,
108127}
109128
110129// Most functions are public because their configuration values could also be used in environment
@@ -115,12 +134,16 @@ impl NodeConfig {
115134 role_group_name : RoleGroupName ,
116135 role_group_config : OpenSearchRoleGroupConfig ,
117136 seed_nodes_service_name : ServiceName ,
137+ cluster_domain_name : DomainName ,
138+ headless_service_name : ServiceName ,
118139 ) -> Self {
119140 Self {
120141 cluster,
121142 role_group_name,
122143 role_group_config,
123144 seed_nodes_service_name,
145+ cluster_domain_name,
146+ headless_service_name,
124147 }
125148 }
126149
@@ -258,16 +281,42 @@ impl NodeConfig {
258281 /// The environment variables should only contain node-specific configuration options.
259282 /// Cluster-wide options should be added to the configuration file.
260283 pub fn environment_variables ( & self ) -> EnvVarSet {
284+ let fqdn = format ! (
285+ "$(_POD_NAME).{}.{}.svc.{}" ,
286+ self . headless_service_name, self . cluster. namespace, self . cluster_domain_name
287+ ) ;
288+
261289 let mut env_vars = EnvVarSet :: new ( )
262290 // Set the OpenSearch node name to the Pod name.
263291 // The node name is used e.g. for INITIAL_CLUSTER_MANAGER_NODES.
292+ . with_field_path (
293+ // Prefix with an underscore, so that it occurs before the other environment
294+ // variables which depend on it.
295+ & EnvVarName :: from_str_unsafe ( "_POD_NAME" ) ,
296+ FieldPathEnvVar :: Name ,
297+ )
264298 . with_field_path (
265299 & EnvVarName :: from_str_unsafe ( CONFIG_OPTION_NODE_NAME ) ,
266300 FieldPathEnvVar :: Name ,
267301 )
302+ . with_value (
303+ & EnvVarName :: from_str_unsafe ( CONFIG_OPTION_NETWORK_PUBLISH_HOST ) ,
304+ & fqdn,
305+ )
306+ . with_value (
307+ & EnvVarName :: from_str_unsafe ( CONFIG_OPTION_TRANSPORT_PUBLISH_HOST ) ,
308+ & fqdn,
309+ )
310+ . with_value (
311+ & EnvVarName :: from_str_unsafe ( CONFIG_OPTION_HTTP_PUBLISH_HOST ) ,
312+ & fqdn,
313+ )
268314 . with_value (
269315 & EnvVarName :: from_str_unsafe ( CONFIG_OPTION_DISCOVERY_SEED_HOSTS ) ,
270- & self . seed_nodes_service_name ,
316+ format ! (
317+ "{}.{}.svc.{}" ,
318+ self . seed_nodes_service_name, self . cluster. namespace, self . cluster_domain_name
319+ ) ,
271320 )
272321 . with_value (
273322 & EnvVarName :: from_str_unsafe ( CONFIG_OPTION_NODE_ROLES ) ,
@@ -547,7 +596,9 @@ mod tests {
547596 cluster,
548597 role_group_name,
549598 role_group_config,
550- ServiceName :: from_str_unsafe ( "my-opensearch-cluster-discovery" ) ,
599+ ServiceName :: from_str_unsafe ( "my-opensearch-seed-nodes" ) ,
600+ DomainName :: from_str ( "cluster.local" ) . expect ( "should be a valid domain name" ) ,
601+ ServiceName :: from_str_unsafe ( "my-opensearch-cluster-default-headless" ) ,
551602 )
552603 }
553604
0 commit comments