Skip to content

Commit 34b328f

Browse files
authored
Merge branch 'master' into golang-vulnerability-fix
2 parents 74d20d4 + f16249f commit 34b328f

File tree

31 files changed

+1717
-197
lines changed

31 files changed

+1717
-197
lines changed

Diff for: bin/experiment/experiment.go

+15-3
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ import (
5656
ebsLossByTag "github.com/litmuschaos/litmus-go/experiments/kube-aws/ebs-loss-by-tag/experiment"
5757
ec2TerminateByID "github.com/litmuschaos/litmus-go/experiments/kube-aws/ec2-terminate-by-id/experiment"
5858
ec2TerminateByTag "github.com/litmuschaos/litmus-go/experiments/kube-aws/ec2-terminate-by-tag/experiment"
59-
springBootChaos "github.com/litmuschaos/litmus-go/experiments/spring-boot/spring-boot-chaos/experiment"
59+
springBootAppKill "github.com/litmuschaos/litmus-go/experiments/spring-boot/spring-boot-app-kill/experiment"
60+
springBootCpuStress "github.com/litmuschaos/litmus-go/experiments/spring-boot/spring-boot-cpu-stress/experiment"
61+
springBootExceptions "github.com/litmuschaos/litmus-go/experiments/spring-boot/spring-boot-exceptions/experiment"
62+
springBootLatency "github.com/litmuschaos/litmus-go/experiments/spring-boot/spring-boot-latency/experiment"
63+
springBootMemoryStress "github.com/litmuschaos/litmus-go/experiments/spring-boot/spring-boot-memory-stress/experiment"
6064
vmpoweroff "github.com/litmuschaos/litmus-go/experiments/vmware/vm-poweroff/experiment"
6165

6266
"github.com/litmuschaos/litmus-go/pkg/clients"
@@ -182,8 +186,16 @@ func main() {
182186
gcpVMInstanceStopByLabel.GCPVMInstanceStopByLabel(clients)
183187
case "gcp-vm-disk-loss-by-label":
184188
gcpVMDiskLossByLabel.GCPVMDiskLossByLabel(clients)
185-
case "spring-boot-chaos":
186-
springBootChaos.Experiment(clients)
189+
case "spring-boot-cpu-stress":
190+
springBootCpuStress.Experiment(clients)
191+
case "spring-boot-memory-stress":
192+
springBootMemoryStress.Experiment(clients)
193+
case "spring-boot-latency":
194+
springBootLatency.Experiment(clients)
195+
case "spring-boot-exceptions":
196+
springBootExceptions.Experiment(clients)
197+
case "spring-boot-app-kill":
198+
springBootAppKill.Experiment(clients)
187199
default:
188200
log.Errorf("Unsupported -name %v, please provide the correct value of -name args", *experimentName)
189201
return

Diff for: chaoslib/litmus/azure-disk-loss/lib/azure-disk-loss.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ func abortWatcher(experimentsDetails *experimentTypes.ExperimentDetails, attache
275275
}
276276
if diskStatusString != "Attached" {
277277
if err := diskStatus.AttachDisk(experimentsDetails.SubscriptionID, experimentsDetails.ResourceGroup, instanceName, experimentsDetails.ScaleSet, diskList); err != nil {
278-
log.Errorf("failed to attach disk '%v, manual revert required, err: %v", err)
278+
log.Errorf("failed to attach disk, manual revert required, err: %v", err)
279279
} else {
280280
common.SetTargets(*disk.Name, "re-attached", "VirtualDisk", chaosDetails)
281281
}

Diff for: chaoslib/litmus/node-memory-hog/lib/node-memory-hog.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ func calculateMemoryConsumption(experimentsDetails *experimentTypes.ExperimentDe
284284
//Get the percentage of memory under chaos wrt allocatable memory
285285
totalMemoryConsumption = int((float64(memoryForChaos) / float64(memoryAllocatable)) * 100)
286286
if totalMemoryConsumption > 100 {
287-
log.Infof("[Info]: PercentageOfMemoryCapacity To Be Used: %d percent, which is more than 100 percent (%d percent) of Allocatable Memory, so the experiment will only consume upto 100 percent of Allocatable Memory", experimentsDetails.MemoryConsumptionPercentage, totalMemoryConsumption)
287+
log.Infof("[Info]: PercentageOfMemoryCapacity To Be Used: %v percent, which is more than 100 percent (%d percent) of Allocatable Memory, so the experiment will only consume upto 100 percent of Allocatable Memory", experimentsDetails.MemoryConsumptionPercentage, totalMemoryConsumption)
288288
MemoryConsumption = "100%"
289289
} else {
290290
log.Infof("[Info]: PercentageOfMemoryCapacity To Be Used: %v percent, which is %d percent of Allocatable Memory", experimentsDetails.MemoryConsumptionPercentage, totalMemoryConsumption)

Diff for: chaoslib/litmus/spring-boot-chaos/lib/spring-boot-chaos.go

+2-13
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,6 @@ func PrepareChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients
6464
"Controller": experimentsDetails.ChaosMonkeyWatchers.Controller,
6565
"RestController": experimentsDetails.ChaosMonkeyWatchers.RestController,
6666
})
67-
log.InfoWithValues("[Info]: Chaos monkeys assaults will be injected to the target pods as follows", logrus.Fields{
68-
"CPU Assault": experimentsDetails.ChaosMonkeyAssault.CPUActive,
69-
"Memory Assault": experimentsDetails.ChaosMonkeyAssault.MemoryActive,
70-
"Kill App Assault": experimentsDetails.ChaosMonkeyAssault.KillApplicationActive,
71-
"Latency Assault": experimentsDetails.ChaosMonkeyAssault.LatencyActive,
72-
"Exception Assault": experimentsDetails.ChaosMonkeyAssault.ExceptionsActive,
73-
})
7467

7568
switch strings.ToLower(experimentsDetails.Sequence) {
7669
case "serial":
@@ -156,12 +149,8 @@ func setChaosMonkeyWatchers(chaosMonkeyPort string, chaosMonkeyPath string, watc
156149
return nil
157150
}
158151

159-
func startAssault(chaosMonkeyPort string, chaosMonkeyPath string, assault experimentTypes.ChaosMonkeyAssault, pod corev1.Pod) error {
160-
jsonValue, err := json.Marshal(assault)
161-
if err != nil {
162-
return err
163-
}
164-
if err := setChaosMonkeyAssault(chaosMonkeyPort, chaosMonkeyPath, jsonValue, pod); err != nil {
152+
func startAssault(chaosMonkeyPort string, chaosMonkeyPath string, assault []byte, pod corev1.Pod) error {
153+
if err := setChaosMonkeyAssault(chaosMonkeyPort, chaosMonkeyPath, assault, pod); err != nil {
165154
return err
166155
}
167156
log.Infof("[Chaos]: Activating Chaos Monkey assault on pod: %v", pod.Name)

Diff for: experiments/spring-boot/README.md

-15
This file was deleted.
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## Experiment Metadata
2+
3+
<table>
4+
<tr>
5+
<th> Name </th>
6+
<th> Description </th>
7+
<th> Documentation Link </th>
8+
</tr>
9+
<tr>
10+
<td> Spring Boot App Kill </td>
11+
<td> This experiment allows injecting Chaos Monkey app-kill assaults on Spring Boot applications, which have the [Chaos Monkey for Spring Boot](https://codecentric.github.io/chaos-monkey-spring-boot/) in their classpath. It can target random pods with a Spring Boot application and allows configuring the assaults to inject app-kill. It tests the resiliency of the system when some applications are having unexpected faulty behavior.</td>
12+
<td> TODO </td>
13+
</tr>
14+
</table>
15+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
package experiment
2+
3+
import (
4+
"os"
5+
6+
"github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1"
7+
litmusLIB "github.com/litmuschaos/litmus-go/chaoslib/litmus/spring-boot-chaos/lib"
8+
"github.com/litmuschaos/litmus-go/pkg/clients"
9+
"github.com/litmuschaos/litmus-go/pkg/events"
10+
"github.com/litmuschaos/litmus-go/pkg/log"
11+
"github.com/litmuschaos/litmus-go/pkg/probe"
12+
"github.com/litmuschaos/litmus-go/pkg/result"
13+
experimentEnv "github.com/litmuschaos/litmus-go/pkg/spring-boot/spring-boot-chaos/environment"
14+
experimentTypes "github.com/litmuschaos/litmus-go/pkg/spring-boot/spring-boot-chaos/types"
15+
"github.com/litmuschaos/litmus-go/pkg/status"
16+
"github.com/litmuschaos/litmus-go/pkg/types"
17+
"github.com/litmuschaos/litmus-go/pkg/utils/common"
18+
"github.com/sirupsen/logrus"
19+
)
20+
21+
// Experiment contains steps to inject chaos
22+
func Experiment(clients clients.ClientSets) {
23+
24+
experimentsDetails := experimentTypes.ExperimentDetails{}
25+
resultDetails := types.ResultDetails{}
26+
eventsDetails := types.EventDetails{}
27+
chaosDetails := types.ChaosDetails{}
28+
29+
//Fetching all the ENV passed from the runner pod
30+
log.Infof("[PreReq]: Getting the ENV for the %v experiment", os.Getenv("EXPERIMENT_NAME"))
31+
experimentEnv.GetENV(&experimentsDetails, "spring-boot-app-kill")
32+
33+
// Initialize the chaos attributes
34+
types.InitialiseChaosVariables(&chaosDetails)
35+
36+
// Initialize Chaos Result Parameters
37+
types.SetResultAttributes(&resultDetails, chaosDetails)
38+
39+
if experimentsDetails.EngineName != "" {
40+
// Initialize the probe details. Bail out upon error, as we haven't entered exp business logic yet
41+
if err := probe.InitializeProbesInChaosResultDetails(&chaosDetails, clients, &resultDetails); err != nil {
42+
log.Errorf("Unable to initialize the probes, err: %v", err)
43+
return
44+
}
45+
}
46+
47+
//Updating the chaos result in the beginning of experiment
48+
log.Infof("[PreReq]: Updating the chaos result of %v experiment (SOT)", experimentsDetails.ExperimentName)
49+
if err := result.ChaosResult(&chaosDetails, clients, &resultDetails, "SOT"); err != nil {
50+
log.Errorf("Unable to Create the Chaos Result, err: %v", err)
51+
failStep := "[pre-chaos]: Failed to update the chaos result of spring-boot-chaos experiment (SOT), err: " + err.Error()
52+
result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails)
53+
return
54+
}
55+
56+
// Set the chaos result uid
57+
_ = result.SetResultUID(&resultDetails, clients, &chaosDetails)
58+
59+
// generating the event in chaosResult to mark the verdict as awaited
60+
msg := "experiment: " + experimentsDetails.ExperimentName + ", Result: Awaited"
61+
types.SetResultEventAttributes(&eventsDetails, types.AwaitedVerdict, msg, "Normal", &resultDetails)
62+
_ = events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosResult")
63+
64+
//DISPLAY THE APP INFORMATION
65+
log.InfoWithValues("[Info]: The application information is as follows", logrus.Fields{
66+
"Namespace": experimentsDetails.AppNS,
67+
"Label": experimentsDetails.AppLabel,
68+
"Chaos Duration": experimentsDetails.ChaosDuration,
69+
})
70+
71+
// Calling AbortWatcher go routine, it will continuously watch for the abort signal and generate the required events and result
72+
go common.AbortWatcherWithoutExit(experimentsDetails.ExperimentName, clients, &resultDetails, &chaosDetails, &eventsDetails)
73+
74+
// Select targeted pods
75+
log.Infof("[PreCheck]: Geting targeted pods list")
76+
if err := litmusLIB.SetTargetPodList(&experimentsDetails, clients, &chaosDetails); err != nil {
77+
log.Errorf("Failed to get target pod list, err: %v", err)
78+
failStep := "[pre-chaos]: Failed to get pod list, err: " + err.Error()
79+
types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, "Pods: Not Found", "Warning", &chaosDetails)
80+
_ = events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine")
81+
result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails)
82+
return
83+
}
84+
podNames := make([]string, 0, 1)
85+
for _, pod := range experimentsDetails.TargetPodList.Items {
86+
podNames = append(podNames, pod.Name)
87+
}
88+
log.Infof("[PreCheck]: Target pods list for chaos, %v", podNames)
89+
90+
// Check if the targeted pods have the chaos monkey endpoint
91+
log.Infof("[PreCheck]: Checking for ChaosMonkey endpoint in target pods")
92+
if _, err := litmusLIB.CheckChaosMonkey(experimentsDetails.ChaosMonkeyPort, experimentsDetails.ChaosMonkeyPath, experimentsDetails.TargetPodList); err != nil {
93+
log.Errorf("Some target pods don't have the chaos monkey endpoint, err: %v", err)
94+
failStep := "[pre-chaos]: Some target pods don't have the chaos monkey endpoint, err: " + err.Error()
95+
types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, "ChaosMonkey: Not Found", "Warning", &chaosDetails)
96+
_ = events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine")
97+
result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails)
98+
return
99+
}
100+
101+
//PRE-CHAOS APPLICATION STATUS CHECK
102+
if chaosDetails.DefaultHealthCheck {
103+
log.Info("[Status]: Verify that the AUT (Application Under Test) is running (pre-chaos)")
104+
if err := status.AUTStatusCheck(experimentsDetails.AppNS, experimentsDetails.AppLabel, experimentsDetails.TargetContainer, experimentsDetails.Timeout, experimentsDetails.Delay, clients, &chaosDetails); err != nil {
105+
log.Errorf("Application status check failed, err: %v", err)
106+
failStep := "[pre-chaos]: Failed to verify that the AUT (Application Under Test) is in running state, err: " + err.Error()
107+
types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, "AUT: Not Running", "Warning", &chaosDetails)
108+
_ = events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine")
109+
result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails)
110+
return
111+
}
112+
}
113+
114+
if experimentsDetails.EngineName != "" {
115+
// marking AUT as running, as we already checked the status of application under test
116+
msg := "AUT: Running"
117+
118+
// run the probes in the pre-chaos check
119+
if len(resultDetails.ProbeDetails) != 0 {
120+
if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil {
121+
log.Errorf("Probe Failed, err: %v", err)
122+
failStep := "[pre-chaos]: Failed while running probes, err: " + err.Error()
123+
msg := "AUT: Running, Probes: Unsuccessful"
124+
types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails)
125+
_ = events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine")
126+
result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails)
127+
return
128+
}
129+
msg = "AUT: Running, Probes: Successful"
130+
}
131+
// generating the events for the pre-chaos check
132+
types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Normal", &chaosDetails)
133+
_ = events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine")
134+
}
135+
136+
// Including the litmus lib
137+
switch experimentsDetails.ChaosLib {
138+
case "litmus":
139+
if err := litmusLIB.PrepareChaos(&experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil {
140+
log.Errorf("Chaos injection failed, err: %v", err)
141+
failStep := "[chaos]: Failed inside the chaoslib, err: " + err.Error()
142+
result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails)
143+
return
144+
}
145+
default:
146+
log.Error("[Invalid]: Please Provide the correct LIB")
147+
failStep := "[chaos]: no match found for specified lib"
148+
result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails)
149+
return
150+
}
151+
152+
log.Infof("[Confirmation]: %v chaos has been injected successfully", experimentsDetails.ExperimentName)
153+
resultDetails.Verdict = v1alpha1.ResultVerdictPassed
154+
155+
// POST-CHAOS APPLICATION STATUS CHECK
156+
if chaosDetails.DefaultHealthCheck {
157+
log.Info("[Status]: Verify that the AUT (Application Under Test) is running (post-chaos)")
158+
if err := status.AUTStatusCheck(experimentsDetails.AppNS, experimentsDetails.AppLabel, experimentsDetails.TargetContainer, experimentsDetails.Timeout, experimentsDetails.Delay, clients, &chaosDetails); err != nil {
159+
log.Errorf("Application status check failed, err: %v", err)
160+
failStep := "[post-chaos]: Failed to verify that the AUT (Application Under Test) is running, err: " + err.Error()
161+
types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, "AUT: Not Running", "Warning", &chaosDetails)
162+
_ = events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine")
163+
result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails)
164+
return
165+
}
166+
}
167+
168+
if experimentsDetails.EngineName != "" {
169+
// marking AUT as running, as we already checked the status of application under test
170+
msg := "AUT: Running"
171+
172+
// run the probes in the post-chaos check
173+
if len(resultDetails.ProbeDetails) != 0 {
174+
if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil {
175+
log.Errorf("Probes Failed, err: %v", err)
176+
failStep := "[post-chaos]: Failed while running probes, err: " + err.Error()
177+
msg := "AUT: Running, Probes: Unsuccessful"
178+
types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails)
179+
_ = events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine")
180+
result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails)
181+
return
182+
}
183+
msg = "AUT: Running, Probes: Successful"
184+
}
185+
186+
// generating post chaos event
187+
types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Normal", &chaosDetails)
188+
_ = events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine")
189+
}
190+
191+
//Updating the chaosResult in the end of experiment
192+
log.Infof("[The End]: Updating the chaos result of %v experiment (EOT)", experimentsDetails.ExperimentName)
193+
if err := result.ChaosResult(&chaosDetails, clients, &resultDetails, "EOT"); err != nil {
194+
log.Errorf("Unable to Update the Chaos Result, err: %v", err)
195+
return
196+
}
197+
198+
// generating the event in chaosResult to mark the verdict as pass/fail
199+
msg = "experiment: " + experimentsDetails.ExperimentName + ", Result: " + string(resultDetails.Verdict)
200+
reason := types.PassVerdict
201+
eventType := "Normal"
202+
if resultDetails.Verdict != "Pass" {
203+
reason = types.FailVerdict
204+
eventType = "Warning"
205+
}
206+
types.SetResultEventAttributes(&eventsDetails, reason, msg, eventType, &resultDetails)
207+
_ = events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosResult")
208+
209+
if experimentsDetails.EngineName != "" {
210+
msg := experimentsDetails.ExperimentName + " experiment has been " + string(resultDetails.Verdict) + "ed"
211+
types.SetEngineEventAttributes(&eventsDetails, types.Summary, msg, "Normal", &chaosDetails)
212+
_ = events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine")
213+
}
214+
}
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
apiVersion: v1
2+
kind: ServiceAccount
3+
metadata:
4+
name: spring-boot-app-kill-sa
5+
namespace: podtato
6+
labels:
7+
name: spring-boot-app-kill-sa
8+
---
9+
apiVersion: rbac.authorization.k8s.io/v1
10+
kind: Role
11+
metadata:
12+
name: spring-boot-app-kill-sa
13+
labels:
14+
name: spring-boot-app-kill-sa
15+
rules:
16+
- apiGroups: [ "","litmuschaos.io","batch","apps" ]
17+
resources: [ "pods","deployments","pods/log","events","jobs","pods/exec","statefulsets","configmaps","chaosengines","chaosexperiments","chaosresults" ]
18+
verbs: [ "create","list","get","patch","delete","update" ]
19+
- apiGroups: [ "" ]
20+
resources: [ "nodes" ]
21+
verbs: [ "get","list" ]
22+
---
23+
apiVersion: rbac.authorization.k8s.io/v1
24+
kind: RoleBinding
25+
metadata:
26+
name: spring-boot-app-kill-sa
27+
labels:
28+
name: spring-boot-app-kill-sa
29+
roleRef:
30+
apiGroup: rbac.authorization.k8s.io
31+
kind: Role
32+
name: spring-boot-app-kill-sa
33+
subjects:
34+
- kind: ServiceAccount
35+
name: spring-boot-app-kill-sa
36+
namespace: podtato

0 commit comments

Comments
 (0)