DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
Securing Your Software Supply Chain with JFrog and Azure
Register Today

Trending

  • 5 Common Data Structures and Algorithms Used in Machine Learning
  • Reactive Programming
  • Decoding eBPF Observability: How eBPF Transforms Observability as We Know It
  • Java Concurrency: Condition

Trending

  • 5 Common Data Structures and Algorithms Used in Machine Learning
  • Reactive Programming
  • Decoding eBPF Observability: How eBPF Transforms Observability as We Know It
  • Java Concurrency: Condition
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Chaos-Mesh-Action: Integrate Chaos Engineering Into Your CI

Chaos-Mesh-Action: Integrate Chaos Engineering Into Your CI

Chaos-mesh-action lets you integrate chaos testing into your CI/continuous development (CD) process.

Xiang Wang user avatar by
Xiang Wang
·
Sep. 21, 20 · Analysis
Like (3)
Save
Tweet
Share
4.07K Views

Join the DZone community and get the full member experience.

Join For Free
chaos mesh

Chaos Mesh is a cloud-native chaos testing platform that orchestrates chaos in Kubernetes environments. While it's well-received in the community with its rich fault injection types and easy-to-use dashboard, it was difficult to use Chaos Mesh with end-to-end testing or the continuous integration (CI) process. As a result, problems introduced during system development could not be discovered before the release.

In this article, I will share how we use chaos-mesh-action, a GitHub action to integrate Chaos Mesh into the CI process.

chaos-mesh-action is available on the GitHub market, and the source code is on GitHub.

Design of Chaos-mesh-action

GitHub Action is a CI/CD feature natively supported by GitHub, through which we can easily build automated and customized software development workflows in the GitHub repository.

Combined with GitHub's actions, Chaos Mesh can be more easily integrated into the daily development and testing of the system, thus guaranteeing that each code submission on GitHub is bug-free and won't damage existing code. The following figure shows chaos-mesh-action integrated into the CI workflow:

github

Using Chaos-mesh-action in GitHub Workflow

chaos-mesh-action works in Github workflows. A GitHub workflow is a configurable automated process that you can set up in your repository to build, test, package, release, or deploy any GitHub project. To integrate Chaos Mesh in your CI, do the following:

  1. Design a workflow.
  2. Create a workflow.
  3. Run the workflow.

Design a Workflow

Before you design a workflow, you must consider the following issues:

  • What functions are we going to test in this workflow?
  • What types of faults will we inject?
  • How do we verify the correctness of the system?

As an example, let's design a simple test workflow that includes the following steps:

  1. Create two Pods in a Kubernetes cluster.
  2. Ping one pod from the other.
  3. Use Chaos Mesh to inject network delay chaos and test whether the ping command is affected.

Create the Workflow

After you design the workflow, the next step is to create it.

  1. Navigate to the GitHub repository that contains the software you want to test.
  2. To start creating a workflow, click Actions, and then click the "New workflow" button:
chaos-mesh

A workflow is essentially the configuration of jobs that take place sequentially and automatically. Note that the jobs are configured in a single file. For better illustration, we split the script into different job groups as shown below:

  • Set the workflow name and trigger rules.

This job names the workflow "Chaos." When the code is pushed to the master branch or a pull request is submitted to the master branch, this workflow is triggered.

YAML
 




x


 
1
name: Chaos
2

            
3
on:
4
 push:
5
   branches:
6
     - master
7
 pull_request:
8
   branches:
9
     - master



  • Install the CI-related environment.

This configuration specifies the operating system (Ubuntu), and that it uses helm/kind-action to create a Kind cluster. Then, it outputs related information about the cluster. Finally, it checks out the GitHub repository for the workflow to access.

YAML
 




xxxxxxxxxx
1
18


 
1
jobs:
2
 build:
3
   runs-on: ubuntu-latest
4
   steps:
5

            
6
   - name: Creating kind cluster
7
     uses: helm/kind-action@v1.0.0-rc.1
8

            
9
   - name: Print cluster information
10
     run: |
11
       kubectl config view
12
       kubectl cluster-info
13
       kubectl get nodes
14
       kubectl get pods -n kube-system
15
       helm version
16
       kubectl version
17

            
18
   - uses: actions/checkout@v2




  • Deploy the application.

In our example, this job deploys an application that creates two Kubernetes Pods.

YAML
 




xxxxxxxxxx
1


 
1
- name: Deploy an application
2
     run: |
3
       kubectl apply -f https://raw.githubusercontent.com/chaos-mesh/apps/master/ping/busybox-statefulset.yaml




Inject chaos with chaos-mesh-action.
YAML
 




xxxxxxxxxx
1


 
1
- name: Run chaos mesh action
2
    uses: chaos-mesh/chaos-mesh-action@xiang/refine_script
3
    env:
4
      CFG_BASE64: YXBpVmVyc2lvbjogY2hhb3MtbWVzaC5vcmcvdjFhbHBoYTEKa2luZDogTmV0d29ya0NoYW9zCm1ldGFkYXRhOgogIG5hbWU6IG5ldHdvcmstZGVsYXkKICBuYW1lc3BhY2U6IGJ1c3lib3gKc3BlYzoKICBhY3Rpb246IGRlbGF5ICMgdGhlIHNwZWNpZmljIGNoYW9zIGFjdGlvbiB0byBpbmplY3QKICBtb2RlOiBhbGwKICBzZWxlY3RvcjoKICAgIHBvZHM6CiAgICAgIGJ1c3lib3g6CiAgICAgICAgLSBidXN5Ym94LTAKICBkZWxheToKICAgIGxhdGVuY3k6ICIxMG1zIgogIGR1cmF0aW9uOiAiNXMiCiAgc2NoZWR1bGVyOgogICAgY3JvbjogIkBldmVyeSAxMHMiCiAgZGlyZWN0aW9uOiB0bwogIHRhcmdldDoKICAgIHNlbGVjdG9yOgogICAgICBwb2RzOgogICAgICAgIGJ1c3lib3g6CiAgICAgICAgICAtIGJ1c3lib3gtMQogICAgbW9kZTogYWxsCg==



With chaos-mesh-action, the installation of Chaos Mesh and the injection of chaos complete automatically. You simply need to prepare the chaos configuration that you intend to use to get its Base64 representation. Here, we want to inject network delay chaos into the Pods, so we use the original chaos configuration as follows:

YAML
 




xxxxxxxxxx
1
24


 
1
apiVersion: chaos-mesh.org/v1alpha1
2
kind: NetworkChaos
3
metadata:
4
 name: network-delay
5
 namespace: busybox
6
spec:
7
 action: delay # the specific chaos action to inject
8
 mode: all
9
 selector:
10
   pods:
11
     busybox:
12
       - busybox-0
13
 delay:
14
   latency: "10ms"
15
 duration: "5s"
16
 scheduler:
17
   cron: "@every 10s"
18
 direction: to
19
 target:
20
   selector:
21
     pods:
22
       busybox:
23
         - busybox-1
24
   mode: all



You can obtain the Base64 value of the above chaos configuration file using the following command:

Shell
 




xxxxxxxxxx
1


 
1
$ base64 chaos.yaml



  • Verify the system's correctness.

In this job, the workflow pings one Pod from the other and observes the changes in network delay.

YAML
 




xxxxxxxxxx
1


 
1
- name: Verify
2
     run: |
3
       echo "do some verification"
4
       kubectl exec busybox-0 -it -n busybox -- ping -c 30 busybox-1.busybox.busybox.svc



Run the Workflow

Now that the workflow is configured, we can trigger it by submitting a pull request to the master branch. When the workflow completes, the verification job outputs of the results that look similar to the following:

Shell
 




xxxxxxxxxx
1
14


 
1
do some verification
2
Unable to use a TTY - input is not a terminal or the right kind of file
3
PING busybox-1.busybox.busybox.svc (10.244.0.6): 56 data bytes
4
64 bytes from 10.244.0.6: seq=0 ttl=63 time=0.069 ms
5
64 bytes from 10.244.0.6: seq=1 ttl=63 time=10.136 ms
6
64 bytes from 10.244.0.6: seq=2 ttl=63 time=10.192 ms
7
64 bytes from 10.244.0.6: seq=3 ttl=63 time=10.129 ms
8
64 bytes from 10.244.0.6: seq=4 ttl=63 time=10.120 ms
9
64 bytes from 10.244.0.6: seq=5 ttl=63 time=0.070 ms
10
64 bytes from 10.244.0.6: seq=6 ttl=63 time=0.073 ms
11
64 bytes from 10.244.0.6: seq=7 ttl=63 time=0.111 ms
12
64 bytes from 10.244.0.6: seq=8 ttl=63 time=0.070 ms
13
64 bytes from 10.244.0.6: seq=9 ttl=63 time=0.077 ms
14
……



The output indicates a regular series of 10-millisecond delays that last about 5 seconds each. This is consistent with the chaos configuration we injected into chaos-mesh-action.

Current Status and Next Steps

At present, we have applied chaos-mesh-action to the TiDB Operator project. The workflow is injected with the Pod chaos to verify the restart function of the specified instances of the operator. The purpose is to ensure that the tidb-operator can work normally when the pods of the operator are randomly deleted by the injected faults. You can view the TiDB Operator page for more details.

In the future, we plan to apply chaos-mesh-action to more tests to ensure the stability of TiDB and related components. You are welcome to create your workflow using chaos-mesh-action.

If you find a bug or think something is missing, feel free to file an issue, open a pull request (PR), or join us on the #project-chaos-mesh channel in the CNCF slack workspace.

Continuous Integration/Deployment Chaos engineering workflow Integration GitHub operating system pull request

Published at DZone with permission of Xiang Wang. See the original article here.

Opinions expressed by DZone contributors are their own.

Trending

  • 5 Common Data Structures and Algorithms Used in Machine Learning
  • Reactive Programming
  • Decoding eBPF Observability: How eBPF Transforms Observability as We Know It
  • Java Concurrency: Condition

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: