-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
709badd
commit 9254ec2
Showing
6 changed files
with
259 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
### Litmus Scenarios | ||
Kraken consumes [Litmus](https://github.com/litmuschaos/litmus) under the hood for some infrastructure, pod, and node scenarios | ||
|
||
#### Litmus chaos scenarios | ||
There are 3 custom resources that are created during each litmus scenario. Below is a description of the resources: | ||
* ChaosEngine: A resource to link a Kubernetes application or Kubernetes node to a ChaosExperiment. ChaosEngine is watched by Litmus' Chaos-Operator which then invokes Chaos-Experiments | ||
* ChaosExperiment: A resource to group the configuration parameters of a chaos experiment. ChaosExperiment CRs are created by the operator when experiments are invoked by ChaosEngine. | ||
* ChaosResult : A resource to hold the results of a chaos-experiment. The Chaos-exporter reads the results and exports the metrics into a configured Prometheus server. | ||
|
||
Following are the start of scenarios for which a chaos scenario config exists today. Adding a new litmus based scenario is as simple as adding 3 new yaml files under scenarios directory and defining it in the config. | ||
|
||
Component | Description | Working | ||
------------------------ | ---------------------------------------------------------------------------------------------------| ------------------------- | | ||
Node CPU Hog | Chaos scenario that hogs up the CPU on a defined node for a specific amount of time | :heavy_check_mark: | | ||
|
||
**NOTE**: [More scenarios](https://hub.litmuschaos.io/) can be found on this page | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import kraken.invoke.command as runcommand | ||
import logging | ||
import time | ||
import sys | ||
|
||
|
||
# Install litmus and wait until pod is running | ||
def install_litmus(version): | ||
runcommand.invoke("kubectl apply -f " | ||
"https://litmuschaos.github.io/litmus/litmus-operator-%s.yaml" % version) | ||
|
||
runcommand.invoke("oc patch -n litmus deployment.apps/chaos-operator-ce --type=json --patch ' " | ||
"[ { \"op\": \"add\", \"path\": \"/spec/template/spec/containers/0/env/-\", " | ||
"\"value\": { \"name\": \"ANALYTICS\", \"value\": \"FALSE\" } } ]'") | ||
|
||
runcommand.invoke("oc wait deploy -n litmus chaos-operator-ce --for=condition=Available") | ||
|
||
|
||
def deploy_all_experiments(version_string): | ||
|
||
if not version_string.startswith("v"): | ||
logging.error("Incorrect version string for litmus, needs to start with 'v' " | ||
"followed by a number") | ||
sys.exit(1) | ||
version = version_string[1:] | ||
|
||
runcommand.invoke("kubectl apply -f " | ||
"https://hub.litmuschaos.io/api/chaos/%s?file=charts/generic/experiments.yaml" | ||
% version) | ||
|
||
|
||
def delete_experiments(): | ||
runcommand.invoke("kubectl delete chaosengine --all") | ||
|
||
|
||
# Check status of experiment | ||
def check_experiment(engine_name, experiment_name, namespace): | ||
chaos_engine = runcommand.invoke("kubectl get chaosengines/%s -n %s -o jsonpath=" | ||
"'{.status.engineStatus}'" % (engine_name, namespace)) | ||
engine_status = chaos_engine.strip() | ||
max_tries = 30 | ||
engine_counter = 0 | ||
while engine_status.lower() != "running" and engine_status.lower() != "completed": | ||
time.sleep(10) | ||
logging.info("Waiting for engine to start running.") | ||
chaos_engine = runcommand.invoke("kubectl get chaosengines/%s -n %s -o jsonpath=" | ||
"'{.status.engineStatus}'" % (engine_name, namespace)) | ||
engine_status = chaos_engine.strip() | ||
if engine_counter >= max_tries: | ||
logging.error("Chaos engine took longer than 5 minutes to be running or complete") | ||
return False | ||
engine_counter += 1 | ||
# need to see if error in run | ||
if "notfound" in engine_status.lower(): | ||
logging.info("Chaos engine was not found") | ||
return False | ||
|
||
if not chaos_engine: | ||
return False | ||
chaos_result = runcommand.invoke("kubectl get chaosresult %s" | ||
"-%s -n %s -o " | ||
"jsonpath='{.status.experimentstatus.verdict}'" | ||
% (engine_name, experiment_name, namespace)) | ||
result_counter = 0 | ||
status = chaos_result.strip() | ||
while status == "Awaited": | ||
logging.info("Waiting for chaos result to finish, sleeping 10 seconds") | ||
time.sleep(10) | ||
chaos_result = runcommand.invoke("kubectl get chaosresult %s" | ||
"-%s -n %s -o " | ||
"jsonpath='{.status.experimentstatus.verdict}'" | ||
% (engine_name, experiment_name, namespace)) | ||
status = chaos_result.strip() | ||
if result_counter >= max_tries: | ||
logging.error("Chaos results took longer than 5 minutes to get a final result") | ||
return False | ||
result_counter += 1 | ||
if "notfound" in status.lower(): | ||
logging.info("Chaos result was not found") | ||
return False | ||
|
||
if status == "Pass": | ||
return True | ||
else: | ||
chaos_result = runcommand.invoke("kubectl get chaosresult %s" | ||
"-%s -n %s -o jsonpath=" | ||
"'{.status.experimentstatus.failStep}'" % | ||
(engine_name, experiment_name, namespace)) | ||
logging.info("Chaos result failed information: " + str(chaos_result)) | ||
return False | ||
|
||
|
||
# Delete all chaos engines in a given namespace | ||
def delete_chaos(namespace): | ||
runcommand.invoke("kubectl delete chaosengine --all -n " + str(namespace)) | ||
runcommand.invoke("kubectl delete chaosexperiment --all -n " + str(namespace)) | ||
runcommand.invoke("kubectl delete chaosresult --all -n " + str(namespace)) | ||
|
||
|
||
# Uninstall litmus operator | ||
def uninstall_litmus(version): | ||
runcommand.invoke("kubectl delete -f " | ||
"https://litmuschaos.github.io/litmus/litmus-operator-%s.yaml" % version) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
apiVersion: litmuschaos.io/v1alpha1 | ||
kind: ChaosEngine | ||
metadata: | ||
name: nginx-chaos | ||
namespace: default | ||
spec: | ||
# It can be true/false | ||
annotationCheck: 'false' | ||
# It can be active/stop | ||
engineState: 'active' | ||
chaosServiceAccount: node-cpu-hog-sa | ||
monitoring: false | ||
# It can be delete/retain | ||
jobCleanUpPolicy: 'delete' | ||
experiments: | ||
- name: node-cpu-hog | ||
spec: | ||
components: | ||
env: | ||
# set chaos duration (in sec) as desired | ||
- name: TOTAL_CHAOS_DURATION | ||
value: '60' | ||
|
||
# ENTER THE NAME OF THE APPLICATION NODE | ||
- name: APP_NODE | ||
value: 'ip-10-0-146-53.us-east-2.compute.internal' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
--- | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: node-cpu-hog-sa | ||
namespace: default | ||
labels: | ||
name: node-cpu-hog-sa | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1beta1 | ||
kind: ClusterRole | ||
metadata: | ||
name: node-cpu-hog-sa | ||
labels: | ||
name: node-cpu-hog-sa | ||
rules: | ||
- apiGroups: ["","litmuschaos.io","batch","apps"] | ||
resources: ["pods","jobs","events","chaosengines","pods/log","chaosexperiments","chaosresults"] | ||
verbs: ["create","list","get","patch","update","delete"] | ||
- apiGroups: [""] | ||
resources: ["nodes"] | ||
verbs: ["get","list"] | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1beta1 | ||
kind: ClusterRoleBinding | ||
metadata: | ||
name: node-cpu-hog-sa | ||
labels: | ||
name: node-cpu-hog-sa | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: ClusterRole | ||
name: node-cpu-hog-sa | ||
subjects: | ||
- kind: ServiceAccount | ||
name: node-cpu-hog-sa | ||
namespace: default |