-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathtest.sh
executable file
·227 lines (176 loc) · 7 KB
/
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
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#!/bin/bash
set -e -o pipefail
norm=$(tput sgr0) || true
red=$(tput setaf 1) || true
green=$(tput setaf 2) || true
yellow=$(tput setaf 3) || true
bold=$(tput bold) || true
timestamp() {
date -u "+[%Y-%m-%dT%H:%M:%SZ]"
}
log-info() {
echo "${bold}$(timestamp) $*${norm}"
}
log-good() {
echo "${green}$(timestamp) $*${norm}"
}
fail-now() {
echo "${red}$(timestamp) $*${norm}" 2>&1
exit 1
}
DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
cd "$DIR"
cleanup() {
if [[ "$1" -ne 0 ]]; then
cat <<EOF >>"$GITHUB_STEP_SUMMARY"
### Describe Pods Cluster 1
\`\`\`
$(./cluster1 kubectl describe pods -n "spire-system")
\`\`\`
### Logs Cluster 1
\`\`\`
$(./cluster1 kubectl get pods -o name -n "spire-system" | while read -r line; do echo; echo "logs for ${line}:"; ./cluster1 kubectl logs -n "spire-system" "${line}" --prefix --all-containers=true --ignore-errors=true; done)
\`\`\`
### Describe Pods Cluster 2
\`\`\`
$(./cluster2 kubectl describe pods -n "spire-system")
\`\`\`
### Logs Cluster 2
\`\`\`
$(./cluster2 kubectl get pods -o name -n "spire-system" | while read -r line; do echo; echo logs for "${line}:"; ./cluster2 kubectl logs -n "spire-system" "${line}" --prefix --all-containers=true --ignore-errors=true; done)
\`\`\`
EOF
fi
echo "Cleaning up..."
./cluster1 kind delete cluster || true
./cluster2 kind delete cluster || true
echo "Done."
}
trap 'EC=$? && trap - SIGTERM && cleanup $EC' SIGINT SIGTERM EXIT
log-info "Tagging devel image as nightly..."
docker tag ghcr.io/spiffe/spire-controller-manager:{devel,nightly}
log-info "Building greeter server/client..."
(cd greeter; make docker-build)
log-info "Pulling docker images..."
echo ghcr.io/spiffe/spire-server:1.10.4 \
ghcr.io/spiffe/spire-agent:1.10.4 \
ghcr.io/spiffe/spiffe-csi-driver:0.2.6 \
registry.k8s.io/sig-storage/csi-node-driver-registrar:v2.12.0 \
| xargs -n1 docker pull
log-info "Creating cluster1..."
./cluster1 kind create cluster --config=config/cluster1/config.yaml
log-info "Creating cluster2..."
./cluster2 kind create cluster --config=config/cluster2/config.yaml
log-info "Loading images into cluster1..."
echo \
ghcr.io/spiffe/spire-server:1.10.4 \
ghcr.io/spiffe/spire-agent:1.10.4 \
ghcr.io/spiffe/spiffe-csi-driver:0.2.6 \
registry.k8s.io/sig-storage/csi-node-driver-registrar:v2.12.0 \
ghcr.io/spiffe/spire-controller-manager:nightly \
greeter-server:demo \
| xargs -n1 ./cluster1 kind load docker-image
log-info "Loading images into cluster2..."
echo \
ghcr.io/spiffe/spire-server:1.10.4 \
ghcr.io/spiffe/spire-agent:1.10.4 \
ghcr.io/spiffe/spiffe-csi-driver:0.2.6 \
registry.k8s.io/sig-storage/csi-node-driver-registrar:v2.12.0 \
ghcr.io/spiffe/spire-controller-manager:nightly \
greeter-client:demo \
| xargs -n1 ./cluster2 kind load docker-image
############################################################################
# Deploy SPIRE and pals
############################################################################
log-info "Applying cluster1 SPIRE config..."
./cluster1 kubectl apply -k config/cluster1
log-info "Applying cluster2 SPIRE config..."
./cluster2 kubectl apply -k config/cluster2
log-info "Waiting for SPIRE server and spire-controller-manager to deploy in cluster1..."
./cluster1 kubectl rollout status -w --timeout=30s -nspire-system deployment/spire-server
log-info "Waiting for SPIRE server and spire-controller-manager to deploy in cluster2..."
./cluster2 kubectl rollout status -w --timeout=30s -nspire-system deployment/spire-server
############################################################################
# Deploy the greeter server and client
############################################################################
log-info "Applying greeter-server config in cluster1..."
./cluster1 kubectl apply -k config/cluster1/greeter-server
log-info "Waiting for the greeter server to deploy in cluster1..."
./cluster1 kubectl rollout status -w --timeout=30s deployment/greeter-server
GREETER_SERVER_ADDR=$(./cluster1 ./scripts/get_service_ip_port.sh default greeter-server)
./cluster2 kubectl apply -f - <<EOF
apiVersion: v1
kind: ConfigMap
metadata:
name: greeter-client-config
data:
greeter-server-addr: "$GREETER_SERVER_ADDR"
EOF
log-info "Applying greeter-client config in cluster2..."
./cluster2 kubectl apply -k config/cluster2/greeter-client
log-info "Waiting for the greeter server to deploy in cluster1..."
./cluster2 kubectl rollout status -w --timeout=30s deployment/greeter-client
############################################################################
# Federate the clusters
############################################################################
log-info "Federating cluster1 with cluster2..."
./cluster1 scripts/make-cluster-federated-trust-domain.sh | \
./cluster2 kubectl apply -f -
log-info "Federating cluster2 with cluster1..."
./cluster2 scripts/make-cluster-federated-trust-domain.sh | \
./cluster1 kubectl apply -f -
############################################################################
# Configure the greeter server/client IDs
############################################################################
log-info "Configuring the greeter server ID in cluster1..."
./cluster1 kubectl apply -f config/greeter-server-id.yaml
log-info "Configuring the greeter client ID in cluster2..."
./cluster2 kubectl apply -f config/greeter-client-id.yaml
############################################################################
# Add a static entry
############################################################################
log-info "Configuring the static entry in cluster1..."
./cluster1 kubectl apply -f config/static-entry.yaml
############################################################################
# Check status
############################################################################
log-info "Checking greeter server logs for success..."
SUCCESS=
for ((i = 0; i < 30; i++)); do
if ./cluster1 kubectl logs deployment/greeter-server | grep -q spiffe://cluster2.demo/greeter-client; then
log-info "Server received request from client!"
SUCCESS=true
break
fi
sleep 1
done
if [ -z "$SUCCESS" ]; then
fail-now "Server never received request from client :("
fi
log-info "Checking greeter client logs for success..."
SUCCESS=
for ((i = 0; i < 30; i++)); do
if ./cluster2 kubectl logs deployment/greeter-client | grep -q spiffe://cluster1.demo/greeter-server; then
log-info "Client received response from server!"
SUCCESS=true
break
fi
sleep 1
done
if [ -z "$SUCCESS" ]; then
fail-now "Client never received response from server :("
fi
log-info "Checking for the static entry..."
SUCCESS=
for ((i = 0; i < 30; i++)); do
if ./cluster1 scripts/show-spire-entries.sh | grep -q static-spiffe-id; then
log-info "Static entry created in cluster1"
SUCCESS=true
break
fi
sleep 1
done
if [ -z "$SUCCESS" ]; then
fail-now "Static entry never created :("
fi
log-good "Success."