-
Notifications
You must be signed in to change notification settings - Fork 27
298 lines (261 loc) · 11.6 KB
/
aws-experiment-pipeline.yml
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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
---
name: AWS-Experiment-Pipeline
on:
workflow_dispatch:
inputs:
experimentImage:
default: "litmuschaos/go-runner:ci"
operatorImage:
default: "litmuschaos/chaos-operator:ci"
runnerImage:
default: "litmuschaos/chaos-runner:ci"
chaosNamespace:
default: "default"
experimentImagePullPolicy:
default: "Always"
jobs:
AWS_EC2_Terminate_By_ID_And_Tag:
runs-on: ubuntu-latest
env:
KUBECONFIG: /etc/rancher/k3s/k3s.yaml
steps:
#Install and configure a k3s cluster
- name: Installing Prerequisites (K3S Cluster)
env:
KUBECONFIG: /etc/rancher/k3s/k3s.yaml
run: |
curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION=v1.21.11+k3s1 sh -s - --docker --write-kubeconfig-mode 664
kubectl wait node --all --for condition=ready --timeout=90s
mkdir -p $HOME/.kube && cat /etc/rancher/k3s/k3s.yaml > $HOME/.kube/config
kubectl get nodes
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: '1.16'
- name: Create Kubernetes secret for aws experiment
if: always()
run: |
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Secret
metadata:
name: cloud-secret
namespace: default
type: Opaque
stringData:
cloud_config.yml: |-
[default]
aws_access_key_id = ${{ secrets.AWS_ACCESS_KEY_ID }}
aws_secret_access_key = ${{ secrets.AWS_SECRET_ACCESS_KEY }}
EOF
- name: Configure AWS Credentials
if: always()
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
# aws-session-token: ${{ secrets.AWS_SESSION_TOKEN }} # if you have/need it
aws-region: ${{ secrets.REGION }}
- name: Creating target EC2 instances
if: always()
run: |
aws ec2 run-instances \
--image-id ami-0d382e80be7ffdae5 \
--count 2 --instance-type t2.small \
--key-name ${{ secrets.KEY_NAME }} \
--security-group-ids ${{ secrets.SECURITY_GROUP_ID }} \
--subnet-id ${{ secrets.SUBNET_ID }} \
--region ${{ secrets.REGION }} \
--tag-specifications 'ResourceType=instance,Tags=[{Key=runNumber,Value=ec2_${{ github.run_number }}}]'
- name: Get the target instance name
if: always()
run: |
instances=$(aws ec2 describe-instances --filters Name=tag-value,Values=ec2_${{ github.run_number }} Name=instance-state-name,Values=pending,running --region ${{ secrets.REGION }} --query 'Reservations[*].Instances[*].{Instance:InstanceId}' --output text)
instance_list=($instances)
echo "inst1: ${instance_list[0]} inst2: ${instance_list[1]}"
echo "INSTANCE_ONE=${instance_list[0]}" >> $GITHUB_ENV
echo "INSTANCE_TWO=${instance_list[1]}" >> $GITHUB_ENV
- name: Litmus Infra Setup
if: always()
run: make build-litmus
env:
OPERATOR_IMAGE: "${{ github.event.inputs.operatorImage }}"
RUNNER_IMAGE: "${{ github.event.inputs.runnerImage }}"
- name: Run EC2 Terminate By ID experiment in serial & parallel mode
if: always()
env:
EC2_INSTANCE_ID: "${{ env.INSTANCE_ONE }},${{ env.INSTANCE_TWO }}"
REGION: ${{ secrets.REGION }}
EXPERIMENT_IMAGE: "${{ github.event.inputs.experimentImage }}"
EXPERIMENT_IMAGE_PULL_POLICY: "${{ github.event.inputs.experimentImagePullPolicy }}"
CHAOS_NAMESPACE: "${{ github.event.inputs.chaosNamespace }}"
run: make ec2-terminate-by-id
- name: Run EC2 Terminate By Tag experiment in serial & parallel mode
if: always()
env:
EC2_INSTANCE_TAG: "runNumber:ec2_${{ github.run_number }}"
REGION: ${{ secrets.REGION }}
EXPERIMENT_IMAGE: "${{ github.event.inputs.experimentImage }}"
EXPERIMENT_IMAGE_PULL_POLICY: "${{ github.event.inputs.experimentImagePullPolicy }}"
CHAOS_NAMESPACE: "${{ github.event.inputs.chaosNamespace }}"
run: make ec2-terminate-by-tag
- name: Terminate target EC2 instances
if: always()
run: |
aws ec2 terminate-instances --instance-ids ${{ env.INSTANCE_ONE }} ${{ env.INSTANCE_TWO }}
- name: "[Debug]: check chaos resources"
if: ${{ failure() }}
continue-on-error: true
run: |
bash <(curl -s https://raw.githubusercontent.com/litmuschaos/litmus-e2e/master/build/debug.sh)
- name: "[Debug]: check operator logs"
if: ${{ failure() }}
continue-on-error: true
run: |
operator_name=$(kubectl get pods -n litmus -l app.kubernetes.io/component=operator --no-headers | awk '{print$1}')
kubectl logs $operator_name -n litmus > logs.txt
cat logs.txt
- name: Litmus Cleanup
if: ${{ always() }}
run: make litmus-cleanup
- name: Deleting K3S cluster
if: always()
run: /usr/local/bin/k3s-uninstall.sh
AWS_EBS_Loss_By_ID_And_Tag:
runs-on: ubuntu-latest
env:
KUBECONFIG: /etc/rancher/k3s/k3s.yaml
needs: AWS_EC2_Terminate_By_ID_And_Tag
steps:
#Install and configure a k3s cluster
- name: Installing Prerequisites (K3S Cluster)
run: |
curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION=v1.21.11+k3s1 sh -s - --docker --write-kubeconfig-mode 664
kubectl wait node --all --for condition=ready --timeout=90s
mkdir -p $HOME/.kube && cat /etc/rancher/k3s/k3s.yaml > $HOME/.kube/config
kubectl get nodes
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: '1.16'
- name: Create Kubernetes secret for aws experiment
if: always()
run: |
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Secret
metadata:
name: cloud-secret
namespace: default
type: Opaque
stringData:
cloud_config.yml: |-
[default]
aws_access_key_id = ${{ secrets.AWS_ACCESS_KEY_ID }}
aws_secret_access_key = ${{ secrets.AWS_SECRET_ACCESS_KEY }}
EOF
- name: Configure AWS Credentials
if: always()
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
# aws-session-token: ${{ secrets.AWS_SESSION_TOKEN }} # if you have/need it
aws-region: ${{ secrets.REGION }}
- name: Creating EC2 instances
if: always()
run: |
aws ec2 run-instances \
--image-id ami-0d382e80be7ffdae5 \
--count 1 \
--instance-type t2.small \
--key-name ${{ secrets.KEY_NAME }} \
--security-group-ids ${{ secrets.SECURITY_GROUP_ID }} \
--subnet-id ${{ secrets.SUBNET_ID }} \
--placement AvailabilityZone=${{ secrets.AVAILABILITY_ZONE }} \
--region ${{ secrets.REGION }} \
--tag-specifications 'ResourceType=instance,Tags=[{Key=runNumber,Value=ebs_${{ github.run_number }}}]'
- name: Create EBS volumes
if: always()
run: |
aws ec2 create-volume \
--volume-type gp2 \
--size 4 \
--availability-zone ${{ secrets.AVAILABILITY_ZONE }} \
--region ${{ secrets.REGION }} \
--tag-specifications 'ResourceType=volume,Tags=[{Key=runNumber,Value=ebs_${{ github.run_number }}}]'
- name: Get the EC2 instance ID
if: always()
run: |
instances=$(aws ec2 describe-instances --filters Name=tag-value,Values=ebs_${{ github.run_number }} Name=instance-state-name,Values=pending,running --region ${{ secrets.REGION }} --query 'Reservations[*].Instances[*].{Instance:InstanceId}' --output text)
instance_list=($instances)
echo "INSTANCE_ONE=${instance_list[0]}" >> $GITHUB_ENV
- name: Get the EBS volume ID
run: |
volumes=$(aws ec2 describe-volumes --filters Name=tag-value,Values=ebs_${{ github.run_number }} Name=availability-zone,Values=${{ secrets.AVAILABILITY_ZONE }} --query "Volumes[*].{ID:VolumeId}" --output text)
echo "VOLUME_ID=${volumes}" >> $GITHUB_ENV
- name: Litmus Infra Setup
if: always()
run: make build-litmus
env:
OPERATOR_IMAGE: "${{ github.event.inputs.operatorImage }}"
RUNNER_IMAGE: "${{ github.event.inputs.runnerImage }}"
- name: Attach the target EBS volume to the EC2 instance
if: always()
run: aws ec2 attach-volume --volume-id ${{ env.VOLUME_ID }} --instance-id ${{ env.INSTANCE_ONE }} --device /dev/sdf
- name: Run EBS Loss By ID experiment in serial & parallel mode
if: always()
env:
EBS_VOLUME_ID: "${{ env.VOLUME_ID }}"
REGION: ${{ secrets.REGION }}
EXPERIMENT_IMAGE: "${{ github.event.inputs.experimentImage }}"
EXPERIMENT_IMAGE_PULL_POLICY: "${{ github.event.inputs.experimentImagePullPolicy }}"
CHAOS_NAMESPACE: "${{ github.event.inputs.chaosNamespace }}"
run: make ebs-loss-by-id
- name: Run EBS Loss By Tag experiment in serial & parallel mode
if: always()
env:
EBS_VOLUME_TAG: "runNumber:ebs_${{ github.run_number }}"
REGION: ${{ secrets.REGION }}
EXPERIMENT_IMAGE: "${{ github.event.inputs.experimentImage }}"
EXPERIMENT_IMAGE_PULL_POLICY: "${{ github.event.inputs.experimentImagePullPolicy }}"
CHAOS_NAMESPACE: "${{ github.event.inputs.chaosNamespace }}"
run: make ebs-loss-by-tag
- name: Terminate EC2 instance
if: always()
run: |
aws ec2 terminate-instances --instance-ids ${{ env.INSTANCE_ONE }} --region ${{ secrets.REGION }}
- name: Waiting for EBS volume to be available
if: always()
run: |
for i in range {0..30};do
volume_status="$(aws ec2 describe-volumes --volume-ids ${{ env.VOLUME_ID }} --query 'Volumes[*].State' --output text)"
echo "ec2 instance status is: ${instance_status}"
if [ "$volume_status" == "available" ];then
echo "The volume is available"
break
fi
sleep 2
done
- name: Delete EBS Volume
if: always()
run: |
aws ec2 delete-volume --volume-id "${{ env.VOLUME_ID }}" --region ${{ secrets.REGION }}
- name: "[Debug]: check chaos resources"
if: ${{ failure() }}
continue-on-error: true
run: |
bash <(curl -s https://raw.githubusercontent.com/litmuschaos/litmus-e2e/master/build/debug.sh)
- name: "[Debug]: check operator logs"
if: ${{ failure() }}
continue-on-error: true
run: |
operator_name=$(kubectl get pods -n litmus -l app.kubernetes.io/component=operator --no-headers | awk '{print$1}')
kubectl logs $operator_name -n litmus > logs.txt
cat logs.txt
- name: Litmus Cleanup
if: ${{ always() }}
run: make litmus-cleanup
- name: Deleting K3S cluster
if: always()
run: /usr/local/bin/k3s-uninstall.sh