-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgetting_started.sh.j2
More file actions
executable file
·109 lines (91 loc) · 3.47 KB
/
Copy pathgetting_started.sh.j2
File metadata and controls
executable file
·109 lines (91 loc) · 3.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#! /usr/bin/env bash
set -euo pipefail
# DO NOT EDIT THE SCRIPT
# Instead, update the j2 template, and regenerate it for dev with `make render-docs`.
# This script contains all the code snippets from the guide, as well as some assert tests
# to test if the instructions in the guide work. The user *could* use it, but it is intended
# for testing only.
# The script will install the operators, create a OpenSearch instance and briefly open a port
# forward and connect to the OpenSearch instance to make sure it is up and running.
# No running processes are left behind (i.e. the port-forwarding is closed at the end)
if [ $# -eq 0 ]
then
echo "Installation method argument ('helm' or 'stackablectl') required."
exit 1
fi
cd "$(dirname "$0")"
case "$1" in
"helm")
echo "Installing Operators with Helm"
# tag::helm-install-operators[]
helm install --wait commons-operator oci://{{ helm.repo_url }}/{{ helm.repo_name }}/commons-operator --version {{ versions.commons }}
helm install --wait secret-operator oci://{{ helm.repo_url }}/{{ helm.repo_name }}/secret-operator --version {{ versions.secret }}
helm install --wait listener-operator oci://{{ helm.repo_url }}/{{ helm.repo_name }}/listener-operator --version {{ versions.listener }}
helm install --wait opensearch-operator oci://{{ helm.repo_url }}/{{ helm.repo_name }}/opensearch-operator --version {{ versions.opensearch }}
# end::helm-install-operators[]
;;
"stackablectl")
echo "installing Operators with stackablectl"
# tag::stackablectl-install-operators[]
stackablectl operator install \
commons={{ versions.commons }} \
secret={{ versions.secret }} \
listener={{ versions.listener }} \
opensearch={{ versions.opensearch }}
# end::stackablectl-install-operators[]
;;
*)
echo "Need to give 'helm' or 'stackablectl' as an argument for which installation method to use!"
exit 1
;;
esac
echo "Creating OpenSearch security plugin configuration"
# tag::apply-security-config[]
kubectl apply -f opensearch-security-config.yaml
# end::apply-security-config[]
echo "Creating OpenSearch cluster"
# tag::apply-cluster[]
kubectl apply -f opensearch.yaml
# end::apply-cluster[]
sleep 5
for (( i=1; i<=15; i++ ))
do
echo "Waiting for OpenSearchCluster to appear ..."
if eval kubectl get statefulset simple-opensearch-nodes-default; then
break
fi
sleep 1
done
echo "Waiting on OpenSearch StatefulSet ..."
# tag::await-cluster[]
kubectl rollout status --watch statefulset/simple-opensearch-nodes-default --timeout 600s
# end::await-cluster[]
# wait a bit for the port to open
sleep 10
echo "Starting port-forwarding of port 9200"
# tag::port-forwarding[]
kubectl port-forward services/simple-opensearch 9200 > /dev/null 2>&1 &
# end::port-forwarding[]
PORT_FORWARD_PID=$!
# shellcheck disable=2064 # we want the PID evaluated now, not at the time the trap is
trap "kill $PORT_FORWARD_PID" EXIT
sleep 5
echo "Using the REST API"
# tag::rest-api[]
export CREDENTIALS=admin:AJVFsGJBbpT6mChn
curl \
--insecure \
--user $CREDENTIALS \
--request PUT \
--json '{"name": "Stackable"}' \
https://localhost:9200/sample_index/_doc/1
# Output:
# {"_index":"sample_index","_id":"1","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":0,"_primary_term":1}
curl \
--insecure \
--user $CREDENTIALS \
--request GET \
https://localhost:9200/sample_index/_doc/1
# Output:
# {"_index":"sample_index","_id":"1","_version":1,"_seq_no":0,"_primary_term":1,"found":true,"_source":{"name": "Stackable"}}
# end::rest-api[]