Skip to content

Commit

Permalink
Adding test, readme and rbac for pod-delete experiment and minor docs…
Browse files Browse the repository at this point in the history
… update for sdk (#32)

* adding test, readme, and rbac for pod-delete experiment and docs update for SDK

Signed-off-by: Oum Kale <oumkale@chaosnative.com>
  • Loading branch information
oumkale authored Nov 12, 2021
1 parent e51ebe1 commit c79105d
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 7 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ You can contribute by raising issues, improving the documentation, contributing

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


### Blogs
- [Create Chaos Experiments Using the LitmusChaos Python SDK](https://dev.to/oumkale/create-chaos-experiments-using-the-litmuschaos-python-sdk-4492)

Expand Down
2 changes: 1 addition & 1 deletion bin/experiment/experiment.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3

import experiments.generic.pod_delete.pod_delete as pod_delete
import experiments.generic.pod_delete.experiment.pod_delete as pod_delete
import argparse
import logging
import pkg.utils.client.client as client
Expand Down
10 changes: 5 additions & 5 deletions contribute/developer-guide/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ The *generate_experiment.py* script is a simple way to bootstrap your experiment
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.

### Pre-Requisites

- *python3* is available (`sudo apt-get install python3`)
- *jinja2* & *pyYaml* python packages are available (`sudo apt-get install python3-pip`, `pip install jinja2`, `pip install pyYaml`)

### Steps to Generate Experiment Manifests

- Clone the litmus-python repository & navigate to the `contribute/developer-guide` folder
Expand Down Expand Up @@ -264,6 +259,11 @@ Follow the steps provided below to setup okteto & test the experiment execution.
This dev container inherits the env, serviceaccount & other properties specified on the test deployment & is now suitable for
running the experiment.
- Install dependencies
- Run `curl -L https://storage.googleapis.com/kubernetes-release/release/"v1.18.0"/bin/linux/"amd64"/kubectl -o /usr/local/bin/kubectl && chmod +x /usr/local/bin/kubectl`
- Run `pip3 install -r requirements.txt`
- Run `python3 setup.py install`, run this command for every change in experiment code.
- Execute the experiment against the sample app chosen & verify the steps via logs printed on the console.
```
Expand Down
15 changes: 15 additions & 0 deletions experiments/generic/pod_delete/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## Experiment Metadata

<table>
<tr>
<th> Name </th>
<th> Description </th>
<th> Documentation Link </th>
</tr>
<tr>
<td> Pod Delete </td>
<td> This experiment causes (forced/graceful) pod failure of random replicas of an application deployment. It tests deployment sanity (replica availability & uninterrupted service) and recovery workflows of the application pod </td>
<td> <a href="https://litmuschaos.github.io/litmus/experiments/categories/pods/pod-delete/"> Here </a> </td>
</tr>
</table>

Empty file.
37 changes: 37 additions & 0 deletions experiments/generic/pod_delete/rbac.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: pod-delete-sa
namespace: default
labels:
name: pod-delete-sa
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: pod-delete-sa
namespace: default
labels:
name: pod-delete-sa
rules:
- apiGroups: ["","litmuschaos.io","batch","apps"]
resources: ["pods","deployments","pods/log","events","jobs","chaosengines","chaosexperiments","chaosresults"]
verbs: ["create","list","get","patch","update","delete","deletecollection"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: pod-delete-sa
namespace: default
labels:
name: pod-delete-sa
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: pod-delete-sa
subjects:
- kind: ServiceAccount
name: pod-delete-sa
namespace: default

54 changes: 54 additions & 0 deletions experiments/generic/pod_delete/test/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: litmus-experiment
spec:
replicas: 1
selector:
matchLabels:
app: litmus-experiment
template:
metadata:
labels:
app: litmus-experiment
spec:
serviceAccountName: pod-delete-sa
containers:
- name: gotest
image: busybox
command:
- sleep
- "3600"
env:
- name: APP_NAMESPACE
value: ''

- name: APP_LABEL
value: ''

- name: APP_KIND
value: ''

- name: TOTAL_CHAOS_DURATION
value: ''

- name: CHAOS_INTERVAL
value: ''

- name: FORCE
value: ''

- name: LIB
value: 'litmus'

- name: CHAOS_NAMESPACE
value: ''

- name: RAMP_TIME
value: ''

- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def get_version_from_package() -> str:
'experiments',
'experiments/generic',
'experiments/generic/pod_delete',
'experiments/generic/pod_delete/experiment',
]
needs_pytest = set(['pytest', 'test']).intersection(sys.argv)
package_data = {
Expand Down

0 comments on commit c79105d

Please sign in to comment.