Skip to content

Commit b384980

Browse files
feat: Add OPENSEARCH_HOSTS to discovery ConfigMap
1 parent f39385a commit b384980

15 files changed

Lines changed: 64 additions & 43 deletions

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ All notable changes to this project will be documented in this file.
1919
- Discovery service named `<cluster-name>`, added.
2020
The discovery service is used to populate the discovery ConfigMap.
2121
- Discovery ConfigMap named `<cluster-name>`, added.
22-
The ConfigMap contains the keys `OPENSEARCH_HOST`, `OPENSEARCH_PORT` and `OPENSEARCH_PROTOCOL`.
23-
Users should use this information to connect to the cluster.
22+
The ConfigMap contains the keys `OPENSEARCH_HOSTNAME`, `OPENSEARCH_PORT`, `OPENSEARCH_PROTOCOL`
23+
and `OPENSEARCH_HOSTS`. Users should use this information to connect to the cluster.
2424
- Configuration parameter `spec.nodes.roleConfig.discoveryServiceListenerClass` added to set the
2525
ListenerClass for the discovery service.
2626
- Configuration parameter `spec.nodes.roleGroups.<role-group-name>.config.discoveryServiceExposed`

docs/modules/opensearch/pages/reference/discovery.adoc

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
:clusterName: simple-opensearch
22
:namespace: stackable
3-
:discoveryServiceListenerClass: external-stable
3+
:exampleDiscoveryServiceListenerClass: external-unstable
4+
:exampleOpensearchProtocol: https
5+
:exampleOpensearchIp: 10.104.213.49
6+
:exampleOpensearchPort: 31315
47

58
= Discovery
69
:page-aliases: discovery.adoc
@@ -27,7 +30,7 @@ spec:
2730
serverSecretClass: tls # <3>
2831
nodes:
2932
roleConfig:
30-
discoveryServiceListenerClass: {discoveryServiceListenerClass} # <4>
33+
discoveryServiceListenerClass: {exampleDiscoveryServiceListenerClass} # <4>
3134
roleGroups:
3235
cluster-manager:
3336
config:
@@ -55,7 +58,7 @@ The resulting discovery ConfigMap is `{namespace}/{clusterName}`.
5558

5659
The `{namespace}/{clusterName}` discovery ConfigMap contains the following fields where `{clusterName}` represents the name and `{namespace}` the namespace of the cluster:
5760

58-
`OPENSEARCH_HOST`::
61+
`OPENSEARCH_HOSTNAME`::
5962
====
6063
Contains the hostname or IP of the service that references the exposed role groups.
6164
@@ -64,9 +67,10 @@ In case, `discoveryServiceListenerClass` was set to `cluster-internal`, the foll
6467
[subs="normal"]
6568
{clusterName}.{namespace}.svc.cluster.local
6669
67-
If `discoveryServiceListenerClass` was set to `external-stable`, the content could look like:
70+
If `discoveryServiceListenerClass` was set to `{exampleDiscoveryServiceListenerClass}`, the content could look like:
6871
69-
10.104.213.49
72+
[subs="normal"]
73+
{exampleOpensearchIp}
7074
====
7175

7276
`OPENSEARCH_PORT`::
@@ -75,12 +79,22 @@ Contains the port of the service that references the exposed role groups.
7579
7680
Depending on the `discoveryServiceListenerClass`, the port will be either the default HTTP port 9200 or a NodePort:
7781
78-
31315
82+
[subs="normal"]
83+
{exampleOpensearchPort}
7984
====
8085

8186
`OPENSEARCH_PROTOCOL`::
8287
====
8388
Contains either `http` or `https`, depending on whether a `serverSecretClass` is configured:
8489
85-
https
90+
[subs="normal"]
91+
{exampleOpensearchProtocol}
92+
====
93+
94+
`OPENSEARCH_HOSTS`::
95+
====
96+
Contains the URL of the service that references the exposed role groups.
97+
98+
[subs="normal"]
99+
{exampleOpensearchProtocol}://{exampleOpensearchIp}:{exampleOpensearchPort}
86100
====

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

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -171,23 +171,30 @@ impl<'a> RoleBuilder<'a> {
171171

172172
let metadata = self.common_metadata(discovery_config_map_name(&self.cluster.name));
173173

174+
let protocol = if self.cluster.tls_config.server_secret_class.is_some() {
175+
"https"
176+
} else {
177+
"http"
178+
};
179+
174180
let data = [
181+
("OPENSEARCH_PROTOCOL".to_owned(), protocol.to_owned()),
175182
(
176-
"OPENSEARCH_PROTOCOL".to_owned(),
177-
if self.cluster.tls_config.server_secret_class.is_some() {
178-
"https".to_owned()
179-
} else {
180-
"http".to_owned()
181-
},
182-
),
183-
(
184-
"OPENSEARCH_HOST".to_owned(),
183+
"OPENSEARCH_HOSTNAME".to_owned(),
185184
discovery_endpoint.hostname.to_string(),
186185
),
187186
(
188187
"OPENSEARCH_PORT".to_owned(),
189188
discovery_endpoint.port.to_string(),
190189
),
190+
(
191+
"OPENSEARCH_HOSTS".to_owned(),
192+
format!(
193+
"{protocol}://{hostname}:{port}",
194+
hostname = discovery_endpoint.hostname,
195+
port = discovery_endpoint.port
196+
),
197+
),
191198
];
192199

193200
Some(ConfigMap {
@@ -661,9 +668,10 @@ mod tests {
661668
],
662669
},
663670
"data": {
664-
"OPENSEARCH_HOST": "1.2.3.4",
671+
"OPENSEARCH_HOSTNAME": "1.2.3.4",
665672
"OPENSEARCH_PORT": "12345",
666673
"OPENSEARCH_PROTOCOL": "https",
674+
"OPENSEARCH_HOSTS": "https://1.2.3.4:12345",
667675
},
668676
}),
669677
discovery_config_map

tests/templates/kuttl/backup-restore/22-create-testuser.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ data:
6565
from opensearchpy import OpenSearch
6666
from opensearchpy.exceptions import RequestError
6767
68-
host = os.environ['OPENSEARCH_HOST']
68+
host = os.environ['OPENSEARCH_HOSTNAME']
6969
port = os.environ['OPENSEARCH_PORT']
7070
http_use_tls = os.environ['OPENSEARCH_PROTOCOL'] == 'https'
7171

tests/templates/kuttl/backup-restore/23-create-data.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ data:
6565
from opensearchpy import OpenSearch
6666
from opensearchpy.exceptions import RequestError
6767
68-
host = os.environ['OPENSEARCH_HOST']
68+
host = os.environ['OPENSEARCH_HOSTNAME']
6969
port = os.environ['OPENSEARCH_PORT']
7070
http_use_tls = os.environ['OPENSEARCH_PROTOCOL'] == 'https'
7171

tests/templates/kuttl/backup-restore/30-create-snapshot.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ data:
6565
from opensearchpy import OpenSearch
6666
from opensearchpy.exceptions import RequestError
6767
68-
host = os.environ['OPENSEARCH_HOST']
68+
host = os.environ['OPENSEARCH_HOSTNAME']
6969
port = os.environ['OPENSEARCH_PORT']
7070
http_use_tls = os.environ['OPENSEARCH_PROTOCOL'] == 'https'
7171

tests/templates/kuttl/backup-restore/31-backup-security-indices.yaml.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ data:
129129
-cacert config/tls/ca.crt \
130130
-cert config/tls-client/tls.crt \
131131
-key config/tls-client/tls.key \
132-
--hostname $OPENSEARCH_HOST \
132+
--hostname $OPENSEARCH_HOSTNAME \
133133
-backup /tmp/backup
134134
upload-security-indices-backup.sh: |
135135
#!/usr/bin/env sh

tests/templates/kuttl/backup-restore/60-restore-security-indices.yaml.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,5 +139,5 @@ data:
139139
-cacert config/tls/ca.crt \
140140
-cert config/tls-client/tls.crt \
141141
-key config/tls-client/tls.key \
142-
--hostname $OPENSEARCH_HOST \
142+
--hostname $OPENSEARCH_HOSTNAME \
143143
--configdir /tmp/backup

tests/templates/kuttl/backup-restore/61-restore-snapshot.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ data:
6565
from opensearchpy import OpenSearch
6666
from opensearchpy.exceptions import RequestError
6767
68-
host = os.environ['OPENSEARCH_HOST']
68+
host = os.environ['OPENSEARCH_HOSTNAME']
6969
port = os.environ['OPENSEARCH_PORT']
7070
http_use_tls = os.environ['OPENSEARCH_PROTOCOL'] == 'https'
7171

tests/templates/kuttl/backup-restore/70-test-opensearch-2.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ data:
6565
from opensearchpy import OpenSearch
6666
from opensearchpy.exceptions import RequestError
6767
68-
host = os.environ['OPENSEARCH_HOST']
68+
host = os.environ['OPENSEARCH_HOSTNAME']
6969
port = os.environ['OPENSEARCH_PORT']
7070
http_use_tls = os.environ['OPENSEARCH_PROTOCOL'] == 'https'
7171

0 commit comments

Comments
 (0)