This repository has been archived by the owner on Nov 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlogshipper-test.sh
executable file
·180 lines (156 loc) · 5.05 KB
/
logshipper-test.sh
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/bin/bash
set -eu
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
REPO_DIR=${REPO_DIR:-$SCRIPT_DIR/couchbase-operator}
CONFIG_DIR=$(mktemp -d)
CLUSTER_NAME=${CLUSTER:-logshipper-test}
CLUSTER_CONFIG="${CONFIG_DIR}/multinode-cluster-conf.yaml"
SKIP_CLUSTER_CREATION=${SKIP_CLUSTER_CREATION:-no}
REBUILD_ALL=${REBUILD_ALL:-yes}
# Find the relevant git repos locally
OPERATOR_REPO_DIR=$(find $SCRIPT_DIR/../ -type d -name "couchbase-operator" -print0)
LOGSHIPPER_REPO_DIR=$(find $SCRIPT_DIR/../ -type d -name "couchbase-fluent-bit" -print0)
DOCKER_TAG=${DOCKER_TAG:-v1}
SERVER_IMAGE=${SERVER_IMAGE:-couchbase/server:6.6.1}
SERVER_COUNT=${SERVER_COUNT:-1}
if [[ "${REBUILD_ALL}" == "yes" ]]; then
echo "Full rebuild"
SKIP_CLUSTER_CREATION=no
pushd "${LOGSHIPPER_REPO_DIR}"
make clean build container
popd
pushd "${OPERATOR_REPO_DIR}"
make && make container
popd
fi
if [[ "${SKIP_CLUSTER_CREATION}" != "yes" ]]; then
echo "Recreating full cluster"
# Simple script to deal with running up a test cluster for KIND for developing logging updates for.
cat << EOF > "${CLUSTER_CONFIG}"
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
featureGates:
EphemeralContainers: true
nodes:
- role: control-plane
EOF
for i in $(seq "$SERVER_COUNT"); do
echo "Adding worker $i"
cat << EOF >> "${CLUSTER_CONFIG}"
- role: worker
EOF
done
kind delete cluster --name="${CLUSTER_NAME}" && echo "Deleted old kind cluster, creating a new one..."
kind create cluster --name="${CLUSTER_NAME}" --config="${CLUSTER_CONFIG}"
echo "$(date) waiting for cluster..."
until kubectl cluster-info; do
echo -n "."
sleep 2
done
echo -n " done"
# Check we can use the storage ok
if ! kubectl get sc standard -o yaml|grep -q "volumeBindingMode: WaitForFirstConsumer"; then
echo "Standard storage class is not lazy binding so needs manual set up"
exit 1
fi
# Ensure we have everything we need
kind load docker-image "couchbase/couchbase-operator:${DOCKER_TAG}" --name="${CLUSTER_NAME}"
kind load docker-image "couchbase/couchbase-operator-admission:${DOCKER_TAG}" --name="${CLUSTER_NAME}"
kind load docker-image "couchbase/operator-logging:${DOCKER_TAG}" --name="${CLUSTER_NAME}"
# Not strictly required but improves caching performance
docker pull "${SERVER_IMAGE}"
kind load docker-image "${SERVER_IMAGE}" --name="${CLUSTER_NAME}"
# It also slows down everything to allow the cluster to come up fully
rm -rf "${CONFIG_DIR}"
# Install CRD, DAC and operator
kubectl create -f "${OPERATOR_REPO_DIR}/example/crd.yaml"
"${OPERATOR_REPO_DIR}/build/bin/cbopcfg" create admission --image=couchbase/couchbase-operator-admission:v1 --log-level=debug
"${OPERATOR_REPO_DIR}/build/bin/cbopcfg" create operator --image=couchbase/couchbase-operator:v1 --log-level=debug
# Need to wait for operator and DAC to start up
echo "Waiting for DAC to complete..."
until kubectl rollout status deployment couchbase-operator-admission; do
echo -n "."
sleep 2
done
echo " done"
echo "Waiting for operator to complete..."
until kubectl rollout status deployment couchbase-operator; do
echo -n "."
sleep 2
done
echo " done"
# Now create a cluster using the specified config
cat << __CLUSTER_CONFIG_EOF__ | kubectl create -f -
apiVersion: v1
kind: Secret
metadata:
name: cb-example-auth
type: Opaque
data:
username: QWRtaW5pc3RyYXRvcg== # Administrator
password: cGFzc3dvcmQ= # password
---
apiVersion: couchbase.com/v2
kind: CouchbaseEphemeralBucket
metadata:
name: default
---
apiVersion: couchbase.com/v2
kind: CouchbaseCluster
metadata:
name: cb-example
spec:
logging:
server:
enabled: true
sidecar:
image: couchbase/operator-logging:${DOCKER_TAG}
audit:
enabled: true
image: "${SERVER_IMAGE}"
security:
adminSecret: cb-example-auth
buckets:
managed: true
servers:
- size: ${SERVER_COUNT}
name: all_services
services:
- data
- index
- query
- search
- eventing
- analytics
volumeMounts:
default: couchbase
volumeClaimTemplates:
- metadata:
name: couchbase
spec:
storageClassName: standard
resources:
requests:
storage: 1Gi
__CLUSTER_CONFIG_EOF__
# Wait for deployment to complete
echo "Waiting for CB to start up..."
until [[ $(kubectl get pods --field-selector=status.phase=Running --selector='app=couchbase' --no-headers 2>/dev/null |wc -l) -eq $SERVER_COUNT ]]; do
echo -n '.'
sleep 2
done
echo -n " done"
fi #SKIP_CLUSTER_CREATION
# Access REST API
echo "Waiting for REST API..."
kubectl port-forward cb-example-0000 8091 &>/dev/null &
PORT_FORWARD_PID=$!
# We need to wait for the CB server to start up and respond to REST API
until curl --silent --show-error -X GET -u Administrator:password http://localhost:8091/settings/audit &>/dev/null; do
echo -n '.'
sleep 2
done
echo -n " done"
echo "Audit settings:"
curl --silent --show-error -X GET -u Administrator:password http://localhost:8091/settings/audit | jq
kill -9 $PORT_FORWARD_PID &>/dev/null