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 discovery_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 discovery_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 discovery_service_name,
145+ cluster_domain_name,
146+ headless_service_name,
124147 }
125148 }
126149
@@ -258,13 +281,36 @@ 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 EnvVarSet :: new ( )
290+ . with_field_path (
291+ // Prefix with an underscore, so that it occurs before the other environment
292+ // variables which depend on it.
293+ & EnvVarName :: from_str_unsafe ( "_POD_NAME" ) ,
294+ FieldPathEnvVar :: Name ,
295+ )
262296 // Set the OpenSearch node name to the Pod name.
263297 // The node name is used e.g. for INITIAL_CLUSTER_MANAGER_NODES.
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 ) ,
270316 & self . discovery_service_name ,
@@ -510,6 +556,8 @@ mod tests {
510556 role_group_name,
511557 role_group_config,
512558 ServiceName :: from_str_unsafe ( "my-opensearch-cluster-manager" ) ,
559+ DomainName :: from_str ( "cluster.local" ) . expect ( "should be a valid domain name" ) ,
560+ ServiceName :: from_str_unsafe ( "my-opensearch-cluster-default-headless" ) ,
513561 )
514562 }
515563
@@ -609,6 +657,10 @@ mod tests {
609657 assert_eq ! (
610658 EnvVarSet :: new( )
611659 . with_value( & EnvVarName :: from_str_unsafe( "TEST" ) , "value" )
660+ . with_field_path(
661+ & EnvVarName :: from_str_unsafe( "_POD_NAME" ) ,
662+ FieldPathEnvVar :: Name
663+ )
612664 . with_value(
613665 & EnvVarName :: from_str_unsafe( "cluster.initial_cluster_manager_nodes" ) ,
614666 "my-opensearch-cluster-nodes-default-0,my-opensearch-cluster-nodes-default-1" ,
@@ -617,13 +669,25 @@ mod tests {
617669 & EnvVarName :: from_str_unsafe( "discovery.seed_hosts" ) ,
618670 "my-opensearch-cluster-manager" ,
619671 )
672+ . with_value(
673+ & EnvVarName :: from_str_unsafe( "http.publish_host" ) ,
674+ "$(_POD_NAME).my-opensearch-cluster-default-headless.default.svc.cluster.local" ,
675+ )
676+ . with_value(
677+ & EnvVarName :: from_str_unsafe( "network.publish_host" ) ,
678+ "$(_POD_NAME).my-opensearch-cluster-default-headless.default.svc.cluster.local" ,
679+ )
620680 . with_field_path(
621681 & EnvVarName :: from_str_unsafe( "node.name" ) ,
622682 FieldPathEnvVar :: Name
623683 )
624684 . with_value(
625685 & EnvVarName :: from_str_unsafe( "node.roles" ) ,
626686 "cluster_manager,data,ingest,remote_cluster_client"
687+ )
688+ . with_value(
689+ & EnvVarName :: from_str_unsafe( "transport.publish_host" ) ,
690+ "$(_POD_NAME).my-opensearch-cluster-default-headless.default.svc.cluster.local" ,
627691 ) ,
628692 node_config. environment_variables( )
629693 ) ;
0 commit comments