Skip to content

Commit

Permalink
Pod experiment fixes (#429)
Browse files Browse the repository at this point in the history
* Fixed issue with pod affected percentage > 100

Signed-off-by: Akash Shrivastava <akash@chaosnative.com>
  • Loading branch information
Akash Shrivastava committed Aug 11, 2021
1 parent 21be0d9 commit 4d41f34
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 16 deletions.
5 changes: 3 additions & 2 deletions chaoslib/litmus/pod-cpu-hog-exec/lib/pod-cpu-hog-exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ func experimentCPU(experimentsDetails *experimentTypes.ExperimentDetails, client

// injectChaosInSerialMode stressed the cpu of all target application serially (one by one)
func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetails, targetPodList corev1.PodList, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error {
// creating err channel to recieve the error from the go routine
stressErr := make(chan error)

// run the probes during chaos
if len(resultDetails.ProbeDetails) != 0 {
Expand All @@ -93,6 +91,9 @@ func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetai

for _, pod := range targetPodList.Items {

// creating err channel to recieve the error from the go routine
stressErr := make(chan error)

if experimentsDetails.EngineName != "" {
msg := "Injecting " + experimentsDetails.ExperimentName + " chaos on " + pod.Name + " pod"
types.SetEngineEventAttributes(eventsDetails, types.ChaosInject, msg, "Normal", chaosDetails)
Expand Down
2 changes: 1 addition & 1 deletion chaoslib/litmus/pod-dns-chaos/lib/pod-dns-chaos.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetai

//Deleting all the helper pod for pod-dns chaos
log.Info("[Cleanup]: Deleting the the helper pod")
if err = common.DeletePod(experimentsDetails.ExperimentName+"-"+runID, appLabel, experimentsDetails.ChaosNamespace, chaosDetails.Timeout, chaosDetails.Delay, clients); err != nil {
if err = common.DeletePod(experimentsDetails.ExperimentName+"-helper-"+runID, appLabel, experimentsDetails.ChaosNamespace, chaosDetails.Timeout, chaosDetails.Delay, clients); err != nil {
return errors.Errorf("Unable to delete the helper pods, err: %v", err)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ func experimentMemory(experimentsDetails *experimentTypes.ExperimentDetails, cli

// injectChaosInSerialMode stressed the memory of all target application serially (one by one)
func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetails, targetPodList corev1.PodList, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error {
// creating err channel to recieve the error from the go routine
stressErr := make(chan error)

// run the probes during chaos
if len(resultDetails.ProbeDetails) != 0 {
Expand All @@ -102,6 +100,9 @@ func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetai

for _, pod := range targetPodList.Items {

// creating err channel to recieve the error from the go routine
stressErr := make(chan error)

if experimentsDetails.EngineName != "" {
msg := "Injecting " + experimentsDetails.ExperimentName + " chaos on " + pod.Name + " pod"
types.SetEngineEventAttributes(eventsDetails, types.ChaosInject, msg, "Normal", chaosDetails)
Expand Down
12 changes: 4 additions & 8 deletions experiments/generic/pod-autoscaler/experiment/pod-autoscaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ func PodAutoscaler(clients clients.ClientSets) {
if err := status.AUTStatusCheck(experimentsDetails.AppNS, experimentsDetails.AppLabel, experimentsDetails.TargetContainer, experimentsDetails.Timeout, experimentsDetails.Delay, clients, &chaosDetails); err != nil {
log.Errorf("Application status check failed, err: %v", err)
failStep := "Verify that the AUT (Application Under Test) is running (pre-chaos)"
types.SetResultAfterCompletion(&resultDetails, "Fail", "Completed", failStep)
result.ChaosResult(&chaosDetails, clients, &resultDetails, "EOT")
result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails)
return
}
if experimentsDetails.EngineName != "" {
Expand Down Expand Up @@ -108,15 +107,13 @@ func PodAutoscaler(clients clients.ClientSets) {
if err := litmusLIB.PreparePodAutoscaler(&experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil {
log.Errorf("Chaos injection failed, err: %v", err)
failStep := "failed in chaos injection phase"
types.SetResultAfterCompletion(&resultDetails, "Fail", "Completed", failStep)
result.ChaosResult(&chaosDetails, clients, &resultDetails, "EOT")
result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails)
return
}
default:
log.Error("[Invalid]: Please Provide the correct LIB")
failStep := "no match found for specified lib"
types.SetResultAfterCompletion(&resultDetails, "Fail", "Completed", failStep)
result.ChaosResult(&chaosDetails, clients, &resultDetails, "EOT")
result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails)
return
}

Expand All @@ -128,8 +125,7 @@ func PodAutoscaler(clients clients.ClientSets) {
if err := status.AUTStatusCheck(experimentsDetails.AppNS, experimentsDetails.AppLabel, experimentsDetails.TargetContainer, experimentsDetails.Timeout, experimentsDetails.Delay, clients, &chaosDetails); err != nil {
log.Errorf("Application status check failed, err: %v", err)
failStep := "Verify that the AUT (Application Under Test) is running (post-chaos)"
types.SetResultAfterCompletion(&resultDetails, "Fail", "Completed", failStep)
result.ChaosResult(&chaosDetails, clients, &resultDetails, "EOT")
result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails)
return
}
if experimentsDetails.EngineName != "" {
Expand Down
2 changes: 1 addition & 1 deletion pkg/generic/pod-cpu-hog-exec/environment/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func GetENV(experimentDetails *experimentTypes.ExperimentDetails) {
experimentDetails.Timeout, _ = strconv.Atoi(common.Getenv("STATUS_CHECK_TIMEOUT", "180"))
experimentDetails.TargetPods = common.Getenv("TARGET_PODS", "")
experimentDetails.ChaosInjectCmd = common.Getenv("CHAOS_INJECT_COMMAND", "md5sum /dev/zero")
experimentDetails.ChaosKillCmd = common.Getenv("CHAOS_KILL_COMMAND", "killall md5sum")
experimentDetails.ChaosKillCmd = common.Getenv("CHAOS_KILL_COMMAND", "kill $(find /proc -name exe -lname '*/md5sum' 2>&1 | grep -v 'Permission denied' | awk -F/ '{print $(NF-1)}')")
experimentDetails.TargetContainer = common.Getenv("TARGET_CONTAINER", "")
experimentDetails.Sequence = common.Getenv("SEQUENCE", "parallel")
experimentDetails.TerminationGracePeriodSeconds, _ = strconv.Atoi(common.Getenv("TERMINATION_GRACE_PERIOD_SECONDS", ""))
Expand Down
2 changes: 1 addition & 1 deletion pkg/generic/pod-memory-hog-exec/environment/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func GetENV(experimentDetails *experimentTypes.ExperimentDetails) {
experimentDetails.Delay, _ = strconv.Atoi(common.Getenv("STATUS_CHECK_DELAY", "2"))
experimentDetails.Timeout, _ = strconv.Atoi(common.Getenv("STATUS_CHECK_TIMEOUT", "180"))
experimentDetails.TargetPods = common.Getenv("TARGET_PODS", "")
experimentDetails.ChaosKillCmd = common.Getenv("CHAOS_KILL_COMMAND", "killall dd")
experimentDetails.ChaosKillCmd = common.Getenv("CHAOS_KILL_COMMAND", "kill $(find /proc -name exe -lname '*/dd' 2>&1 | grep -v 'Permission denied' | awk -F/ '{print $(NF-1)}' | head -n 1)")
experimentDetails.LIBImagePullPolicy = common.Getenv("LIB_IMAGE_PULL_POLICY", "Always")
experimentDetails.TargetContainer = common.Getenv("TARGET_CONTAINER", "")
experimentDetails.Sequence = common.Getenv("SEQUENCE", "parallel")
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/common/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ func GetTargetPodsWhenTargetPodsENVNotSet(podAffPerc int, clients clients.Client
return filteredPods, errors.Errorf("No target pod found")
}

newPodListLength := math.Maximum(1, math.Adjustment(podAffPerc, len(filteredPods.Items)))
newPodListLength := math.Maximum(1, math.Adjustment(math.Minimum(podAffPerc, 100), len(filteredPods.Items)))
rand.Seed(time.Now().UnixNano())

// it will generate the random podlist
Expand Down

0 comments on commit 4d41f34

Please sign in to comment.