forked from meshery/meshery
-
Notifications
You must be signed in to change notification settings - Fork 0
273 lines (262 loc) · 11.1 KB
/
test_adaptersv2.yaml
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
# This workflow will be called/referenced in each of the adapters and runs in the context of adapter
name: Adapter Integration - Core v2
on:
workflow_call:
inputs:
expected_resources:
required: true
type: string
expected_resources_types:
required: true
type: string
expected_resources_namespaces:
required: true
type: string
service_url:
required: false
type: string
deployment_url:
required: false
type: string
adapter_name:
required: false
type: string
default: meshery
patternfile_name:
required: true
type: string
k8s_cni:
required: false
type: string
default: "bridge"
k8s_version:
required: false
type: string
sm_version:
required: false
type: string
output_filename:
required: true
type: string
adapter_version:
required: false
type: string
provider: #default to local
required: false
type: string
secrets:
token:
required: true
jobs:
TestAdapter:
strategy:
fail-fast: false
matrix:
k8s_version: ["v1.21.5", "v1.22.2", "v1.23.9", "v1.25.2"]
runs-on: ubuntu-22.04
outputs:
exitstatus: ${{ steps.runresources.outputs.exitstatus }}
steps:
- name: Set adapter_name for output
id: adapter_name
run: |
USER_INPUT=${{ github.event.inputs.adapter_name }}
echo "value=${USER_INPUT:-"meshery"}" >> $GITHUB_OUTPUT
- name: Setting up minikube
id: setk8s
uses: manusa/[email protected]
with:
minikube version: "v1.28.0"
kubernetes version: "${{ matrix.k8s_version }}"
driver: docker
start args: --cni "${{ inputs.k8s_cni }}"
- name: Checkout Code
uses: actions/checkout@master
# Build the image by setting appropriate environmental variables in order to access the image from minikube
- name: Build the tagged Docker image
run: |
if [ "${{ inputs.adapter_name }}" != "meshery" ];then
eval $(minikube -p minikube docker-env)
docker build -t test:test .
else
eval $(minikube -p minikube docker-env)
docker build -f install/docker/Dockerfile -t test:test .
fi
- name: Retrieve kubeconfig
run: |
echo "Before flattening"
cat ~/.kube/config
kubectl config view --minify --flatten > ~/.kube/configtemp
mv ~/.kube/configtemp ~/.kube/config
echo "After flattening"
cat ~/.kube/config
# Setup meshery config.yaml and auth.json
- name: Setup meshery config and infinite token for use
env:
provider_token: ${{ secrets.token }}
run: |
echo $provider_token
mkdir ~/.meshery
config='{"contexts":{"local":{"endpoint":"http://localhost:9081","token":"default","platform":"kubernetes","components":[],"channel":"stable","version":"latest"}},"current-context":"local","tokens":[{"location":"auth.json","name":"default"}]}'
echo $config > ~/.meshery/config.yaml
cat ~/.meshery/config.yaml
echo "Using provider: ${{ inputs.provider }}"
if [ "${{ inputs.provider }}" = "Meshery" ] && [ "$provider_token" != "" ] ;then
echo '{ "meshery-provider": "Meshery", "token": null }' | jq -c '.token = "'$provider_token'"' > ~/.meshery/auth.json
else
echo '{ "meshery-provider": "None", "token": "" }' > ~/.meshery/auth.json
fi
cat ~/.meshery/auth.json
- name: Cluster info for debugging before starting Meshery
run: kubectl get all -A
# Start Meshery Server (Assuming that this step will create the meshery namespace)
- name: Start Meshery Server using mesheryctl
run: |
curl -L https://meshery.io/install | PLATFORM=kubernetes bash -
# Start the adapter using yamls
- name: Start adapter
run: |
if [ "${{ inputs.adapter_name }}" != "meshery" ];then
touch testimagedep.yaml
curl ${{ inputs.deployment_url }} > ./testimagedep.yaml
yq e -i '.spec.template.spec.containers[0].image="test:test"' ./testimagedep.yaml
yq e -i '.spec.template.spec.containers[0].imagePullPolicy="Never"' ./testimagedep.yaml
cat testimagedep.yaml
kubectl apply -f testimagedep.yaml --namespace=meshery
kubectl apply -f ${{ inputs.service_url }} --namespace=meshery
fi
# Start tunnelling to allocate external IP to LoadBalancer type service(meshery)(SO that we can access meshery from outside)
- name: Start tunelling
run: minikube tunnel &> /dev/null &
# Checking meshery server logs
- name: Check Meshery pod logs
run: |
SECONDS=0
end=$((SECONDS+300))
while [ $SECONDS -lt $end ]; do
status=$(mesheryctl system status -v | sed -n 2p | sed -e "s/[[:space:]]\+/ /g" | cut -d " " -f 3)
if [ "$status" = "Running" ];then
break
fi
done
mesheryctl system logs meshery
# If external IP has not been allotted then server is unreachable, exit here in that case
- name: Check if Meshery has been allotted external IP
run: |
svcstatus=$(kubectl get svc -n meshery| grep meshery | tr -s ' ' | cut -d " " -f 4)
echo $svcstatus
if [ "$svcstatus" = "<pending>" ];then
exit 1
fi
# Reset meshery's address to the external IP in config.yaml such that mesheryctl can reach it
- name: Reset Meshery address
run: |
kubectl get svc -n meshery
svcip="http://$(kubectl get svc -n meshery | grep "meshery " | tr -s ' ' | cut -d " " -f 3):9081"
echo "this is $svcip"
config='{"contexts":{"local":{"endpoint":'$svcip',"token":"default","platform":"kubernetes","adapters":[],"channel":"stable","version":"latest"}},"current-context":"local","tokens":[{"location":"auth.json","name":"default"}]}'
echo $config > ~/.meshery/config.yaml
- name: Download patternfile
uses: actions/download-artifact@v3
with:
name: patternfile
- name: Wait for Meshery pods to come up
run: sleep 100
# This pattern will try to install service mesh(the first attempt can fail currently fot k8s componets so we will wait 100 seconds after the first apply and then apply again. Since pattern apply is idempotent, this wont be an issue.)
- name: Pattern apply
run: |
cat ./${{ inputs.patternfile_name }}
mesheryctl pattern apply -f ./${{ inputs.patternfile_name }}
- name: Sleep 120 seconds
run: sleep 120
- name: Pattern apply, second iteration. [IDEMPOTENT]
run: |
cat ./${{ inputs.patternfile_name }}
mesheryctl pattern apply -f ./${{ inputs.patternfile_name }}
- name: Check adapter logs
run: |
if [ "${{ inputs.adapter_name }}" != "meshery" ];then
podname=$(kubectl get pods -n meshery | grep ${{ inputs.adapter_name }} | tr -s ' ' | cut -d " " -f 1)
kubectl logs pod/$podname -n meshery
fi
- name: Check Meshery logs
run: |
mesheryctl system logs meshery
- name: Whole status for debugging
run: kubectl get all -A
# Check if all pods are in a Running state
- name: Check if all expected resources have started
id: runresources
run: |
SECONDS=0
exitstatus=0
end=$((SECONDS+300))
resourcenames="${{ inputs.expected_resources }}"
resourcetypes="${{ inputs.expected_resources_types }}"
nsnames="${{ inputs.expected_resources_namespaces}}"
set -f
resources=(${resourcenames//,/ })
types=(${resourcetypes//,/ })
ns=(${nsnames//,/ })
breakout=1
while [ $SECONDS -lt $end ]; do
for i in "${!resources[@]}"
do
resourceinfo=$(kubectl get ${types[i]} -n ${ns[i]} | grep ${resources[i]} | tr -s ' ')
resourcestarted=$(echo $resourceinfo | cut -d " " -f 1)
resourcestatus=$(echo $resourceinfo | cut -d " " -f 3)
if [[ ("${types[i]}" = "pod" && "$resourcestatus" != "Running") || ("${types[i]}" != "pod" && "$resourcestarted" = "") ]];then
breakout=0
fi
done
if [ $breakout -eq 1 ];then
break
fi
breakout=1
done
touch data.json
runon=$(date)
itran=0
itdidnotrun=0
echo "Ran on $runon"
echo '{"metadata":{ "k8s_version":"'${{ matrix.k8s_version }}'", "service_mesh_name":"'${{ inputs.adapter_name }}'", "service_mesh_version":"'${{ inputs.sm_version }}'","adapter_version":"'${{ inputs.adapter_version }}'" ,"runon":"'$runon'"}, "resources_status":{}, "overall-status":""}' | jq > ./data.json
for i in "${!resources[@]}"
do
resourceinfo=$(kubectl get ${types[i]} -n ${ns[i]} | grep ${resources[i]} | tr -s ' ')
resourcestarted=$(echo $resourceinfo | cut -d " " -f 1)
resourcestatus=$(echo $resourceinfo | cut -d " " -f 3)
if [[ ("${types[i]}" = "pod" && "$resourcestatus" = "Running") || ("${types[i]}" != "pod" && "$resourcestarted" != "") ]];then
itran=1
echo "${types[i]} ${resources[i]} started in namespace ${ns[i]}"
echo $(jq '.resources_status."'${types[i]}/${resources[i]}'" |= "Running"' data.json) > data.json
else
itdidnotrun=1
echo "${types[i]} ${resources[i]} did not start in namespace ${ns[i]} "
echo $(jq '.resources_status."'${types[i]}/${resources[i]}'" |= "Not Running"' data.json) > data.json
exitstatus=1
fi
done
status=""
if [ "$exitstatus" -eq 0 ];then
status="passing"
else
status="failing"
fi
if [ "$itran" -eq 1 ] && [ "$itdidnotrun" -eq 1 ] ;then
status="partial"
fi
echo $(jq '."overall-status" |= "'$status'"' data.json) > data.json;
MESHERY_VERSION=$(curl -L -s https://github.com/meshery/meshery/releases/latest | grep "/releases/tag/" | head -1 | awk -F '"' '{print $4}' | awk -F '/' '{print $NF}' )
echo $(jq '.metadata."meshery-server-version" |="'$MESHERY_VERSION'"' data.json ) > data.json
echo "exitstatus=$exitstatus" >> $GITHUB_ENV
- name: UploadResults
uses: actions/upload-artifact@v3
with:
name: ${{ inputs.output_filename }}
path: ./${{ inputs.output_filename }}
continue-on-error: true
- name: exit
run: |
if [ "$exitstatus" -eq 1 ];then
exit 1
fi