Skip to content

Commit 027cad6

Browse files
authored
Chore(stress-chaos): Run CPU chaos with percentage of cpu cores (#482)
* Chore(stress-chaos): Run CPU chaos with percentage of cores Signed-off-by: uditgaurav <[email protected]>
1 parent 4bd3845 commit 027cad6

File tree

7 files changed

+10
-1
lines changed

7 files changed

+10
-1
lines changed

chaoslib/litmus/node-cpu-hog/lib/node-cpu-hog.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,8 @@ func createHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, chao
244244
Args: []string{
245245
"--cpu",
246246
strconv.Itoa(experimentsDetails.NodeCPUcores),
247+
"--cpu-load",
248+
strconv.Itoa(experimentsDetails.CPULoad),
247249
"--timeout",
248250
strconv.Itoa(experimentsDetails.ChaosDuration),
249251
},

chaoslib/litmus/stress-chaos/helper/stress-helper.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ func prepareStressor(experimentDetails *experimentTypes.ExperimentDetails) []str
238238
"Timeout": experimentDetails.ChaosDuration,
239239
})
240240
stressArgs = append(stressArgs, "--cpu "+strconv.Itoa(experimentDetails.CPUcores))
241+
stressArgs = append(stressArgs, " --cpu-load "+strconv.Itoa(experimentDetails.CPULoad))
241242

242243
case "pod-memory-stress":
243244

@@ -510,6 +511,7 @@ func getENV(experimentDetails *experimentTypes.ExperimentDetails) {
510511
experimentDetails.ContainerRuntime = types.Getenv("CONTAINER_RUNTIME", "")
511512
experimentDetails.SocketPath = types.Getenv("SOCKET_PATH", "")
512513
experimentDetails.CPUcores, _ = strconv.Atoi(types.Getenv("CPU_CORES", ""))
514+
experimentDetails.CPULoad, _ = strconv.Atoi(types.Getenv("CPU_LOAD", ""))
513515
experimentDetails.FilesystemUtilizationPercentage, _ = strconv.Atoi(types.Getenv("FILESYSTEM_UTILIZATION_PERCENTAGE", ""))
514516
experimentDetails.FilesystemUtilizationBytes, _ = strconv.Atoi(types.Getenv("FILESYSTEM_UTILIZATION_BYTES", ""))
515517
experimentDetails.NumberOfWorkers, _ = strconv.Atoi(types.Getenv("NUMBER_OF_WORKERS", ""))

chaoslib/litmus/stress-chaos/lib/stress-chaos.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ func getPodEnv(experimentsDetails *experimentTypes.ExperimentDetails, podName st
291291
SetEnv("EXPERIMENT_NAME", experimentsDetails.ExperimentName).
292292
SetEnv("SOCKET_PATH", experimentsDetails.SocketPath).
293293
SetEnv("CPU_CORES", strconv.Itoa(experimentsDetails.CPUcores)).
294+
SetEnv("CPU_LOAD", strconv.Itoa(experimentsDetails.CPULoad)).
294295
SetEnv("FILESYSTEM_UTILIZATION_PERCENTAGE", strconv.Itoa(experimentsDetails.FilesystemUtilizationPercentage)).
295296
SetEnv("FILESYSTEM_UTILIZATION_BYTES", strconv.Itoa(experimentsDetails.FilesystemUtilizationBytes)).
296297
SetEnv("NUMBER_OF_WORKERS", strconv.Itoa(experimentsDetails.NumberOfWorkers)).

pkg/generic/node-cpu-hog/environment/environment.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ func GetENV(experimentDetails *experimentTypes.ExperimentDetails) {
2323
experimentDetails.InstanceID = types.Getenv("INSTANCE_ID", "")
2424
experimentDetails.ChaosPodName = types.Getenv("POD_NAME", "")
2525
experimentDetails.NodeCPUcores, _ = strconv.Atoi(types.Getenv("NODE_CPU_CORE", "0"))
26+
experimentDetails.CPULoad, _ = strconv.Atoi(types.Getenv("CPU_LOAD", "100"))
2627
experimentDetails.LIBImage = types.Getenv("LIB_IMAGE", "litmuschaos/go-runner:latest")
2728
experimentDetails.LIBImagePullPolicy = types.Getenv("LIB_IMAGE_PULL_POLICY", "Always")
2829
experimentDetails.AuxiliaryAppInfo = types.Getenv("AUXILIARY_APPINFO", "")

pkg/generic/node-cpu-hog/types/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ type ExperimentDetails struct {
2020
ChaosNamespace string
2121
ChaosPodName string
2222
NodeCPUcores int
23+
CPULoad int
2324
RunID string
2425
LIBImage string
2526
LIBImagePullPolicy string

pkg/generic/stress-chaos/environment/environment.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ func GetENV(experimentDetails *experimentTypes.ExperimentDetails, expName string
3838

3939
switch expName {
4040
case "pod-cpu-hog":
41-
experimentDetails.CPUcores, _ = strconv.Atoi(types.Getenv("CPU_CORES", "1"))
41+
experimentDetails.CPUcores, _ = strconv.Atoi(types.Getenv("CPU_CORES", "0"))
42+
experimentDetails.CPULoad, _ = strconv.Atoi(types.Getenv("CPU_LOAD", "100"))
4243
experimentDetails.StressType = "pod-cpu-stress"
4344

4445
case "pod-memory-hog":

pkg/generic/stress-chaos/types/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type ExperimentDetails struct {
3333
Sequence string
3434
TerminationGracePeriodSeconds int
3535
CPUcores int
36+
CPULoad int
3637
FilesystemUtilizationPercentage int
3738
FilesystemUtilizationBytes int
3839
NumberOfWorkers int

0 commit comments

Comments
 (0)