Skip to content

Commit

Permalink
Merge pull request #1167 from ksatchit/v1.0.x-ramp-time-support
Browse files Browse the repository at this point in the history
[Cherry pick for patch release 1.0.1]
  • Loading branch information
Chandan Kumar authored Jan 25, 2020
2 parents 00949a1 + 417b354 commit ae7b43a
Show file tree
Hide file tree
Showing 65 changed files with 435 additions and 208 deletions.
27 changes: 26 additions & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,33 @@ Test Litmus Playbook Syntax:
script:
- sudo docker run litmuschaos/ansible-runner:ci ./syntax-check

baseline-image:

when: always
stage: baseline
tags:
- test
only:
refs:
- /^(v[0-9][.][0-9][.]x|master)?$/
script:
- pwd
- export BRANCH=${CI_COMMIT_REF_NAME}
- echo $BRANCH
- export COMMIT=${CI_COMMIT_SHORT_SHA}
- echo $COMMIT
- git clone https://github.com/litmuschaos/litmus-e2e.git
- cd litmus-e2e
- git checkout ${BASELINE_BRANCH}
- cd baseline
- ansible-playbook commit-writer.yml --extra-vars "branch=$BRANCH repo=$CI_PROJECT_NAME commit=$COMMIT"
- git status
- git add baseline
- git status
- git commit -m "updated $CI_PROJECT_NAME commit:$COMMIT"
- git push http://${YOUR_USERNAME}:${PERSONAL_ACCESS_TOKEN}@github.com/litmuschaos/litmus-e2e.git --all

Push Litmus Image:
stage: litmusImagePush
script:
- REPONAME="litmuschaos" IMGNAME="ansible-runner" IMGTAG="ci" ./hack/push

Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
apiVersion: extensions/apps/v1
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: containerd-chaos
spec:
selector:
matchLabels:
app: crictl
template:
metadata:
labels:
Expand Down
62 changes: 40 additions & 22 deletions chaoslib/litmus/container_kill/containerd_chaos/crictl-chaos.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
---
- name: Patch the chaoslib image
template:
src: /chaoslib/litmus/container_kill/containerd_chaos/containerd.j2
dest: /chaoslib/litmus/container_kill/containerd_chaos/containerd-chaos-ds.yml
vars:
containerd_image: "{{ lib_image }}"

- block:

- name: Patch the chaoslib image
template:
src: /chaoslib/litmus/container_kill/containerd_chaos/containerd.j2
dest: /chaoslib/litmus/container_kill/containerd_chaos/containerd-chaos-ds.yml
vars:
containerd_image: "{{ lib_image }}"

- name: Setup containerd chaos infrastructure.
shell: >
kubectl apply -f /chaoslib/litmus/container_kill/containerd_chaos/containerd-chaos-ds.yml
-n {{ namespace }}
args:
executable: /bin/bash
register: result
register: crictl_ds_result

- name: Confirm that the containerd-chaos ds is running on all nodes.
shell: >
Expand Down Expand Up @@ -131,27 +131,45 @@
delay: 3
retries: 30

when: action == "killapp"

- block:

- name: Delete the crictl-chaos daemonset
shell: >
kubectl delete -f /chaoslib/litmus/container_kill/containerd_chaos/containerd-chaos-ds.yml
-n {{ namespace }}
kubectl delete -f /chaoslib/litmus/container_kill/containerd_chaos/containerd-chaos-ds.yml -n {{ namespace }}
args:
executable: /bin/bash
register: result


- name: Confirm that the containerd-chaos pod is deleted successfully
shell: >
kubectl get pod -l app=crictl
--no-headers -n {{ namespace }}
kubectl get pods -l app=crictl --no-headers -n {{ namespace }}
args:
executable: /bin/bash
register: result
until: "result.stdout == ''"
delay: 3
retries: 50
until: "'No resources found' in result.stderr"
delay: 5
retries: 60


when: action == "delete-containerd"
rescue:

- block:

- name: Delete the crictl-chaos daemonset
shell: >
kubectl delete -f /chaoslib/litmus/container_kill/containerd_chaos/containerd-chaos-ds.yml -n {{ namespace }}
args:
executable: /bin/bash
when: crictl_ds_result.rc == 0

- name: Confirm that the containerd-chaos pod is deleted successfully
shell: >
kubectl get pods -l app=crictl --no-headers -n {{ namespace }}
args:
executable: /bin/bash
register: result
until: "'No resources found' in result.stderr"
delay: 5
retries: 60
when: " crictl_ds_result is defined"

- fail:
msg: "crictl-chaos lib failed"
when: true
4 changes: 4 additions & 0 deletions chaoslib/litmus/cordon_drain_node.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
- block:

- name: Wait for the specified ramp time before injecting chaos
wait_for: timeout="{{ ramp_time }}"
when: "ramp_time is defined and ramp_time != ''"

- name: Drain the application node
shell: >
kubectl drain {{ app_node }}
Expand Down
4 changes: 4 additions & 0 deletions chaoslib/litmus/cpu_hog/app_cpu_stress.j2
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ spec:
## default: 1
- name: CORES
value: "{{ c_cores }}"
{% if ramp_time is defined and ramp_time != '' %}
- name: RAMP_TIME
value: "{{ ramp_time }}"
{% endif %}
volumeMounts:
- name: dockersocket
mountPath: /var/run/docker.sock
Expand Down
18 changes: 15 additions & 3 deletions chaoslib/litmus/cpu_hog/pod_cpu_hog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,20 @@
executable: /bin/bash
register: cpu_app_deploy_result

- name: Calculate the total wait time for cpu stress job
## considering duration in milliseconds from spec
## with a grace period of 2 min before cpu stress job terminate
set_fact:
job_wait_time: "{{ ((c_duration|int)/1000 + 120)| int }}"
when: "ramp_time is not defined or ramp_time == ''"

- name: Calculate the total wait time for cpu stress job
## considering duration in milliseconds from spec
## with a grace period of 2 min before cpu stress job terminate
set_fact:
job_wait_time: "{{ ((c_duration|int)/1000 + (ramp_time|int) + 120)| int }}"
when: "ramp_time is defined and ramp_time != ''"

- name: Wait until the cpu stress job is completed
shell: >
kubectl get pods -l job-name=app-cpu-stress-{{ run_id }} --no-headers -n {{ app_ns }}
Expand All @@ -96,9 +110,7 @@
register: result
until: "result.stdout == 'Succeeded'"
delay: 1
## considering duration in milliseconds from spec
## with a grace period of 1 min before cpu stress job terminate
retries: "{{ ((c_duration|int)/1000 + 120)| int }}"
retries: "{{ job_wait_time }}"

- name: Tear down cpu chaos infrastructure
shell: >
Expand Down
4 changes: 4 additions & 0 deletions chaoslib/litmus/disk_fill/disk_fill_by_litmus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@
app_ns: "{{ a_ns }}"
delay: 1
retries: 60

- name: Wait for the specified ramp time before injecting chaos
wait_for: timeout="{{ ramp_time }}"
when: "ramp_time is defined and ramp_time != ''"

- name: Record the disk-fill pod on app node
shell: >
Expand Down
4 changes: 4 additions & 0 deletions chaoslib/litmus/platform/aws/disk_loss.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
- name: Wait for the specified ramp time before injecting chaos
wait_for: timeout="{{ ramp_time }}"
when: "ramp_time is defined and ramp_time != ''"

- name: Detaching the disk
ec2_vol:
id: "{{ disk_name }}"
Expand Down
6 changes: 5 additions & 1 deletion chaoslib/litmus/platform/gke/disk_loss.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
- name: Wait for the specified ramp time before injecting chaos
wait_for: timeout="{{ ramp_time }}"
when: "ramp_time is defined and ramp_time != ''"

- name: Detaching the disk
shell: gcloud compute instances detach-disk {{ node_name }} --disk {{ disk_name }} --zone {{ zone_name }}

Expand All @@ -11,4 +15,4 @@
- block:
- name: If disk is not attached, it will attach manually
shell: gcloud compute instances attach-disk {{ node_name }} --device-name {{ disk_name }} --disk {{ disk_name }} --zone {{ zone_name }}
when: "inuse == false"
when: "inuse == false"
4 changes: 4 additions & 0 deletions chaoslib/litmus/platform/gke/pod_cpu_consumption.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
- set_fact:
pod_ds_app: "{{ po_ds_app | json_query('resources[0].metadata.name') }}"

- name: Wait for the specified ramp time before injecting chaos
wait_for: timeout="{{ ramp_time }}"
when: "ramp_time is defined and ramp_time != ''"

## GETTING THE NODE CPU CAPACITY
- name: Getting the node cpu capacity
k8s_facts:
Expand Down
8 changes: 6 additions & 2 deletions chaoslib/litmus/pod_failure_by_litmus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@
- name: Set min chaos count to 1 if interval > duration
set_fact:
c_iterations: 1
when: "c_iterations == '0'"
when: "c_iterations == '0'"

- name: Wait for the specified ramp time before injecting chaos
wait_for: timeout="{{ ramp_time }}"
when: "ramp_time is defined and ramp_time != ''"

- name: Kill random pod
include: kill_random_pod.yml
with_sequence: start=1 end={{ c_iterations }}


6 changes: 5 additions & 1 deletion chaoslib/powerfulseal/pod_failure_by_powerfulseal.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
- block:

- name: Wait for the specified ramp time before injecting chaos
wait_for: timeout="{{ ramp_time }}"
when: "ramp_time is defined and ramp_time != ''"

- name: Generate the powerfulseal deployment spec from template
template:
Expand All @@ -24,7 +28,7 @@
retries: 90

- name: Wait for chaos duration
wait_for: timeout={{ c_duration }}
wait_for: timeout="{{ c_duration }}"

- name: Tear down the powerfulseal deployment
shell:
Expand Down
7 changes: 7 additions & 0 deletions chaoslib/pumba/network_chaos/network_chaos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@
c_container: "{{ container.stdout }}"

when: c_container is not defined or c_container == ''

- name: Wait for the specified ramp time before injecting chaos
## the ramp_time is spent before launching the pumba job instead
## of in the pumba job, as with the new scratch-based pumba images
## there is no shell available by default
wait_for: timeout="{{ ramp_time }}"
when: "ramp_time is defined and ramp_time != ''"

- name: Patch the chaoslib image
template:
Expand Down
Loading

0 comments on commit ae7b43a

Please sign in to comment.