Skip to content

Commit 57f5329

Browse files
author
Shubham Chaudhary
authored
Merge pull request #18 from oumkale/pod_delete
chore(experiment) : Pod-Delete Experiment and supporting Directory files added to litmus-python | BYOC added
2 parents 05020a0 + ae5f9a1 commit 57f5329

File tree

91 files changed

+1777
-110
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+1777
-110
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
**/.idea
22
**/*.egg-info
33
**/.DS_Store
4-
**/build
54
**/*intuit*/**
65
**/*intuit.md
76
**/*intuit*

.travis.yml

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,47 @@
1-
dist: trusty
2-
sudo: required
1+
os: linux
2+
dist: bionic
3+
services:
4+
- docker
35
install: true
46
stages:
57
- shell check
68
- build docker images
7-
env:
8-
global:
9-
- GOARCH=amd64
10-
before_install:
11-
- sleep 15
12-
- sudo apt-get install -y curl shellcheck
9+
- push docker images
1310

11+
before_script:
12+
- sudo apt-get install -y curl shellcheck
13+
- docker run --rm --privileged docker/binfmt:a7996909642ee92942dcd6cff44b9b95f08dad64
14+
# #Upgrade to Docker CE 19.03 for BuildKit support
15+
- curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
16+
- sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
17+
- sudo apt-get update
18+
- sudo apt-get -y -o Dpkg::Options::="--force-confnew" install docker-ce=5:19.03.8~3-0~ubuntu-bionic # pin version for reproducibility
19+
# Show info to simplify debugging and create a builder
20+
- docker info
21+
- docker buildx create --name builder --use
22+
- docker buildx ls
1423
jobs:
1524
include:
1625

1726
- stage: shell check
1827
name: checking syntax of shell script
1928
script:
2029
- bash -c 'shopt -s globstar nullglob; shellcheck **/*.{sh,ksh,bash}' || true
30+
31+
- stage: build docker images
32+
name: installing and configuring dependencies
33+
script:
34+
- make deps
35+
36+
- stage: build docker images
37+
name: build docker image
38+
script:
39+
- make build
2140

22-
- stage: build chaos-test images
23-
name: build docker image chaos-test
41+
- stage: push docker images
42+
name: push docker images
2443
script:
25-
- make chaostest
44+
- make push
2645

2746
notifications:
2847
email:

Dockerfile

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
2+
FROM python:3.8
3+
4+
LABEL maintainer="LitmusChaos"
5+
6+
ARG TARGETARCH
7+
8+
# upgrade and setup python
9+
RUN apt-get update \
10+
&& apt-get -y install gcc python-pip python3-pip python-dev curl \
11+
&& pip install --upgrade pip \
12+
&& pip install jinja2 pyYaml
13+
14+
#Installing kops
15+
ENV kopsversion=v1.20.0
16+
RUN curl -Lsf -o kops-linux https://github.com/kubernetes/kops/releases/download/${kopsversion}/kops-linux-${TARGETARCH}
17+
RUN chmod +x ./kops-linux
18+
RUN mv ./kops-linux /usr/local/bin/kops
19+
20+
#Installing Kubectl
21+
ENV KUBE_LATEST_VERSION="v1.18.0"
22+
RUN curl -L https://storage.googleapis.com/kubernetes-release/release/${KUBE_LATEST_VERSION}/bin/linux/${TARGETARCH}/kubectl -o /usr/local/bin/kubectl && \
23+
chmod +x /usr/local/bin/kubectl
24+
25+
RUN rm -rf /tmp/* /root/.cache
26+
27+
ENV LC_ALL=C.UTF-8
28+
29+
ENV LANG=C.UTF-8
30+
31+
WORKDIR /litmus
32+
33+
# Copying Necessary Files
34+
COPY . .
35+
36+
# Setup requirements
37+
RUN pip3 install -r requirements.txt
38+
RUN python3 setup.py install
39+
40+
WORKDIR /litmus/byoc
41+
42+
# Setup requirements for byoc
43+
RUN chmod +x install.sh
44+
RUN ./install.sh
45+
46+
WORKDIR /litmus
47+
48+
# Copying experiment file
49+
COPY ./bin/experiment/experiment.py ./experiments
50+
51+
ENV PYTHONPATH /litmus
52+
53+
ENTRYPOINT ["python3"]

Makefile

Lines changed: 62 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,34 @@
1-
# Makefile for building Containers for Storage Testing
1+
2+
# Makefile for building Litmus and its tools
23
# Reference Guide - https://www.gnu.org/software/make/manual/make.html
34

45
# Internal variables or constants.
56
# NOTE - These will be executed when any make target is invoked.
6-
IS_DOCKER_INSTALLED := $(shell which docker >> /dev/null 2>&1; echo $$?)
77

8+
IS_DOCKER_INSTALLED = $(shell which docker >> /dev/null 2>&1; echo $$?)
9+
10+
# Docker info
11+
DOCKER_REPO ?= litmuschaos
12+
DOCKER_IMAGE ?= py-runner
13+
DOCKER_TAG ?= ci
14+
15+
.PHONY: help
816
help:
917
@echo ""
1018
@echo "Usage:-"
11-
@echo "\tmake deps -- will verify build dependencies are installed"
12-
@echo "\tmake chaostest -- will build and push python experiment images
19+
@echo "\tmake deps -- sets up dependencies for image build"
20+
@echo "\tmake build -- builds the litmus-py multi-arch image"
21+
@echo "\tmake push -- pushes the litmus-py multi-arch image"
22+
@echo "\tmake build-amd64 -- builds the litmus-py docker amd64 image"
23+
@echo "\tmake push-amd64 -- pushes the litmus-py amd64 image"
1324
@echo ""
1425

26+
.PHONY: all
27+
all: deps build push
28+
29+
.PHONY: deps
30+
deps: _build_check_docker
31+
1532
_build_check_docker:
1633
@if [ $(IS_DOCKER_INSTALLED) -eq 1 ]; \
1734
then echo "" \
@@ -20,16 +37,47 @@ _build_check_docker:
2037
&& exit 1; \
2138
fi;
2239

23-
deps: _build_check_docker
24-
@echo ""
25-
@echo "INFO:\tverifying dependencies for litmus-python ..."
40+
.PHONY: build
41+
build: docker.buildx image-build
42+
43+
.PHONY: docker.buildx
44+
docker.buildx:
45+
@echo "------------------------------"
46+
@echo "--> Setting up Builder "
47+
@echo "------------------------------"
48+
@if ! docker buildx ls | grep -q multibuilder; then\
49+
docker buildx create --name multibuilder;\
50+
docker buildx inspect multibuilder --bootstrap;\
51+
docker buildx use multibuilder;\
52+
fi
53+
54+
.PHONY: image-build
55+
image-build:
56+
@echo "-------------------------"
57+
@echo "--> Build py-runner image"
58+
@echo "-------------------------"
59+
@docker buildx build --file Dockerfile --progress plane --platform linux/arm64,linux/amd64 --no-cache --tag $(DOCKER_REPO)/$(DOCKER_IMAGE):$(DOCKER_TAG) .
60+
61+
.PHONY: push
62+
push: docker.buildx litmus-py-push
2663

27-
_build_tests_chaostest_image:
28-
@echo "INFO: Building container image for performing chaostoolkit tests"
29-
cd chaos-test && docker build -t litmuschaos/chaostoolkit:ci .
64+
.PHONE: litmus-py-push
65+
litmus-py-push:
66+
@echo "-------------------"
67+
@echo "--> py-runner image"
68+
@echo "-------------------"
69+
REGISTRYNAME="$(DOCKER_REGISTRY)" REPONAME="$(DOCKER_REPO)" IMGNAME="$(DOCKER_IMAGE)" IMGTAG="$(DOCKER_TAG)" ./build/push
3070

31-
_push_tests_chaostest_image:
32-
@echo "INFO: Publish container litmuschaos/chaostoolkit:ci"
33-
REPONAME="litmuschaos" IMGNAME="chaostoolkit" IMGTAG="ci" ./chaos-test/buildscripts/push
71+
.PHONY: build-amd64
72+
build-amd64:
73+
@echo "-------------------------"
74+
@echo "--> Build py-runner amd64 image"
75+
@echo "-------------------------"
76+
@sudo docker build --file Dockerfile --tag $(DOCKER_REPO)/$(DOCKER_IMAGE):$(DOCKER_TAG) . --build-arg TARGETARCH=amd64
3477

35-
chaostest: deps _build_tests_chaostest_image _push_tests_chaostest_image
78+
.PHONY: push-amd64
79+
push-amd64:
80+
@echo "-------------------"
81+
@echo "--> push py-runner image"
82+
@echo "-------------------"
83+
REPONAME="$(DOCKER_REPO)" IMGNAME="$(DOCKER_IMAGE)" IMGTAG="$(DOCKER_TAG)" ./build/push

README.md

Lines changed: 7 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,13 @@
11
### litmus-python:
22

3-
This repo consists of Litmus Chaos Experiments written in Python. The examples in this repo are good indicators
4-
of how to construct the various experiment pieces in python: complete with steady state checks, chaos injection,
5-
chaosresult generation, post chaos checks, events generation, reports for observability etc..,
6-
7-
The chaos injection mechanism employed itself may vary ranging right from non-standard/custom approaches to reuse of
8-
popular tools like chaostoolkit.
3+
- This repo consists of Litmus Chaos Experiments written in python. The examples in this repo are good indicators
4+
of how to construct the experiments in python: complete with steady state checks, chaosresult generation, chaos injection,
5+
post chaos checks, create events and reports for observability and configure sinks for these.
96

107
**NOTE**
118

129
- This repo can be viewed as an extension to the [litmuschaos/litmus](https://github.com/litmuschaos/litmus) repo
13-
in the sense that the litmus repo also houses a set of chaos experiments, built using ansible. The litmus repo
14-
will also continue to be the project's community-facing meta repo housing other important project arefacts.
15-
The litmus-python is very similar to and therefore a sister repo of [litmus-go](https://github.com/litmuschaos/litmus-go)
16-
which houses examples for experiment business logic written in golang.
17-
18-
### commit process
19-
- Fork the project
20-
* checkout the project using
21-
```
22-
git clone [email protected]:sumitnagal/litmus-python.git
23-
```
24-
* go to your folder
25-
```
26-
cd litmus-python
27-
```
28-
* add upstream for main and intuit repo
29-
```
30-
git remote add upstream [email protected]:litmuschaos/litmus-python.git
31-
git pull upstream master
32-
git checkout -b <branch name>
33-
```
34-
* Make the changes and commit with signed
35-
```
36-
git add .
37-
git commit -s -m "<message>"
38-
git push origin <branch>
39-
```
40-
41-
### Appendix
42-
- This repo moved from existing location of [test-tools/chaostoolkit](https://github.com/litmuschaos/test-tools/tree/master/chaostoolkit) to better serve as stand-alone project
10+
in the sense that the litmus repo also houses a significant set of experiments, built using ansible. The litmus repo
11+
will also continue to be the project's community-facing meta repo housing other important project artifacts. In that
12+
sense, litmus-py is very similar to and therefore a sister repo of [litmus-go](https://github.com/litmuschaos/litmus-go) which
13+
houses examples for experiment business logic written in python.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1.19 KB
Binary file not shown.

bin/experiment/experiment.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env python3
2+
3+
import experimentList.generic.podDelete.podDelete as podDelete
4+
import argparse
5+
import logging
6+
import pkg.utils.client.client as client
7+
8+
logging.basicConfig(format='time=%(asctime)s level=%(levelname)s msg=%(message)s', level=logging.INFO)
9+
10+
def main():
11+
parser = argparse.ArgumentParser()
12+
13+
# parse the experiment name
14+
parser.add_argument("-name", action='store', default="pod-delete", dest="name", help="Chaos experiment for execution")
15+
# parse the kubeconfig
16+
parser.add_argument("-kubeconfig", required=False, default="", dest='kubeconfig', help="Absolute path to the kubeconfig file")
17+
args = parser.parse_args()
18+
19+
#Getting kubeConfig and Generate ClientSets
20+
config = client.Configuration(kubeconfig=args.kubeconfig)
21+
clients = client.K8sClient(conf = config.get_config())
22+
logging.info("Experiment Name: %s", args.name)
23+
24+
# invoke the corresponding experiment based on the the (-name) flag
25+
if args.name == "pod-delete":
26+
podDelete.PodDelete(clients)
27+
else:
28+
logging.error("Unsupported -name %s, please provide the correct value of -name args", args.name)
29+
return
30+
if __name__ == "__main__":
31+
main()
32+

0 commit comments

Comments
 (0)