forked from kiali/kiali
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup-kind-in-ci.sh
executable file
·212 lines (178 loc) · 6.82 KB
/
setup-kind-in-ci.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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#!/bin/bash
#
# Refer to the --help output for a description of this script and its available options.
#
infomsg() {
echo "[INFO] ${1}"
}
helpmsg() {
cat <<HELP
This script will run setup a KinD cluster for testing Kiali against a real environment in CI.
Options:
-dorp|--docker-or-podman <docker|podman>
What to use when building images.
Default: docker
-iv|--istio-version <#.#.#>
The version of Istio you want to install.
This option is ignored if -ii is false.
If not specified, the latest version of Istio is installed.
Default: <the latest release>
HELP
}
# process command line arguments
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-dorp|--docker-or-podman) DORP="$2"; shift;shift; ;;
-h|--help) helpmsg; exit 1 ;;
-iv|--istio-version) ISTIO_VERSION="$2"; shift;shift; ;;
*) echo "Unknown argument: [$key]. Aborting."; helpmsg; exit 1 ;;
esac
done
# abort on any error
set -e
# set up some of our defaults
DORP="${DORP:-docker}"
# Defaults the branch to master unless it is already set
TARGET_BRANCH="${TARGET_BRANCH:-master}"
# If a specific version of Istio hasn't been provided, try and guess the right one
# based on the Kiali branch being tested (TARGET_BRANCH) and the compatibility matrices:
# https://kiali.io/docs/installation/installation-guide/prerequisites/
# https://istio.io/latest/docs/releases/supported-releases/
if [ "${TARGET_BRANCH}" == "v1.48" ]; then
ISTIO_VERSION="1.13.0"
elif [ "${TARGET_BRANCH}" == "v1.36" ]; then
ISTIO_VERSION="1.10.0"
fi
KIND_NODE_IMAGE=""
if [ "${ISTIO_VERSION}" == "1.10.0" ]; then
KIND_NODE_IMAGE="kindest/node:v1.21.10@sha256:84709f09756ba4f863769bdcabe5edafc2ada72d3c8c44d6515fc581b66b029c"
elif [ "${ISTIO_VERSION}" == "1.13.0" ]; then
KIND_NODE_IMAGE="kindest/node:v1.23.4@sha256:0e34f0d0fd448aa2f2819cfd74e99fe5793a6e4938b328f657c8e3f81ee0dfb9"
else
KIND_NODE_IMAGE="kindest/node:v1.24.4@sha256:adfaebada924a26c2c9308edd53c6e33b3d4e453782c0063dc0028bdebaddf98"
fi
# print out our settings for debug purposes
cat <<EOM
=== SETTINGS ===
DORP=$DORP
ISTIO_VERSION=$ISTIO_VERSION
KIND_NODE_IMAGE=$KIND_NODE_IMAGE
TARGET_BRANCH=$TARGET_BRANCH
=== SETTINGS ===
EOM
infomsg "Make sure everything exists"
which kubectl > /dev/null || (infomsg "kubectl executable is missing"; exit 1)
which kind > /dev/null || (infomsg "kind executable is missing"; exit 1)
which "${DORP}" > /dev/null || (infomsg "[$DORP] is not in the PATH"; exit 1)
NODE_IMAGE_LINE=""
if [ -n "${KIND_NODE_IMAGE}" ]; then
NODE_IMAGE_LINE="image: ${KIND_NODE_IMAGE}"
fi
infomsg "Kind cluster to be created with name [ci]"
cat <<EOF | kind create cluster --name ci --config -
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
${NODE_IMAGE_LINE}
- role: worker
${NODE_IMAGE_LINE}
EOF
# When a new cluster is created, kind automagically sets the kube context.
infomsg "Create Kind LoadBalancer via MetalLB"
lb_addr_range="255.70-255.84"
kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.13.5/config/manifests/metallb-native.yaml
subnet=$(${DORP} network inspect kind --format '{{(index .IPAM.Config 0).Subnet}}')
subnet_trimmed=$(echo "${subnet}" | sed -E 's/([0-9]+\.[0-9]+)\.[0-9]+\..*/\1/')
first_ip="${subnet_trimmed}.$(echo "${lb_addr_range}" | cut -d '-' -f 1)"
last_ip="${subnet_trimmed}.$(echo "${lb_addr_range}" | cut -d '-' -f 2)"
if [ -n "${ISTIO_VERSION}" ]; then
DOWNLOAD_ISTIO_VERSION_ARG="--istio-version ${ISTIO_VERSION}"
fi
infomsg "Downloading istio"
hack/istio/download-istio.sh ${DOWNLOAD_ISTIO_VERSION_ARG}
kubectl rollout status deployment controller -n metallb-system
cat <<LBCONFIGMAP | kubectl apply -f -
apiVersion: metallb.io/v1beta1
kind: IPAddressPool
metadata:
namespace: metallb-system
name: config
spec:
addresses:
- ${first_ip}-${last_ip}
LBCONFIGMAP
cat <<LBCONFIGMAP | kubectl apply -f -
apiVersion: metallb.io/v1beta1
kind: L2Advertisement
metadata:
namespace: metallb-system
name: l2config
spec:
ipAddressPools:
- config
LBCONFIGMAP
infomsg "Installing istio"
# Apparently you can't set the requests to zero for the proxy so just setting them to some really low number.
hack/istio/install-istio-via-istioctl.sh --reduce-resources true --client-exe-path "$(which kubectl)" -cn "cluster-default" -mid "mesh-default" -net "network-default"
infomsg "Pushing the images into the cluster..."
make -e DORP="${DORP}" -e CLUSTER_TYPE="kind" -e KIND_NAME="ci" cluster-push-kiali
infomsg "Cloning kiali helm-charts..."
git clone --single-branch --branch "${TARGET_BRANCH}" https://github.com/kiali/helm-charts.git helm-charts
make -C helm-charts build-helm-charts
infomsg "Installing kiali server via Helm"
# The grafana and tracing urls need to be set for backend e2e tests
# but they don't need to be accessible outside the cluster.
# Need a single dashboard set for grafana.
helm install \
--namespace istio-system \
--set auth.strategy="anonymous" \
--set deployment.logger.log_level="trace" \
--set deployment.service_type="LoadBalancer" \
--set deployment.image_name=kiali/kiali \
--set deployment.image_version=dev \
--set deployment.image_pull_policy="Never" \
--set external_services.grafana.url="http://grafana.istio-system:3000" \
--set external_services.grafana.dashboards[0].name="Istio Mesh Dashboard" \
--set external_services.tracing.url="http://tracing.istio-system:16685/jaeger" \
--set health_config.rate[0].kind="service" \
--set health_config.rate[0].name="y-server" \
--set health_config.rate[0].namespace="alpha" \
--set health_config.rate[0].tolerance[0].code="5xx" \
--set health_config.rate[0].tolerance[0].degraded=2 \
--set health_config.rate[0].tolerance[0].failure=100 \
kiali-server \
helm-charts/_output/charts/kiali-server-*-SNAPSHOT.tgz
# Unfortunately kubectl rollout status fails if the resource does not exist yet.
for (( i=1; i<=60; i++ ))
do
PODS=$(kubectl get pods -l app=kiali -n istio-system -o name)
if [ "${PODS}" != "" ]; then
infomsg "Kiali pods exist"
break
fi
infomsg "Waiting for kiali pod to exist"
sleep 5
done
# Checking pod status in a loop gives us more debug info on the state of the pod.
TIMEOUT="True"
for (( i=1; i<=30; i++ ))
do
READY=$(kubectl get pods -l app=kiali -n istio-system -o jsonpath='{.items[0].status.conditions[?(@.type=="Ready")].status}')
if [ "${READY}" == "True" ]; then
infomsg "Kiali finished rolling out successfully"
TIMEOUT="False"
break
fi
infomsg "Waiting for kiali pod to be ready"
infomsg "Kiali pod status:"
# Show status info of kiali pod. yq is used to parse out just the status info.
kubectl get pods -l app=kiali -n istio-system -o yaml | yq '.items[0].status'
sleep 10
done
if [ "${TIMEOUT}" == "True" ]; then
infomsg "Timed out waiting for kiali pods to be ready"
exit 1
fi
infomsg "Kiali is ready."