Skip to content

Commit

Permalink
[Cherrypick for 2.2.0] (#456)
Browse files Browse the repository at this point in the history
* Bug(Experiment Generator): Add AuxiliaryAppInfo to template (#455)

Signed-off-by: dravog7 <[email protected]>

* chore(charts): update readme, contributor guide and github actions (#454)

* chore(charts): update readme, contributor guide and github actions

Signed-off-by: shubham chaudhary <[email protected]>

* chore(repo-health): adding cii best practices

Signed-off-by: shubham chaudhary <[email protected]>

* chore(synk): Adding snyk to check the vulnerabilities

Signed-off-by: shubham chaudhary <[email protected]>

* chore(trivy): remove trivy check from push and release actions

Signed-off-by: shubham chaudhary <[email protected]>

* resolved conflicts

Signed-off-by: shubham chaudhary <[email protected]>

Co-authored-by: John Abraham <[email protected]>
  • Loading branch information
Shubham Chaudhary and dravog7 committed Oct 13, 2021
1 parent 0ffc453 commit f8d618c
Show file tree
Hide file tree
Showing 116 changed files with 1,159 additions and 1,717 deletions.
23 changes: 23 additions & 0 deletions .github/auto-merge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Configuration for probot-auto-merge - https://github.com/bobvanderlinden/probot-auto-merge

reportStatus: true
updateBranch: false
deleteBranchAfterMerge: true
mergeMethod: squash

minApprovals:
COLLABORATOR: 0
maxRequestedChanges:
NONE: 0
blockingLabels:
- DO NOT MERGE
- WIP
- blocked

# Will merge whenever the above conditions are met, but also
# the owner has approved or merge label was added.
rules:
- minApprovals:
OWNER: 1
- requiredLabels:
- merge
13 changes: 12 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,18 @@ jobs:
fi
- name: golangci-lint
uses: reviewdog/action-golangci-lint@v1
uses: reviewdog/action-golangci-lint@v1

security:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Run Snyk to check for vulnerabilities
uses: snyk/actions/golang@master
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
args: --severity-threshold=high

build:
needs: pre-checks
Expand Down
19 changes: 0 additions & 19 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,3 @@ jobs:
file: build/Dockerfile
platforms: linux/amd64,linux/arm64
tags: litmuschaos/go-runner:ci

trivy:
needs: pre-checks
runs-on: ubuntu-latest
steps:
# Install golang
- uses: actions/setup-go@v2
with:
go-version: 1.16
- uses: actions/checkout@v2

- name: Build image for trivy scan
run: make build-amd64

- name: setup trivy
run: |
wget https://github.com/aquasecurity/trivy/releases/download/v0.11.0/trivy_0.11.0_Linux-64bit.tar.gz
tar zxvf trivy_0.11.0_Linux-64bit.tar.gz
make trivy-check
19 changes: 0 additions & 19 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,3 @@ jobs:
file: build/Dockerfile
platforms: linux/amd64,linux/arm64
tags: litmuschaos/go-runner:${{ env.RELEASE_TAG }},litmuschaos/go-runner:latest

trivy:
needs: pre-checks
runs-on: ubuntu-latest
steps:
# Install golang
- uses: actions/setup-go@v2
with:
go-version: 1.16
- uses: actions/checkout@v2

- name: Build image for trivy scan
run: make build-amd64

- name: setup trivy
run: |
wget https://github.com/aquasecurity/trivy/releases/download/v0.11.0/trivy_0.11.0_Linux-64bit.tar.gz
tar zxvf trivy_0.11.0_Linux-64bit.tar.gz
make trivy-check
7 changes: 6 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,9 @@ This project is implemented using Go and uses the standard golang tools for deve
- are familiar with Docker containers
- are familiar with Kubernetes and have access to a Kubernetes cluster or Minikube to test the changes.

For the creation of new chaos-experiment and testing of the modified changes, see the detailed instructions [here](./contribute/developer-guide/README.md).
For the creation of new chaos-experiment and testing of the modified changes, see the detailed instructions [here](./contribute/developer-guide/README.md).

## Community

The litmus community will have a monthly community sync-up on 3rd Wednesday 22.00-23.00IST / 18.30-19.30CEST
- The community meeting details are available [here](https://hackmd.io/a4Zu_sH4TZGeih-xCimi3Q). Please feel free to join the community meeting.
42 changes: 33 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,37 @@
# LitmusGo:

- This repo consists of Litmus Chaos Experiments written in golang. The examples in this repo are good indicators
of how to construct the experiments in golang: complete with steady state checks, chaosresult generation, chaos injection etc..,
post chaos checks, create events and reports for observability and configure sinks for these.
[![Slack Channel](https://img.shields.io/badge/Slack-Join-purple)](https://slack.litmuschaos.io)
![GitHub Workflow](https://github.com/litmuschaos/litmus-go/actions/workflows/push.yml/badge.svg?branch=master)
[![Docker Pulls](https://img.shields.io/docker/pulls/litmuschaos/go-runner.svg)](https://hub.docker.com/r/litmuschaos/go-runner)
[![GitHub issues](https://img.shields.io/github/issues/litmuschaos/litmus-go)](https://github.com/litmuschaos/litmus-go/issues)
[![Twitter Follow](https://img.shields.io/twitter/follow/litmuschaos?style=social)](https://twitter.com/LitmusChaos)
[![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/5297/badge)](https://bestpractices.coreinfrastructure.org/projects/5297)
[![Go Report Card](https://goreportcard.com/badge/github.com/litmuschaos/litmus-go)](https://goreportcard.com/report/github.com/litmuschaos/litmus-go)
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Flitmuschaos%2Flitmus-go.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Flitmuschaos%2Flitmus-go?ref=badge_shield)
[![YouTube Channel](https://img.shields.io/badge/YouTube-Subscribe-red)](https://www.youtube.com/channel/UCa57PMqmz_j0wnteRa9nCaw)
<br><br>

**NOTE**
This repo consists of Litmus Chaos Experiments written in golang. The examples in this repo are good indicators of how to construct the experiments in golang: complete with steady state checks, chaosresult generation, chaos injection etc.., post chaos checks, create events and reports for observability and configure sinks for these.

- This repo can be viewed as an extension to the [litmuschaos/litmus](https://github.com/litmuschaos/litmus) repo
in the sense that the litmus repo also houses a significant set of experiments, built using ansible. The litmus repo
will also continue to be the project's community-facing meta repo housing other important project artifacts. In that
sense, litmus-go is very similar to and therefore a sister repo of [litmus-python](https://github.com/litmuschaos/litmus-python) which
houses examples for experiment business logic written in python.
**NOTE**: This repo can be viewed as an extension to the [litmuschaos/litmus](https://github.com/litmuschaos/litmus) repo. The litmus repo will also continue to be the project's community-facing meta repo housing other important project artifacts. In that sense, litmus-go is very similar to and therefore a sister repo of [litmus-python](https://github.com/litmuschaos/litmus-python) which houses examples for experiment business logic written in python.

## Litmus SDK

The Litmus SDK provides a simple way to bootstrap your experiment and helps create the aforementioned artifacts in the appropriate directory (i.e., as per the chaos-category) based on an attributes file provided as input by the chart-developer. The scaffolded files consist of placeholders which can then be filled as desired.

It generates the custom chaos experiments with some default Pre & Post Chaos Checks (AUT & Auxiliary Applications status checks). It can use the existing chaoslib (present inside /chaoslib directory), if available else It will create a new chaoslib inside the corresponding directory.

Refer [Litmus-SDK](https://github.com/litmuschaos/litmus-go/blob/master/contribute/developer-guide/README.md) for more details.

## How to get started?

Refer the [LitmusChaos Docs](https://docs.litmuschaos.io) and [Experiment Docs](https://litmuschaos.github.io/litmus/experiments/categories/contents/)

## How do I contribute?

You can contribute by raising issues, improving the documentation, contributing to the core framework and tooling, etc.

Head over to the [Contribution guide](CONTRIBUTING.md)

## License
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Flitmuschaos%2Flitmus-go.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Flitmuschaos%2Flitmus-go?ref=badge_large)
4 changes: 2 additions & 2 deletions chaoslib/litmus/aws-ssm-chaos/lib/ssm-chaos.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func InjectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetai

select {
case <-inject:
// stopping the chaos execution, if abort signal recieved
// stopping the chaos execution, if abort signal received
os.Exit(0)
default:
//ChaosStartTimeStamp contains the start timestamp, when the chaos injection begin
Expand Down Expand Up @@ -86,7 +86,7 @@ func InjectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDet

select {
case <-inject:
// stopping the chaos execution, if abort signal recieved
// stopping the chaos execution, if abort signal received
os.Exit(0)
default:
//ChaosStartTimeStamp contains the start timestamp, when the chaos injection begin
Expand Down
4 changes: 2 additions & 2 deletions chaoslib/litmus/azure-disk-loss/lib/azure-disk-loss.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func PrepareChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients

select {
case <-inject:
// stopping the chaos execution, if abort signal recieved
// stopping the chaos execution, if abort signal received
os.Exit(0)
default:

Expand Down Expand Up @@ -247,7 +247,7 @@ func abortWatcher(experimentsDetails *experimentTypes.ExperimentDetails, attache

log.Info("[Abort]: Chaos Revert Started")

log.Info("[Abort]: Attaching disk(s) as abort signal recieved")
log.Info("[Abort]: Attaching disk(s) as abort signal received")

for instanceName, diskList := range attachedDisksWithInstance {
// Checking for provisioning state of the vm instances
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func injectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDet
events.GenerateEvents(eventsDetails, clients, chaosDetails, "ChaosEngine")
}

// PowerOff the instances parallely
// PowerOff the instances parallelly
for _, vmName := range instanceNameList {
// Stopping the Azure instance
log.Infof("[Chaos]: Stopping the Azure instance: %v", vmName)
Expand Down
35 changes: 17 additions & 18 deletions chaoslib/litmus/container-kill/helper/container-kill.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

"github.com/litmuschaos/litmus-go/pkg/clients"
"github.com/litmuschaos/litmus-go/pkg/events"
experimentEnv "github.com/litmuschaos/litmus-go/pkg/generic/container-kill/environment"
experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/container-kill/types"
"github.com/litmuschaos/litmus-go/pkg/log"
"github.com/litmuschaos/litmus-go/pkg/result"
Expand All @@ -34,7 +33,7 @@ func Helper(clients clients.ClientSets) {
getENV(&experimentsDetails)

// Intialise the chaos attributes
experimentEnv.InitialiseChaosVariables(&chaosDetails, &experimentsDetails)
types.InitialiseChaosVariables(&chaosDetails)

// Intialise Chaos Result Parameters
types.SetResultAttributes(&resultDetails, chaosDetails)
Expand Down Expand Up @@ -197,20 +196,20 @@ func verifyRestartCount(experimentsDetails *experimentTypes.ExperimentDetails, p

//getENV fetches all the env variables from the runner pod
func getENV(experimentDetails *experimentTypes.ExperimentDetails) {
experimentDetails.ExperimentName = common.Getenv("EXPERIMENT_NAME", "")
experimentDetails.InstanceID = common.Getenv("INSTANCE_ID", "")
experimentDetails.AppNS = common.Getenv("APP_NS", "")
experimentDetails.TargetContainer = common.Getenv("APP_CONTAINER", "")
experimentDetails.TargetPods = common.Getenv("APP_POD", "")
experimentDetails.ChaosDuration, _ = strconv.Atoi(common.Getenv("TOTAL_CHAOS_DURATION", "30"))
experimentDetails.ChaosInterval, _ = strconv.Atoi(common.Getenv("CHAOS_INTERVAL", "10"))
experimentDetails.ChaosNamespace = common.Getenv("CHAOS_NAMESPACE", "litmus")
experimentDetails.EngineName = common.Getenv("CHAOS_ENGINE", "")
experimentDetails.ChaosUID = clientTypes.UID(common.Getenv("CHAOS_UID", ""))
experimentDetails.ChaosPodName = common.Getenv("POD_NAME", "")
experimentDetails.SocketPath = common.Getenv("SOCKET_PATH", "")
experimentDetails.ContainerRuntime = common.Getenv("CONTAINER_RUNTIME", "")
experimentDetails.Signal = common.Getenv("SIGNAL", "SIGKILL")
experimentDetails.Delay, _ = strconv.Atoi(common.Getenv("STATUS_CHECK_DELAY", "2"))
experimentDetails.Timeout, _ = strconv.Atoi(common.Getenv("STATUS_CHECK_TIMEOUT", "180"))
experimentDetails.ExperimentName = types.Getenv("EXPERIMENT_NAME", "")
experimentDetails.InstanceID = types.Getenv("INSTANCE_ID", "")
experimentDetails.AppNS = types.Getenv("APP_NAMESPACE", "")
experimentDetails.TargetContainer = types.Getenv("APP_CONTAINER", "")
experimentDetails.TargetPods = types.Getenv("APP_POD", "")
experimentDetails.ChaosDuration, _ = strconv.Atoi(types.Getenv("TOTAL_CHAOS_DURATION", "30"))
experimentDetails.ChaosInterval, _ = strconv.Atoi(types.Getenv("CHAOS_INTERVAL", "10"))
experimentDetails.ChaosNamespace = types.Getenv("CHAOS_NAMESPACE", "litmus")
experimentDetails.EngineName = types.Getenv("CHAOSENGINE", "")
experimentDetails.ChaosUID = clientTypes.UID(types.Getenv("CHAOS_UID", ""))
experimentDetails.ChaosPodName = types.Getenv("POD_NAME", "")
experimentDetails.SocketPath = types.Getenv("SOCKET_PATH", "")
experimentDetails.ContainerRuntime = types.Getenv("CONTAINER_RUNTIME", "")
experimentDetails.Signal = types.Getenv("SIGNAL", "SIGKILL")
experimentDetails.Delay, _ = strconv.Atoi(types.Getenv("STATUS_CHECK_DELAY", "2"))
experimentDetails.Timeout, _ = strconv.Atoi(types.Getenv("STATUS_CHECK_TIMEOUT", "180"))
}
4 changes: 2 additions & 2 deletions chaoslib/litmus/container-kill/lib/container-kill.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,12 @@ func createHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clie
func getPodEnv(experimentsDetails *experimentTypes.ExperimentDetails, podName string) []apiv1.EnvVar {

var envDetails common.ENVDetails
envDetails.SetEnv("APP_NS", experimentsDetails.AppNS).
envDetails.SetEnv("APP_NAMESPACE", experimentsDetails.AppNS).
SetEnv("APP_POD", podName).
SetEnv("APP_CONTAINER", experimentsDetails.TargetContainer).
SetEnv("TOTAL_CHAOS_DURATION", strconv.Itoa(experimentsDetails.ChaosDuration)).
SetEnv("CHAOS_NAMESPACE", experimentsDetails.ChaosNamespace).
SetEnv("CHAOS_ENGINE", experimentsDetails.EngineName).
SetEnv("CHAOSENGINE", experimentsDetails.EngineName).
SetEnv("CHAOS_UID", string(experimentsDetails.ChaosUID)).
SetEnv("CHAOS_INTERVAL", strconv.Itoa(experimentsDetails.ChaosInterval)).
SetEnv("SOCKET_PATH", experimentsDetails.SocketPath).
Expand Down
35 changes: 17 additions & 18 deletions chaoslib/litmus/disk-fill/helper/disk-fill.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (

"github.com/litmuschaos/litmus-go/pkg/clients"
"github.com/litmuschaos/litmus-go/pkg/events"
experimentEnv "github.com/litmuschaos/litmus-go/pkg/generic/disk-fill/environment"
experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/disk-fill/types"
"github.com/litmuschaos/litmus-go/pkg/log"
"github.com/litmuschaos/litmus-go/pkg/result"
Expand Down Expand Up @@ -50,7 +49,7 @@ func Helper(clients clients.ClientSets) {
getENV(&experimentsDetails)

// Intialise the chaos attributes
experimentEnv.InitialiseChaosVariables(&chaosDetails, &experimentsDetails)
types.InitialiseChaosVariables(&chaosDetails)

// Intialise Chaos Result Parameters
types.SetResultAttributes(&resultDetails, chaosDetails)
Expand Down Expand Up @@ -158,7 +157,7 @@ func fillDisk(containerID string, sizeTobeFilled, bs int) error {

select {
case <-inject:
// stopping the chaos execution, if abort signal recieved
// stopping the chaos execution, if abort signal received
os.Exit(1)
default:
// Creating files to fill the required ephemeral storage size of block size of 4K
Expand Down Expand Up @@ -253,24 +252,24 @@ func remedy(experimentsDetails *experimentTypes.ExperimentDetails, clients clien

//getENV fetches all the env variables from the runner pod
func getENV(experimentDetails *experimentTypes.ExperimentDetails) {
experimentDetails.ExperimentName = common.Getenv("EXPERIMENT_NAME", "")
experimentDetails.InstanceID = common.Getenv("INSTANCE_ID", "")
experimentDetails.AppNS = common.Getenv("APP_NS", "")
experimentDetails.TargetContainer = common.Getenv("APP_CONTAINER", "")
experimentDetails.TargetPods = common.Getenv("APP_POD", "")
experimentDetails.ChaosDuration, _ = strconv.Atoi(common.Getenv("TOTAL_CHAOS_DURATION", "30"))
experimentDetails.ChaosNamespace = common.Getenv("CHAOS_NAMESPACE", "litmus")
experimentDetails.EngineName = common.Getenv("CHAOS_ENGINE", "")
experimentDetails.ChaosUID = clientTypes.UID(common.Getenv("CHAOS_UID", ""))
experimentDetails.ChaosPodName = common.Getenv("POD_NAME", "")
experimentDetails.FillPercentage, _ = strconv.Atoi(common.Getenv("FILL_PERCENTAGE", ""))
experimentDetails.EphemeralStorageMebibytes, _ = strconv.Atoi(common.Getenv("EPHEMERAL_STORAGE_MEBIBYTES", ""))
experimentDetails.DataBlockSize, _ = strconv.Atoi(common.Getenv("DATA_BLOCK_SIZE", "256"))
experimentDetails.ExperimentName = types.Getenv("EXPERIMENT_NAME", "")
experimentDetails.InstanceID = types.Getenv("INSTANCE_ID", "")
experimentDetails.AppNS = types.Getenv("APP_NAMESPACE", "")
experimentDetails.TargetContainer = types.Getenv("APP_CONTAINER", "")
experimentDetails.TargetPods = types.Getenv("APP_POD", "")
experimentDetails.ChaosDuration, _ = strconv.Atoi(types.Getenv("TOTAL_CHAOS_DURATION", "30"))
experimentDetails.ChaosNamespace = types.Getenv("CHAOS_NAMESPACE", "litmus")
experimentDetails.EngineName = types.Getenv("CHAOSENGINE", "")
experimentDetails.ChaosUID = clientTypes.UID(types.Getenv("CHAOS_UID", ""))
experimentDetails.ChaosPodName = types.Getenv("POD_NAME", "")
experimentDetails.FillPercentage, _ = strconv.Atoi(types.Getenv("FILL_PERCENTAGE", ""))
experimentDetails.EphemeralStorageMebibytes, _ = strconv.Atoi(types.Getenv("EPHEMERAL_STORAGE_MEBIBYTES", ""))
experimentDetails.DataBlockSize, _ = strconv.Atoi(types.Getenv("DATA_BLOCK_SIZE", "256"))
}

// abortWatcher continuosly watch for the abort signals
// abortWatcher continuously watch for the abort signals
func abortWatcher(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, containerID, resultName string) {
// waiting till the abort signal recieved
// waiting till the abort signal received
<-abort

log.Info("[Chaos]: Killing process started because of terminated signal received")
Expand Down
4 changes: 2 additions & 2 deletions chaoslib/litmus/disk-fill/lib/disk-fill.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,12 @@ func createHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clie
func getPodEnv(experimentsDetails *experimentTypes.ExperimentDetails, podName string) []apiv1.EnvVar {

var envDetails common.ENVDetails
envDetails.SetEnv("APP_NS", experimentsDetails.AppNS).
envDetails.SetEnv("APP_NAMESPACE", experimentsDetails.AppNS).
SetEnv("APP_POD", podName).
SetEnv("APP_CONTAINER", experimentsDetails.TargetContainer).
SetEnv("TOTAL_CHAOS_DURATION", strconv.Itoa(experimentsDetails.ChaosDuration)).
SetEnv("CHAOS_NAMESPACE", experimentsDetails.ChaosNamespace).
SetEnv("CHAOS_ENGINE", experimentsDetails.EngineName).
SetEnv("CHAOSENGINE", experimentsDetails.EngineName).
SetEnv("CHAOS_UID", string(experimentsDetails.ChaosUID)).
SetEnv("EXPERIMENT_NAME", experimentsDetails.ExperimentName).
SetEnv("FILL_PERCENTAGE", strconv.Itoa(experimentsDetails.FillPercentage)).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func PrepareEBSLossByID(experimentsDetails *experimentTypes.ExperimentDetails, c

select {
case <-inject:
// stopping the chaos execution, if abort signal recieved
// stopping the chaos execution, if abort signal received
os.Exit(0)
default:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func PrepareEBSLossByTag(experimentsDetails *experimentTypes.ExperimentDetails,

select {
case <-inject:
// stopping the chaos execution, if abort signal recieved
// stopping the chaos execution, if abort signal received
os.Exit(0)
default:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetai

select {
case <-inject:
// stopping the chaos execution, if abort signal recieved
// stopping the chaos execution, if abort signal received
os.Exit(0)
default:
//ChaosStartTimeStamp contains the start timestamp, when the chaos injection begin
Expand Down Expand Up @@ -149,7 +149,7 @@ func injectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDet

select {
case <-inject:
// stopping the chaos execution, if abort signal recieved
// stopping the chaos execution, if abort signal received
os.Exit(0)
default:
//ChaosStartTimeStamp contains the start timestamp, when the chaos injection begin
Expand Down
Loading

0 comments on commit f8d618c

Please sign in to comment.