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
/
xdcrTests.sh
executable file
·133 lines (114 loc) · 4.93 KB
/
xdcrTests.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
#!/bin/bash
# Copyright 2021 Couchbase, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Simple script to provision a Kubernetes cluster using KIND: https://kind.sigs.k8s.io/
# It then spins up a Couchbase Server cluster on it using Helm: https://helm.sh/
# To use, need Docker (or a container runtime) installed plus kubectl, KIND & Helm.
set -eu
# In case you want a different name
CLUSTER_NAME=${CLUSTER_NAME:-xdcr-test}
# The server container image to use
SERVER_IMAGE=${SERVER_IMAGE:-couchbase/server:7.0.1}
# Delete the old cluster
kind delete cluster --name="${CLUSTER_NAME}"
# Create KIND cluster with 3 worker nodes
kind create cluster --name="${CLUSTER_NAME}" --config - <<EOF
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: worker
- role: worker
- role: worker
EOF
# Speed up deployment by pre-loading the server image
docker pull "${SERVER_IMAGE}"
kind load docker-image "${SERVER_IMAGE}" --name="${CLUSTER_NAME}"
# Add Couchbase via helm chart
helm repo add couchbase https://couchbase-partners.github.io/helm-charts/ || helm repo add couchbase https://couchbase-partners.github.io/helm-charts
# Ensure we update the repo (may have added it years ago!)
helm repo update
HELM_CONFIG=$(mktemp)
cat << EOF > "${HELM_CONFIG}"
couchbaseOperator:
name: "couchbase-operator"
image:
repository: couchbase/operator
tag: 2.2.1
buckets:
default:
kind: CouchbaseBucket
target:
kind: CouchbaseBucket
cluster:
security:
password: password
image: ${SERVER_IMAGE}
xdcr:
managed: true
EOF
# Always installs the latest version, can be pinned with --version X
helm upgrade --install couchbase couchbase/couchbase-operator --values "${HELM_CONFIG}"
# Wait for deployment to complete, potentially a call to --wait may work with helm but it can be flakey
echo "Waiting for CB to start up..."
# The operator uses readiness gates to hold the containers until the cluster is actually ready to be used
until [[ $(kubectl get pods --field-selector=status.phase=Running --selector='app=couchbase' --no-headers 2>/dev/null |wc -l) -eq 3 ]]; do
echo -n '.'
sleep 2
done
echo "CB configured and ready to go"
# We have to wait for cluster start up to get the UUID to target ourselves with a replication
CLUSTER_ID=$(kubectl get cbc couchbase-couchbase-cluster -o template --template='{{.status.clusterId}}')
cat << EOF >> "${HELM_CONFIG}"
remoteClusters:
- authenticationSecret: auth-couchbase-couchbase-cluster
hostname: couchbase://couchbase-couchbase-cluster-srv.default?network=default
name: couchbase-couchbase-cluster
uuid: ${CLUSTER_ID}
EOF
helm upgrade --install couchbase couchbase/couchbase-operator --values "${HELM_CONFIG}"
# Now we need to create the replication resources
cat << EOF | kubectl apply -f -
apiVersion: couchbase.com/v2
kind: CouchbaseReplication
metadata:
name: replicate-default-to-target-buckets-in-local-cluster
spec:
bucket: default
remoteBucket: target
EOF
# Now add a remote cluster
CLUSTER2_NAMESPACE=${CLUSTER2_NAMESPACE:-test-remote}
helm upgrade --install "${CLUSTER2_NAMESPACE}" couchbase/couchbase-operator \
--set cluster.image="${SERVER_IMAGE}",cluster.servers.default.size="1",install.admissionController=false,cluster.security.password="password",buckets.target.kind="CouchbaseBucket" \
--namespace "${CLUSTER2_NAMESPACE}" --create-namespace --wait --values "${HELM_CONFIG}"
# Wait for deployment to complete, a call to --wait may work with helm but it can be flakey
echo "Waiting for Couchbase to start up..."
# The operator uses readiness gates to hold the containers until the cluster is actually ready to be used
until [[ $(kubectl get pods --namespace "${CLUSTER2_NAMESPACE}" --field-selector=status.phase=Running --selector='app=couchbase' --no-headers 2>/dev/null |wc -l) -eq 1 ]]; do
echo -n '.'
sleep 2
done
echo "Completed Couchbase deployment 2 into: $CLUSTER2_NAMESPACE"
CLUSTER_ID=$(kubectl get cbc --namespace "${CLUSTER2_NAMESPACE}" test-remote-couchbase-cluster -o template --template='{{.status.clusterId}}')
cat << EOF >> "${HELM_CONFIG}"
remoteClusters:
- authenticationSecret: auth-couchbase-couchbase-cluster
hostname: couchbase://${CLUSTER2_NAMESPACE}-couchbase-cluster-srv.${CLUSTER2_NAMESPACE}?network=default
name: ${CLUSTER2_NAMESPACE}-couchbase-cluster
uuid: ${CLUSTER_ID}
EOF
# Update the original
helm upgrade --install couchbase couchbase/couchbase-operator --values "${HELM_CONFIG}"
rm -f "${HELM_CONFIG}"