diff --git a/.bettercodehub.yml b/.bettercodehub.yml new file mode 100644 index 00000000000..a54433f696b --- /dev/null +++ b/.bettercodehub.yml @@ -0,0 +1,9 @@ +component_depth: 2 +languages: +- go +exclude: +- /build/plugins/.* +- /build/utils/.* +test: + include: + - /contribute/developer_guide/test_*\.py diff --git a/ADOPTERS.md b/ADOPTERS.md new file mode 100644 index 00000000000..3c44cd122bf --- /dev/null +++ b/ADOPTERS.md @@ -0,0 +1,2 @@ +This is the list of organizations and users that publicly shared details of how they are using LitmusChaos for running chaos experiments. +Please send PRs to add or remove organizations/users. diff --git a/README.md b/README.md index cd9164a772e..7c13fa3eb80 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ [![Twitter Follow](https://img.shields.io/twitter/follow/litmuschaos?style=social)](https://twitter.com/LitmusChaos) [![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/3202/badge)](https://bestpractices.coreinfrastructure.org/projects/3202) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=litmuschaos_litmus&metric=alert_status)](https://sonarcloud.io/dashboard?id=litmuschaos_litmus) +[![BCH compliance](https://bettercodehub.com/edge/badge/litmuschaos/litmus?branch=master)](https://bettercodehub.com/)



@@ -42,6 +43,7 @@ See Contributing to chaos hub ## Adopters +See Adopters of LitmusChaos (*Send a PR to the above page if you are using Litmus in your chaos engineering practice*) diff --git a/chaoslib/chaoskube/README.md b/chaoslib/chaoskube/README.md index 330290e1723..6f15c5266fb 100644 --- a/chaoslib/chaoskube/README.md +++ b/chaoslib/chaoskube/README.md @@ -1,3 +1,3 @@ ## Note -The chaoskube library is not supported by litmuschaos any more. It will be left here, because it can be used if the chaosServiceAccount has cluster-scope. As of version 0.8 chaosexperiments are namespace-scoped +The chaoskube library is not supported by litmuschaos any more. It will be left here, because it can be used if the chaosServiceAccount has cluster-scope. As of version 1.0 the pod-delete (and other app-level) chaosexperiments are namespace-scoped diff --git a/chaoslib/litmus/cpu_hog/pod_cpu_hog.yml b/chaoslib/litmus/cpu_hog/pod_cpu_hog.yml index f7b1b4d78e8..f4f9472ed53 100644 --- a/chaoslib/litmus/cpu_hog/pod_cpu_hog.yml +++ b/chaoslib/litmus/cpu_hog/pod_cpu_hog.yml @@ -16,7 +16,7 @@ set_fact: app_pod: "{{ app_pod_name.stdout }}" - when: "app_pod is not defined or app_pod = ''" + when: "app_pod is not defined or app_pod == ''" # here app_ns is the namespace of pod on which we are performing cpu chaos # in genric experiments app_ns is same as app_ns diff --git a/chaoslib/litmus/disk_fill/disk_fill_by_litmus.yml b/chaoslib/litmus/disk_fill/disk_fill_by_litmus.yml index da2f7661023..7a05adb1eb9 100644 --- a/chaoslib/litmus/disk_fill/disk_fill_by_litmus.yml +++ b/chaoslib/litmus/disk_fill/disk_fill_by_litmus.yml @@ -151,12 +151,12 @@ executable: /bin/bash - name: Confirm that the Disk Fill DaemonSet is deleted successfully - shell: > - kubectl get ds -l app=disk-fill --no-headers - args: - executable: /bin/bash - register: result - until: "'No resources found' in result.stderr" + k8s_facts: + kind: DaemonSet + label_selectors: + - app=disk-fill + register: resource_daemonset + until: "resource_daemonset.resources | length < 1" delay: 5 retries: 60 @@ -164,7 +164,7 @@ - block: - - name: Deleting the Cpu Hog DaemonSet + - name: Deleting the Disk-fill DaemonSet shell: > kubectl delete -f /chaoslib/litmus/disk_fill/disk_fill_ds.yaml -n {{ a_ns }} args: @@ -172,14 +172,14 @@ when: "disk_fill_ds_result.rc == 0 " - name: Confirm that the Disk Fill DaemonSet is deleted successfully - shell: > - kubectl get ds -l app=disk-fill --no-headers - args: - executable: /bin/bash - register: result - until: "'No resources found' in result.stderr" + k8s_facts: + kind: DaemonSet + label_selectors: + - app=disk-fill + register: resource_daemonset + until: "resource_daemonset.resources | length < 1" delay: 5 - retries: 60 + retries: 60 when: "disk_fill_ds_result is defined" - fail: diff --git a/chaoslib/litmus/platform/gke/pod_cpu_consumption.yml b/chaoslib/litmus/platform/gke/pod_cpu_consumption.yml index a7e7473f388..9fcd8649e95 100644 --- a/chaoslib/litmus/platform/gke/pod_cpu_consumption.yml +++ b/chaoslib/litmus/platform/gke/pod_cpu_consumption.yml @@ -86,12 +86,12 @@ executable: /bin/bash - name: Confirm that the Cpu Hog DaemonSet is deleted successfully - shell: > - kubectl get ds -l app=cpu-hog --no-headers - args: - executable: /bin/bash - register: result - until: "'No resources found' in result.stderr" + k8s_facts: + kind: DaemonSet + label_selectors: + - app=cpu-hog + register: resource_daemonset + until: "resource_daemonset.resources | length < 1" delay: 5 retries: 60 @@ -107,12 +107,12 @@ when: "cpu_hog_ds_result is succeeded" - name: Confirm that the Cpu Hog DaemonSet is deleted successfully - shell: > - kubectl get ds -l app=cpu-hog --no-headers - args: - executable: /bin/bash - register: result - until: "'No resources found' in result.stderr" + k8s_facts: + kind: DaemonSet + label_selectors: + - app=cpu-hog + register: resource_daemonset + until: "resource_daemonset.resources | length < 1" delay: 5 retries: 60 when: "cpu_hog_ds_result is defined" diff --git a/chaoslib/powerfulseal/pod_failure_by_powerfulseal.yml b/chaoslib/powerfulseal/pod_failure_by_powerfulseal.yml index 1d79792eb17..37c7930f78e 100644 --- a/chaoslib/powerfulseal/pod_failure_by_powerfulseal.yml +++ b/chaoslib/powerfulseal/pod_failure_by_powerfulseal.yml @@ -1,44 +1,72 @@ -- name: Generate the powerfulseal deployment spec from template - template: - src: /chaoslib/powerfulseal/powerfulseal.j2 - dest: powerfulseal.yml - -- name: Setup powerfulseal to initiate random pod chaos - shell: - kubectl apply -f powerfulseal.yml -n {{ a_ns }} - args: - executable: /bin/bash - register: result - failed_when: "result.rc != 0" - -- name: Confirm that powerfulseal pod is running - shell: > - kubectl get pod -l name=powerfulseal --no-headers -n {{ a_ns }} - args: - executable: /bin/bash - register: result - until: "'Running' in result.stdout" - delay: 1 - retries: 90 - -- name: Wait for chaos duration - wait_for: timeout={{ c_duration }} - -- name: Tear down the powerfulseal deployment - shell: - kubectl delete -f powerfulseal.yml -n {{ a_ns }} - args: - executable: /bin/bash - register: result - failed_when: "result.rc != 0" - -- name: Confirm that powerfulseal pod is cleaned up - shell: > - kubectl get pod -l name=powerfulseal --no-headers -n {{ a_ns }} - args: - executable: /bin/bash - register: result - until: "'Running' not in result.stdout" - delay: 1 - retries: 120 +- block: + + - name: Generate the powerfulseal deployment spec from template + template: + src: /chaoslib/powerfulseal/powerfulseal.j2 + dest: powerfulseal.yml + - name: Setup powerfulseal to initiate random pod chaos + shell: + kubectl apply -f powerfulseal.yml -n {{ app_ns }} + args: + executable: /bin/bash + register: deployment_result + failed_when: "deployment_result.rc != 0" + + - name: Confirm that powerfulseal pod is running + shell: > + kubectl get pod -l name=powerfulseal --no-headers -n {{ app_ns }} + args: + executable: /bin/bash + register: result + until: "'Running' in result.stdout" + delay: 1 + retries: 90 + + - name: Wait for chaos duration + wait_for: timeout={{ c_duration }} + + - name: Tear down the powerfulseal deployment + shell: + kubectl delete -f powerfulseal.yml -n {{ app_ns }} + args: + executable: /bin/bash + register: result + failed_when: "result.rc != 0" + + - name: Confirm that powerfulseal pod is cleaned up + k8s_facts: + kind: Deployment + label_selectors: + - name=powerfulseal + register: resource_deployment + until: "resource_deployment.resources | length < 1" + delay: 1 + retries: 120 + + rescue: + + - block: + + - name: Tear down the powerfulseal deployment + shell: > + kubectl delete -f powerfulseal.yml -n {{ app_ns }} + args: + executable: /bin/bash + when: deployment_result.rc == 0 + + - name: Confirm that powerfulseal pod is cleaned up + k8s_facts: + kind: Deployment + label_selectors: + - name=powerfulseal + register: resource_deployment + until: "resource_deployment.resources | length < 1" + delay: 1 + retries: 120 + + when: "deployment_result is defined" + + - fail: + msg: "pod_failure_by_powerfulseal lib failed" + when: true diff --git a/chaoslib/powerfulseal/powerfulseal.j2 b/chaoslib/powerfulseal/powerfulseal.j2 index 69774a3b1dc..8466ebc91d5 100644 --- a/chaoslib/powerfulseal/powerfulseal.j2 +++ b/chaoslib/powerfulseal/powerfulseal.j2 @@ -13,8 +13,8 @@ data: - name: "delete random pods in default namespace" match: - labels: - namespace: {{ a_ns }} - selector: {{ a_label }} + namespace: {{ app_ns }} + selector: {{ app_label }} filters: - randomSample: size: 1 diff --git a/executor/README.md b/executor/README.md index 7054c1741d9..26dd465d2d8 100644 --- a/executor/README.md +++ b/executor/README.md @@ -127,12 +127,8 @@ ### Limitations -- Executor is currently unable to parse more than one configmap. - - The name of file which contains data for configmap in experimentCR should be parameters.yml - The configmap is mounted in this default directory: /mnt/ -- Executor is currently unable to parse more than one secret. - - The secret is mounted in this default directory: /tmp/ diff --git a/experiments/kafka/kafka-broker-pod-failure/chaosutil.j2 b/experiments/kafka/kafka-broker-pod-failure/chaosutil.j2 index cbf537e7f41..ce5061c3a94 100644 --- a/experiments/kafka/kafka-broker-pod-failure/chaosutil.j2 +++ b/experiments/kafka/kafka-broker-pod-failure/chaosutil.j2 @@ -1,6 +1,4 @@ -{% if c_lib is defined and c_lib == 'chaoskube' %} - c_util: /chaoslib/chaoskube/pod_failure_by_chaoskube.yml -{% elif c_lib is defined and c_lib == 'powerfulseal' %} +{% if c_lib is defined and c_lib == 'powerfulseal' %} c_util: /chaoslib/powerfulseal/pod_failure_by_powerfulseal.yml {% else %} c_util: /chaoslib/litmus/pod_failure_by_litmus.yml diff --git a/experiments/kafka/kafka-broker-pod-failure/kafka-broker-pod-failure-ansible-logic.yml b/experiments/kafka/kafka-broker-pod-failure/kafka-broker-pod-failure-ansible-logic.yml index 89f07570ab0..3769c46a14b 100644 --- a/experiments/kafka/kafka-broker-pod-failure/kafka-broker-pod-failure-ansible-logic.yml +++ b/experiments/kafka/kafka-broker-pod-failure/kafka-broker-pod-failure-ansible-logic.yml @@ -8,6 +8,7 @@ c_interval: "{{ lookup('env','CHAOS_INTERVAL') }}" c_force: "{{ lookup('env','FORCE') }}" c_lib: "{{ lookup('env','LIB') }}" + c_svc_acc: "{{ lookup('env','CHAOS_SERVICE_ACCOUNT') }}" kill_count: "{{ lookup('env','KILL_COUNT') }}" kafka_instance: "{{ lookup('env','KAFKA_INSTANCE_NAME') }}" kafka_ns: "{{ lookup('env','KAFKA_NAMESPACE') }}" @@ -67,7 +68,6 @@ vars: app_ns: "{{ kafka_ns }}" app_label: "{{ kafka_label }}" - # derived from the 'kafka_broker_util' task app_pod_name: "{{ kafka_broker }}" diff --git a/sonar-project.properties b/sonar-project.properties index eb04d3a6f0e..2599c43a697 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -9,3 +9,7 @@ sonar.sources=. # Encoding of the source code. Default is default system encoding #sonar.sourceEncoding=UTF-8 + +# Exclude the ansible plugin/utils files from analysis +sonar.exclusions=build/utils/**/*,build/plugins/**/* +sonar.tests=contribute/developer_guide diff --git a/utils/apps/kafka/kafka_cluster_health.yml b/utils/apps/kafka/kafka_cluster_health.yml index 8620f831c18..426c1179537 100644 --- a/utils/apps/kafka/kafka_cluster_health.yml +++ b/utils/apps/kafka/kafka_cluster_health.yml @@ -12,8 +12,8 @@ vars: delay: 1 retries: 60 - a_ns: "{{ zk_ns }}" - a_label: "{{ zk_label }}" + app_ns: "{{ zk_ns }}" + app_label: "{{ zk_label }}" - name: Obtain pods name of any one of the zookeeper pods shell: > @@ -51,19 +51,19 @@ when: "kafka_instance is defined and kafka_instance != ''" -- block: - - name: Derive the available kafka brokers from zookeeper - shell: > - kubectl exec {{ zk_pod_name }} -n {{ zk_ns }} bash - -- zkCli.sh -server {{ zk_service }}:{{ zk_port }} - ls /brokers/ids | tail -n 1 | tr -d '[],' | tr ' ' '\n' | wc -l - args: - executable: /bin/bash - register: kafka_available_brokers +# - block: +# - name: Derive the available kafka brokers from zookeeper +# shell: > +# kubectl exec {{ zk_pod_name }} -n {{ zk_ns }} bash +# -- zkCli.sh -server {{ zk_service }}:{{ zk_port }} +# ls /brokers/ids | tail -n 1 | tr -d '[],' | tr ' ' '\n' | wc -l +# args: +# executable: /bin/bash +# register: kafka_available_brokers - - name: Check whether all kafka brokers are alive - debug: - msg: "All Kafka brokers are alive" - failed_when: "kafka_sts_replicas.stdout != kafka_available_brokers.stdout" +# - name: Check whether all kafka brokers are alive +# debug: +# msg: "All Kafka brokers are alive" +# failed_when: "kafka_sts_replicas.stdout != kafka_available_brokers.stdout" - when: "kafka_instance is not defined or kafka_instance == ''" +# when: "kafka_instance is not defined or kafka_instance == ''" diff --git a/utils/cloud/aws/aws_configure.yml b/utils/cloud/aws/aws_configure.yml index 14c155d0a61..f65c74e8cb7 100644 --- a/utils/cloud/aws/aws_configure.yml +++ b/utils/cloud/aws/aws_configure.yml @@ -10,5 +10,5 @@ - name: Copying aws credentials from cloud_config copy: - src: /mnt/cloud_config.yml - dest: /root/.aws/credentials \ No newline at end of file + src: /tmp/cloud_config.yml + dest: /root/.aws/credentials \ No newline at end of file