Skip to content

Commit da0084b

Browse files
feat: Service discovery and exposition (#94)
* feat: Rename discovery service * Set initial_cluster_manager_nodes only on cluster_manager nodes; Add opensearch-discovery scope only on cluster_manager nodes * Fields discoveryServiceExposed and discoveryServiceListenerClass added to the CRD * Rename opensearch-discovery service to opensearch-seed-nodes and remove the HTTP port * wip * Set seed nodes service scope on the internal TLS volume * test: Use the discovery ConfigMap in all tests * test(backup-restore): Add the option to disable TLS in S3 * Publish fully qualified domain names so that the SANs in the TLS certificates are matched * test(opensearch-dashboards): Use the OpenSearch discovery ConfigMap for OpenSearch Dashboards * Fix unit tests * test: Use the images built by CI * chore: Use constant for HTTP port name * Fix regexes for attributed string types; Add unit tests for validation * test: Add unit tests for Port * Remove TODO after successful test * test(smoke): Remove assertions about PVC statuses * Add missing start and end tags to regular expressions * Update changelog * docs: Document the discovery ConfigMap * docs: Reference Discovery ConfigMap in the ListenerClass usage guide * Remove allow_k8s_contexts from Tiltfile * test: Make unit tests less verbose * test: Remove OpenSearch 3.4.0 for now * feat: Add OPENSEARCH_HOSTS to discovery ConfigMap * docs: Use the discovery ConfigMap in "First Steps" * docs: Use the discovery ConfigMap in "OpenSearch Dashboards" * docs: Fix clippy warnings * docs: Update image with deployed Kubernetes resources * docs: Update the description of the Kubernetes resources * Run pre-commit
1 parent 365aa05 commit da0084b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1302
-431
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@ All notable changes to this project will be documented in this file.
1414
- Enable the [restart-controller](https://docs.stackable.tech/home/nightly/commons-operator/restarter/), so that the Pods are automatically restarted on config changes ([#97]).
1515
- Configure OpenSearch to publish the fully-qualified domain names of the nodes instead of the IP
1616
addresses, so that TLS certificates can be verified ([#100]).
17+
- Add service discovery and exposition ([#94]):
18+
- Service to set up the cluster renamed to `<cluster-name>-seed-nodes`.
19+
- Discovery service named `<cluster-name>`, added.
20+
The discovery service is used to populate the discovery ConfigMap.
21+
- Discovery ConfigMap named `<cluster-name>`, added.
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.
24+
- Configuration parameter `spec.nodes.roleConfig.discoveryServiceListenerClass` added to set the
25+
ListenerClass for the discovery service.
26+
- Configuration parameter `spec.nodes.roleGroups.<role-group-name>.config.discoveryServiceExposed`
27+
added to expose a role-group via the discovery service.
1728

1829
### Changed
1930

@@ -24,6 +35,7 @@ All notable changes to this project will be documented in this file.
2435
[#76]: https://github.com/stackabletech/opensearch-operator/pull/76
2536
[#91]: https://github.com/stackabletech/opensearch-operator/pull/91
2637
[#93]: https://github.com/stackabletech/opensearch-operator/pull/93
38+
[#94]: https://github.com/stackabletech/opensearch-operator/pull/94
2739
[#97]: https://github.com/stackabletech/opensearch-operator/pull/97
2840
[#100]: https://github.com/stackabletech/opensearch-operator/pull/100
2941

deploy/helm/opensearch-operator/crds/crds.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,10 @@ spec:
246246
type: object
247247
x-kubernetes-preserve-unknown-fields: true
248248
type: object
249+
discoveryServiceExposed:
250+
description: Determines whether this role group is exposed in the discovery service.
251+
nullable: true
252+
type: boolean
249253
gracefulShutdownTimeout:
250254
description: |-
251255
Time period Pods have to gracefully shut down, e.g. `30m`, `1h` or `2d`. Consult the
@@ -517,11 +521,19 @@ spec:
517521
x-kubernetes-preserve-unknown-fields: true
518522
roleConfig:
519523
default:
524+
discoveryServiceListenerClass: cluster-internal
520525
podDisruptionBudget:
521526
enabled: true
522527
maxUnavailable: null
523528
description: This is a product-agnostic RoleConfig, which is sufficient for most of the products.
524529
properties:
530+
discoveryServiceListenerClass:
531+
default: cluster-internal
532+
description: The [ListenerClass](https://docs.stackable.tech/home/nightly/listener-operator/listenerclass.html) that is used for the discovery service.
533+
maxLength: 253
534+
minLength: 1
535+
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
536+
type: string
525537
podDisruptionBudget:
526538
default:
527539
enabled: true
@@ -600,6 +612,10 @@ spec:
600612
type: object
601613
x-kubernetes-preserve-unknown-fields: true
602614
type: object
615+
discoveryServiceExposed:
616+
description: Determines whether this role group is exposed in the discovery service.
617+
nullable: true
618+
type: boolean
603619
gracefulShutdownTimeout:
604620
description: |-
605621
Time period Pods have to gracefully shut down, e.g. `30m`, `1h` or `2d`. Consult the

docs/modules/opensearch/examples/getting_started/getting_started.sh

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,25 +75,21 @@ kubectl rollout status --watch statefulset/simple-opensearch-nodes-default --tim
7575
# wait a bit for the port to open
7676
sleep 10
7777

78-
echo "Starting port-forwarding of port 9200"
79-
# tag::opensearch-port-forwarding[]
80-
kubectl port-forward services/simple-opensearch 9200 > /dev/null 2>&1 &
81-
# end::opensearch-port-forwarding[]
82-
PORT_FORWARD_PID=$!
83-
# shellcheck disable=2064 # we want the PID evaluated now, not at the time the trap is
84-
trap "kill $PORT_FORWARD_PID" EXIT
85-
sleep 5
86-
8778
echo "Using the REST API"
8879
# tag::rest-api[]
8980
export CREDENTIALS=admin:AJVFsGJBbpT6mChn
9081

82+
OPENSEARCH_HOST=$(
83+
kubectl get configmap simple-opensearch \
84+
--output=jsonpath='{.data.OPENSEARCH_HOSTS}'
85+
)
86+
9187
curl \
9288
--insecure \
9389
--user $CREDENTIALS \
9490
--request PUT \
9591
--json '{"name": "Stackable"}' \
96-
https://localhost:9200/sample_index/_doc/1
92+
"$OPENSEARCH_HOST/sample_index/_doc/1"
9793

9894
# Output:
9995
# {"_index":"sample_index","_id":"1","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":0,"_primary_term":1}
@@ -102,7 +98,7 @@ curl \
10298
--insecure \
10399
--user $CREDENTIALS \
104100
--request GET \
105-
https://localhost:9200/sample_index/_doc/1
101+
"$OPENSEARCH_HOST/sample_index/_doc/1"
106102

107103
# Output:
108104
# {"_index":"sample_index","_id":"1","_version":1,"_seq_no":0,"_primary_term":1,"found":true,"_source":{"name": "Stackable"}}

docs/modules/opensearch/examples/getting_started/getting_started.sh.j2

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,25 +75,21 @@ kubectl rollout status --watch statefulset/simple-opensearch-nodes-default --tim
7575
# wait a bit for the port to open
7676
sleep 10
7777

78-
echo "Starting port-forwarding of port 9200"
79-
# tag::opensearch-port-forwarding[]
80-
kubectl port-forward services/simple-opensearch 9200 > /dev/null 2>&1 &
81-
# end::opensearch-port-forwarding[]
82-
PORT_FORWARD_PID=$!
83-
# shellcheck disable=2064 # we want the PID evaluated now, not at the time the trap is
84-
trap "kill $PORT_FORWARD_PID" EXIT
85-
sleep 5
86-
8778
echo "Using the REST API"
8879
# tag::rest-api[]
8980
export CREDENTIALS=admin:AJVFsGJBbpT6mChn
9081

82+
OPENSEARCH_HOST=$(
83+
kubectl get configmap simple-opensearch \
84+
--output=jsonpath='{.data.OPENSEARCH_HOSTS}'
85+
)
86+
9187
curl \
9288
--insecure \
9389
--user $CREDENTIALS \
9490
--request PUT \
9591
--json '{"name": "Stackable"}' \
96-
https://localhost:9200/sample_index/_doc/1
92+
"$OPENSEARCH_HOST/sample_index/_doc/1"
9793

9894
# Output:
9995
# {"_index":"sample_index","_id":"1","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":0,"_primary_term":1}
@@ -102,7 +98,7 @@ curl \
10298
--insecure \
10399
--user $CREDENTIALS \
104100
--request GET \
105-
https://localhost:9200/sample_index/_doc/1
101+
"$OPENSEARCH_HOST/sample_index/_doc/1"
106102

107103
# Output:
108104
# {"_index":"sample_index","_id":"1","_version":1,"_seq_no":0,"_primary_term":1,"found":true,"_source":{"name": "Stackable"}}

docs/modules/opensearch/examples/getting_started/opensearch-dashboards-values.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
---
2-
opensearchHosts: https://simple-opensearch-nodes-default.default.svc.cluster.local:9200
32
image:
43
repository: oci.stackable.tech/sdp/opensearch-dashboards
54
tag: 3.1.0-stackable0.0.0-dev
@@ -23,6 +22,11 @@ config:
2322
cookie:
2423
secure: true
2524
extraEnvs:
25+
- name: OPENSEARCH_HOSTS
26+
valueFrom:
27+
configMapKeyRef:
28+
name: simple-opensearch
29+
key: OPENSEARCH_HOSTS
2630
- name: OPENSEARCH_PASSWORD
2731
valueFrom:
2832
secretKeyRef:

docs/modules/opensearch/examples/getting_started/opensearch-dashboards-values.yaml.j2

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
---
2-
opensearchHosts: https://simple-opensearch-nodes-default.default.svc.cluster.local:9200
32
image:
43
repository: oci.stackable.tech/sdp/opensearch-dashboards
54
tag: 3.1.0-stackable{{ versions.opensearch }}
@@ -23,6 +22,11 @@ config:
2322
cookie:
2423
secure: true
2524
extraEnvs:
25+
- name: OPENSEARCH_HOSTS
26+
valueFrom:
27+
configMapKeyRef:
28+
name: simple-opensearch
29+
key: OPENSEARCH_HOSTS
2630
- name: OPENSEARCH_PASSWORD
2731
valueFrom:
2832
secretKeyRef:

docs/modules/opensearch/examples/getting_started/opensearch.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ spec:
77
image:
88
productVersion: 3.1.0
99
nodes:
10+
roleConfig:
11+
discoveryServiceListenerClass: external-stable
1012
roleGroups:
1113
default:
1214
replicas: 3

docs/modules/opensearch/images/opensearch_overview.drawio.svg

Lines changed: 1 addition & 1 deletion
Loading

docs/modules/opensearch/pages/getting_started/first_steps.adoc

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,6 @@ You can do so with this command:
5858
include::example$getting_started/getting_started.sh[tag=await-cluster]
5959
----
6060

61-
== Connecting to the HTTP endpoint
62-
63-
Once the OpenSearch nodes are created, you can use the REST API of OpenSearch.
64-
65-
To forward the HTTP port (`9200`) to localhost, run:
66-
67-
[source,bash]
68-
----
69-
include::example$getting_started/getting_started.sh[tag=opensearch-port-forwarding]
70-
----
71-
7261
== Using the REST API
7362

7463
You can use the REST API as follows:

docs/modules/opensearch/pages/index.adoc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,18 @@ It helps you tune your cluster to your needs by configuring xref:usage-guide/sto
4141

4242
=== Kubernetes resources
4343

44-
Based on the custom resources you define, the operator creates ConfigMaps, StatefulSets and Services.
44+
Based on the custom resources you define, the operator creates ConfigMaps, StatefulSets, Services and so on.
4545

4646
image::opensearch_overview.drawio.svg[A diagram depicting the Kubernetes resources created by the operator]
4747

4848
The diagram above depicts all the Kubernetes resources created by the operator, and how they relate to each other.
4949

50-
For every xref:concepts:roles-and-role-groups.adoc#role-groups[role group] you define, the operator creates a StatefulSet with the amount of replicas defined in the role group.
51-
For every role group, a Service is created, as well as one for the whole cluster that references the cluster manager nodes.
50+
What should be highlighted, is the xref:reference/discovery.adoc[discovery ConfigMap] which is named the same as the OpenSearchCluster.
51+
It references the Service that should be used to connect to the cluster.
5252

53-
Additionally, a ConfigMap is created for each role group.
54-
These ConfigMaps contain configuration files like `opensearch.yml`.
53+
For every xref:concepts:roles-and-role-groups.adoc#role-groups[role group] you define, the operator deploys OpenSearch as a StatefulSet with the amount of replicas defined in the role group.
54+
The pods of a StatefulSet use the configuration from the role group ConfigMap, i.e. they all use the same OpenSearch node roles, e.g. `cluster-manager` or `data`, and xref:opensearch:usage-guide/storage-resource-configuration.adoc[resource configurations].
55+
If you want dedicated `cluster-manager` and `data` nodes, you just define two role groups with according configurations as described in xref:opensearch:usage-guide/node-roles.adoc[].
5556

5657
== Supported versions
5758

0 commit comments

Comments
 (0)