Skip to content

Commit 3a0f746

Browse files
committed
added client and cofiguration
Signed-off-by: Oum Kale <[email protected]>
1 parent ba16633 commit 3a0f746

Some content is hidden

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

66 files changed

+2252
-458
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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ jobs:
2424
script:
2525
- make chaostest
2626

27+
2728
notifications:
2829
email:
2930
recipients:

Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,17 @@ DOCKER_TAG ?= ci
1616
help:
1717
@echo ""
1818
@echo "Usage:-"
19+
@echo "\tmake deps -- sets up dependencies for image build"
1920
@echo "\tmake litmuspython -- will build and push the litmus-python image"
20-
@echo "\tmake chaostest -- will build and push python experiment images
21+
@echo "\tmake chaostest -- will build and push python experiment images
2122
@echo ""
2223

2324

2425
deps: _build_check_docker
2526
@echo ""
2627
@echo "INFO:\tverifying dependencies for litmus-python ..."
2728

29+
.PHONY: litmuspython
2830
_build_tests_litmus_python_image:
2931
@echo "INFO: Building container image for performing chaostoolkit tests"
3032
docker build -t litmuschaos/litmus-python:ci .
@@ -36,7 +38,7 @@ _push_tests_litmus_python_image:
3638

3739
litmuspython: deps _build_tests_litmus_python_image _push_tests_litmus_python_image
3840

39-
41+
.PHONY: chaostest
4042
_build_tests_chaostest_image:
4143
@echo "INFO: Building container image for performing chaostoolkit tests"
4244
cd byoc && docker build -t litmuschaos/chaostoolkit:ci .

bin/experiment/chaosresult.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
apiVersion: litmuschaos.io/v1alpha1
3+
kind: ChaosResult
4+
metadata:
5+
name: "pod-delete-pod-delete"
6+
namespace: "litmus"
7+
labels: {'component': 'litmusportal-frontend', 'pod-template-hash': '64898fdcc8', 'name': 'pod-delete-pod-delete'}
8+
spec:
9+
engine: "pod-delete"
10+
experiment: "pod-delete"
11+
status:
12+
experimentStatus:
13+
phase: "Completed"
14+
verdict: "Pass"
15+
probeSuccessPercentage: "100"
16+
failStep: "N/A"
17+
history:
18+
passedRuns: 1
19+
failedRuns: 0
20+
stoppedRuns: 0

bin/experiment/experiment.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import argparse
55
import os
66
import logging
7+
from pkg.utils.client.client import Configs, Client
8+
79
logging.basicConfig(format='time=%(asctime)s level=%(levelname)s msg=%(message)s', level=logging.INFO)
810
def main():
911
parser = argparse.ArgumentParser()
@@ -21,11 +23,13 @@ def main():
2123
help="Kubernetes client ignore SSL")
2224
args = parser.parse_args()
2325

26+
config = Configs(kubeContext=args.kubeContext)
27+
clients = Client(conf = config.get_config())
2428
logging.info("Experiment Name: {}".format(args.experimentName))
2529

2630
# invoke the corresponding experiment based on the the (-name) flag
2731
if args.experimentName == "pod-delete":
28-
podDelete.PodDelete()
32+
podDelete.PodDelete(clients)
2933
else:
3034
logging.warning("Unsupported -name {}, please provide the correct value of -name args".format(args.experimentName))
3135
return

build/lib/bin/__init__.py

Whitespace-only changes.

build/lib/bin/experiment/__init__.py

Whitespace-only changes.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
apiVersion: litmuschaos.io/v1alpha1
3+
kind: ChaosResult
4+
metadata:
5+
name: "pod-delete-pod-delete"
6+
namespace: "litmus"
7+
labels: {'component': 'litmusportal-frontend', 'pod-template-hash': '64898fdcc8', 'name': 'pod-delete-pod-delete'}
8+
spec:
9+
engine: "pod-delete"
10+
experiment: "pod-delete"
11+
status:
12+
experimentStatus:
13+
phase: "Completed"
14+
verdict: "Pass"
15+
probeSuccessPercentage: "100"
16+
failStep: "N/A"
17+
history:
18+
passedRuns: 1
19+
failedRuns: 0
20+
stoppedRuns: 0
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env python3
2+
3+
import experimentList.generic.podDelete.podDelete as podDelete
4+
import argparse
5+
import os
6+
import logging
7+
from pkg.utils.client.client import Configs, Client
8+
9+
logging.basicConfig(format='time=%(asctime)s level=%(levelname)s msg=%(message)s', level=logging.INFO)
10+
def main():
11+
parser = argparse.ArgumentParser()
12+
13+
# parse the experiment name
14+
parser.add_argument("-experimentName", action='store',
15+
default="pod-delete",
16+
dest="experimentName",
17+
help="Chaos experiment to chose for execution"
18+
)
19+
parser.add_argument("-kubeContext",
20+
required=False,
21+
default=os.environ.get("KUBECONFIG", ""),
22+
dest='kubeContext',
23+
help="Kubernetes client ignore SSL")
24+
args = parser.parse_args()
25+
26+
config = Configs(kubeContext=args.kubeContext)
27+
clients = Client(conf = config.get_config())
28+
logging.info("Experiment Name: {}".format(args.experimentName))
29+
30+
# invoke the corresponding experiment based on the the (-name) flag
31+
if args.experimentName == "pod-delete":
32+
podDelete.PodDelete(clients)
33+
else:
34+
logging.warning("Unsupported -name {}, please provide the correct value of -name args".format(args.experimentName))
35+
return
36+
if __name__ == "__main__":
37+
main()
38+

build/lib/chaosLib/__init__.py

Whitespace-only changes.

build/lib/chaosLib/litmus/__init__.py

Whitespace-only changes.

build/lib/chaosLib/litmus/poddelete/__init__.py

Whitespace-only changes.

build/lib/chaosLib/litmus/poddelete/lib/__init__.py

Whitespace-only changes.
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
2+
import pkg.types.types as types
3+
import pkg.events.events as events
4+
from kubernetes import client, config
5+
import time
6+
import logging
7+
logging.basicConfig(format='time=%(asctime)s level=%(levelname)s msg=%(message)s', level=logging.INFO)
8+
import pkg.utils.common.common as common
9+
from pkg.utils.common.pods import Pods
10+
from datetime import datetime
11+
from pkg.status.application import Application
12+
import pkg.maths.maths as maths
13+
import os
14+
15+
#PreparePodDelete contains the prepration steps before chaos injection
16+
def PreparePodDelete(experimentsDetails , resultDetails, eventsDetails, chaosDetails, clients):
17+
18+
#Waiting for the ramp time before chaos injection
19+
if experimentsDetails.RampTime != 0 :
20+
logging.info("[Ramp]: Waiting for the %s ramp time before injecting chaos",(experimentsDetails.RampTime))
21+
common.WaitForDuration(experimentsDetails.RampTime)
22+
23+
if experimentsDetails.Sequence.lower() == "serial":
24+
err = injectChaosInSerialMode(experimentsDetails, chaosDetails, eventsDetails, resultDetails, clients)
25+
if err != None:
26+
return err
27+
elif experimentsDetails.Sequence.lower() == "parallel":
28+
err = injectChaosInParallelMode(experimentsDetails, chaosDetails, eventsDetails, resultDetails, clients)
29+
if err != None:
30+
return err
31+
else:
32+
logging.warning("[Warning]: %s sequence is not supported",(experimentsDetails.Sequence))
33+
34+
#Waiting for the ramp time after chaos injection
35+
if experimentsDetails.RampTime != 0 :
36+
logging.info("[Ramp]: Waiting for the %s ramp time after injecting chaos",(experimentsDetails.RampTime))
37+
common.WaitForDuration(experimentsDetails.RampTime)
38+
return None
39+
40+
# injectChaosInSerialMode delete the target application pods serial mode(one by one)
41+
def injectChaosInSerialMode(experimentsDetails , chaosDetails , eventsDetails , resultDetails, clients):
42+
43+
status = Application()
44+
45+
pods = Pods()
46+
GracePeriod = 0
47+
48+
#ChaosStartTimeStamp contains the start timestamp, when the chaos injection begin
49+
ChaosStartTimeStamp = datetime.now()
50+
duration = (datetime.now() - ChaosStartTimeStamp).seconds
51+
52+
while duration < experimentsDetails.ChaosDuration:
53+
# Get the target pod details for the chaos execution
54+
# if the target pod is not defined it will derive the random target pod list using pod affected percentage
55+
if experimentsDetails.TargetPods == "" and chaosDetails.AppDetail.Label == "" :
56+
return logging.warning("[Warning]: Please provide one of the appLabel or TARGET_PODS")
57+
58+
targetPodList, err = pods.GetPodList(experimentsDetails.TargetPods, experimentsDetails.PodsAffectedPerc, chaosDetails, clients)
59+
if err != None:
60+
return err
61+
62+
podNames = []
63+
for pod in targetPodList.items:
64+
podNames.append(pod.metadata.name)
65+
66+
logging.info("[Info]: Target pods list, %s",(podNames))
67+
68+
if experimentsDetails.EngineName != "" :
69+
msg = "Injecting " + experimentsDetails.ExperimentName + " chaos on application pod"
70+
types.SetEngineEventAttributes(eventsDetails, types.ChaosInject, msg, "Normal", chaosDetails)
71+
events.GenerateEvents(eventsDetails, chaosDetails, "ChaosEngine", clients)
72+
73+
#Deleting the application pod
74+
for pod in targetPodList.items :
75+
76+
logging.info("[Info]: Killing the following pods, PodName : %s", pod.metadata.name)
77+
try:
78+
if experimentsDetails.Force == True:
79+
err = clients.clientk8s.delete_namespaced_pod(pod.metadata.name, experimentsDetails.AppNS, grace_period_seconds=GracePeriod)
80+
else:
81+
err = clients.clientk8s.delete_namespaced_pod(pod.metadata.name, experimentsDetails.AppNS)
82+
except Exception as e:
83+
return e
84+
85+
if chaosDetails.Randomness == True :
86+
err = common.RandomInterval(experimentsDetails.ChaosInterval)
87+
if err != None:
88+
return err
89+
else:
90+
#Waiting for the chaos interval after chaos injection
91+
if experimentsDetails.ChaosInterval != "":
92+
logging.info("[Wait]: Wait for the chaos interval %s",(experimentsDetails.ChaosInterval))
93+
waitTime = maths.atoi(experimentsDetails.ChaosInterval)
94+
common.WaitForDuration(waitTime)
95+
96+
#Verify the status of pod after the chaos injection
97+
logging.info("[Status]: Verification for the recreation of application pod")
98+
err = status.CheckApplicationStatus(experimentsDetails.AppNS, experimentsDetails.AppLabel, experimentsDetails.Timeout, experimentsDetails.Delay,clients)
99+
if err != None:
100+
return err
101+
102+
duration = (datetime.now() - ChaosStartTimeStamp).seconds
103+
104+
logging.info("[Completion]: %s chaos is done",(experimentsDetails.ExperimentName))
105+
106+
return None
107+
108+
# injectChaosInParallelMode delete the target application pods in parallel mode (all at once)
109+
def injectChaosInParallelMode(experimentsDetails , chaosDetails , eventsDetails , resultDetails, clients):
110+
111+
status = Application()
112+
pods = Pods()
113+
114+
GracePeriod = 0
115+
116+
#ChaosStartTimeStamp contains the start timestamp, when the chaos injection begin
117+
ChaosStartTimeStamp = datetime.now()
118+
duration = (datetime.now() - ChaosStartTimeStamp).seconds
119+
120+
while duration < experimentsDetails.ChaosDuration:
121+
# Get the target pod details for the chaos execution
122+
# if the target pod is not defined it will derive the random target pod list using pod affected percentage
123+
if experimentsDetails.TargetPods == "" and chaosDetails.AppDetail.Label == "" :
124+
return logging.info("[Warning]: Please provide one of the appLabel or TARGET_PODS")
125+
126+
targetPodList, err = pods.GetPodList(experimentsDetails.TargetPods, experimentsDetails.PodsAffectedPerc, chaosDetails, clients)
127+
if err != None:
128+
return err
129+
podNames = []
130+
for pod in targetPodList.items:
131+
podNames.append(str(pod.metadata.name))
132+
133+
logging.info("[Info]: Target pods list for chaos, %s",(podNames))
134+
135+
if experimentsDetails.EngineName != "" :
136+
msg = "Injecting " + experimentsDetails.ExperimentName + " chaos on application pod"
137+
types.SetEngineEventAttributes(eventsDetails, types.ChaosInject, msg, "Normal", chaosDetails)
138+
events.GenerateEvents(eventsDetails, chaosDetails, "ChaosEngine",clients)
139+
140+
#Deleting the application pod
141+
for pod in targetPodList.items:
142+
logging.info("[Info]: Killing the following pods, PodName : %s", pod.metadata.name)
143+
try:
144+
if experimentsDetails.Force == True:
145+
clients.clientk8s.delete_namespaced_pod(pod.metadata.name, experimentsDetails.AppNS, grace_period_seconds=GracePeriod)
146+
else:
147+
clients.clientk8s.delete_namespaced_pod(pod.metadata.name, experimentsDetails.AppNS)
148+
except Exception as err:
149+
return err
150+
151+
if chaosDetails.Randomness == True:
152+
err = common.RandomInterval(experimentsDetails.ChaosInterval)
153+
if err != None:
154+
return err
155+
else:
156+
#Waiting for the chaos interval after chaos injection
157+
if experimentsDetails.ChaosInterval != "" :
158+
logging.info("[Wait]: Wait for the chaos interval %s", experimentsDetails.ChaosInterval)
159+
waitTime = maths.atoi(experimentsDetails.ChaosInterval)
160+
common.WaitForDuration(waitTime)
161+
162+
#Verify the status of pod after the chaos injection
163+
logging.info("[Status]: Verification for the recreation of application pod")
164+
err = status.CheckApplicationStatus(experimentsDetails.AppNS, experimentsDetails.AppLabel, experimentsDetails.Timeout, experimentsDetails.Delay, clients)
165+
if err != None:
166+
return err
167+
duration = (datetime.now() - ChaosStartTimeStamp).seconds
168+
169+
logging.info("[Completion]: %s chaos is done",(experimentsDetails.ExperimentName))
170+
171+
return None

build/lib/experimentList/__init__.py

Whitespace-only changes.

build/lib/experimentList/generic/__init__.py

Whitespace-only changes.

build/lib/experimentList/generic/podDelete/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)