Contribution Guidelines
How to contribute and get started
How to contribute
We’re excited to have you consider contributing to our chaos! Contributions are always appreciated.
Krkn
Contributing to Krkn
If you would like to contribute to Krkn, but are not sure exactly what to work on, you can find a number of open issues that are awaiting contributions in
issues.
Adding New Scenarios and Configurations
New Scenarios
We are always looking for new scenarios to make krkn better and more usable for our chaos community. If you have any ideas, please first open an issue to explain the new scenario you are wanting to add. We will review and respond with ideas of how to get started.
New Configuration to Scenarios
If you are currently using a scenario but want more configuration options, please open a github issue describing your use case and what fields and functionality you would like to see added. We will review the sugguestion and give pointers on how to add the functionality. If you feel inclined, you can start working on the feature and we’ll help if you get stuck along the way.
Work in Progress PR’s
If you are working on a contribution in any capacity and would like to get a new set of eyes on your work, go ahead and open a PR with ‘[WIP]’ at the start of the tite in your PR and tag the maintainers for review. We will review your changes and give you sugguestions to keep you moving!
Good PR Checklist
Here’s a quick checklist for a good PR, more details below:
- One feature/change per PR
- One commit per PR squash your commits
- PR rebased on main (git rebase, not git pull)
- Good descriptive commit message, with link to issue
- No changes to code not directly related to your PR
- Includes functional/integration test (more applicable to krkn-lib)
- Includes link to documentation PR (documentation hosted in https://github.com/krkn-chaos/website)
Helpful Documents
Refer to the docs below to be able to test your own images with any changes and be able to contribute them to the repository
1 - Testing your changes
This page gives details about how you can get a kind cluster configured to be able to run on krkn-lib (the lowest level of krkn-chaos repos) up through krkn-hub
Testing Changes in Krkn-lib
Create a kind cluster if needed
Install kind
Create cluster using kind-config.yml under krkn-lib base folder
kind create cluster --wait 300s --config=kind-config.yml
Elasticsearch and Prometheus
To be able to run the full test suite of tests you need to have elasticsearch and promethues properly configured on the cluster
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo add stable https://charts.helm.sh/stable
helm repo update
Prometheus
Configuring prometheus
ElasticSearch
Set enviornment variables of elasticsearch variables
export ELASTIC_URL="https://localhost"
export ELASTIC_PORT="9091"
export ELASTIC_USER="elastic"
export ELASTIC_PASSWORD="test"
Configuring elasticsearch
Install poetry
Using a virtual enviornment install poetry and install krkn-lib requirmenets
$ pip install poetry
$ poetry install --no-interaction
Run tests
poetry run python3 -m coverage run -a -m unittest discover -v src/krkn_lib/tests/
Adding a New Scenario to Krkn-hub
Install Podman/Docker Compose
You can use either podman-compose or docker-compose for this step
NOTE: Podman might not work on Mac’s
pip3 install docker-compose
OR
To get latest podman-compose features we need, use this installation command
pip3 install https://github.com/containers/podman-compose/archive/devel.tar.gz
Editing a New Scenario to Krkn-hub
Create folder with scenario name
Create generic scenario template with enviornment variables
a. See scenario.yaml for example
b. Almost all parameters should be set using a variable (these will be set in the env.sh file or through the command line environment variables)
Add defaults for any environment variables in an “env.sh” file
a. See env.sh for example
Create script to run.sh chaos scenario
a. See run.sh for example
b. edit line 16 with your scenario yaml template
c. edit line 17 and 23 with your yaml config location
Create Dockerfile template
a. See dockerfile for example
b. Lines to edit
i. 15: replace "application-outages" with your folder name
ii. 17: replace "application-outages" with your folder name
iii. 19: replace "application-outages" with your folder name and config file name
Add service/scenario to docker-compose.yaml file following syntax of other services
Point the dockerfile parameter in your docker-compose to the Dockerfile file in your new folder
Update this doc and main README with new scenario type
Add CI test for new scenario
a. See test_application_outages.sh for example
b. Lines to change
i. 14 and 31: Give a new function name
ii. 19: Give it a meaningful container name
iii. Edit line 20 to give scenario type defined in docker-compose file
c. Add test name to all_tests file
NOTE:
- If you added any variables or new sections be sure to update config.yaml.template
- Similar to above, also add the default parameter values to env.sh
Build Your Changes
- Run build.sh to get Dockerfiles for each scenario
- Edit the docker-compose.yaml file to point to your quay.io repository (optional)
- Build your image(s) from base krkn-hub directory
Builds all images in docker-compose file
docker-compose build
Builds single image defined by service/scenario name
docker-compose build <scenario_type>
OR
Builds all images in podman-compose file
podman-compose build
Builds single image defined by service/scenario name
podman-compose build <scenario_type>
Push Images to your quay.io
All Images
docker image push --all-tags quay.io/<username>/kraken-hub
Single image
docker image push quay.io/<username>/kraken-hub:<scenario_type>
OR
Single Image (have to go one by one to push images through podman)
podman image push quay.io/<username>/kraken-hub:<scenario_type>
Run your scenario
docker run -d -v <kube_config_path>:/root/.kube/config:Z quay.io/<username>/kraken-hub:<scenario_type>
OR
podman run -d -v <kube_config_path>:/root/.kube/config:Z quay.io/<username>/kraken-hub:<scenario_type>
Follow Contribute guide
Once all you’re happy with your changes, follow the contribution guide on how to create your own branch and squash your commits
2 - Contributions
How to contribute
Contributions are always appreciated.
How to:
Pull request
In order to submit a change or a PR, please fork the project and follow instructions:
$ git clone http://github.com/<me>/krkn-hub
$ cd krkn-hub
$ git checkout -b <branch_name>
$ <make change>
$ git add <changes>
$ git commit -a
$ <insert good message>
$ git push
Squash Commits
If there are mutliple commits, please rebase/squash multiple commits
before creating the PR by following:
$ git checkout <my-working-branch>
$ git rebase -i HEAD~<num_of_commits_to_merge>
-OR-
$ git rebase -i <commit_id_of_first_change_commit>
In the interactive rebase screen, set the first commit to pick
and all others to squash
(or whatever else you may need to do).
Push your rebased commits (you may need to force), then issue your PR.
$ git push origin <my-working-branch> --force
Rebase with Upstream
If new commits were merged while you were working you’ll need to rebase with upstream
before creating the PR by following:
$ git checkout <my-working-branch>
$ git remote add upstream https://github.com/krkn-chaos/krkn (or krkn-hub)
$ git fetch upstream
$ git rebase upstream/<branch_in_upstream_to_rebase> (most likely `main`)
If any errors occur:
- It’ll list off any files that have merge issues
- Edit the files with the code blocks you want to keep
- Add and continue rebase
$ git add .
$ git rebase --continue
- Might need to repeat steps 1-3 until you see
Successfully rebased and updated refs/heads/<my-working-branch>.
Push your rebased commits (you may need to force), then issue your PR.
$ git push origin <my-working-branch> --force
Developer’s Certificate of Origin
Any contributions to Krkn must only contain code that can legally be contributed to Krkn, and which the Krkn project can distribute under its license.
Prior to contributing to Krkn please read the Developer’s Certificate of Origin and sign-off all commits with the –signoff option provided by git commit. For example:
git rebase HEAD~1 --signoff
git push origin <branch_name> --force
This option adds a Signed-off-by trailer at the end of the commit log message.