forked from meshery/meshery
-
Notifications
You must be signed in to change notification settings - Fork 1
183 lines (161 loc) · 6.72 KB
/
testadapters.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
# This workflow will be called/referenced in each of the adapters and runs in the context of adapter
name: Adapter Integration - Core
on:
workflow_call:
inputs:
expected_pods:
required: true
type: string
expected_pods_namespaces:
required: true
type: string
service_url:
required: true
type: string
deployment_url:
required: true
type: string
adapter_name:
required: true
type: string
patternfile_name:
required: true
type: string
provider: #default to local
required: false
type: string
secrets:
token:
required: true
jobs:
TestAdapter:
runs-on: ubuntu-latest
steps:
- name: Setting up minikube
uses: manusa/actions-setup-minikube@v2.4.1
with:
minikube version: 'v1.23.2'
kubernetes version: 'v1.20.7'
driver: docker
- name: Checkout Code
uses: actions/checkout@v2
# Build the image by setting appropriate environmental variables in order to access the image from minikube
- name: Build the tagged Docker image
run: |
eval $(minikube -p minikube docker-env)
docker build -t test:test .
# 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","adapters":[],"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
# Start meshery server (Assuming that this step will create the meshery namespace)
- name: Start meshery server using mesheryctl
run: |
curl -L https://git.io/meshery | PLATFORM=kubernetes bash -
sleep 20s
# Start the adapter using yamls
- name: Start adapter
run: |
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
# 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 &
- name: wait 10 sec
run: sleep 10s
# Checking meshery server logs
- name: Check meshery pod logs
run: |
podName=$(kubectl get pods -o wide -n meshery | sed -n 2p | tr -s ' ' | cut -d " " -f 1)
kubectl logs pod/$podName -n 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@v2
with:
name: patternfile
# This pattern will try to install service mesh
- name: Pattern apply (Install service mesh)
run: |
mesheryctl pattern apply -f ./${{ inputs.patternfile_name }}
# Wait for sometime to get some logs
- name: Sleep for 30 sec
run: sleep 30s
- name: Check adapter logs
run: |
podname=$(kubectl get pods -n meshery | grep ${{ inputs.adapter_name }} | tr -s ' ' | cut -d " " -f 1)
kubectl logs pod/$podname -n meshery
- name: Check meshery logs
run: |
podName=$(kubectl get pods -o wide -n meshery | sed -n 2p | tr -s ' ' | cut -d " " -f 1)
kubectl logs pod/$podName -n 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 pods have started
run: |
SECONDS=0
exitstatus=0
end=$((SECONDS+300))
podnames="${{ inputs.expected_pods }}"
nsnames="${{ inputs.expected_pods_namespaces}}"
set -f
pods=(${podnames//,/ })
ns=(${nsnames//,/ })
breakout=1
while [ $SECONDS -lt $end ]; do
for i in "${!pods[@]}"
do
podstatus=$(kubectl get pods -n ${ns[i]} | grep ${pods[i]} | tr -s ' ' | cut -d " " -f 3)
if [ "$podstatus" != "Running" ];then
breakout=0
fi
done
if [ $breakout -eq 1 ];then
break
fi
breakout=1
done
for i in "${!pods[@]}"
do
podstatus=$(kubectl get pods -n ${ns[i]} | grep ${pods[i]} | tr -s ' ' | cut -d " " -f 3)
if [ "$podstatus" = "Running" ];then
echo "Pod ${pods[i]} started in namespace ${ns[i]}"
else
echo "Pod ${pods[i]} did not start in namespace ${ns[i]} "
exitstatus=1
fi
done
exit $exitstatus