Skip to content

Commit

Permalink
(enahncement)experiment: add node label filter for pod network and st…
Browse files Browse the repository at this point in the history
…ress chaos (#494)

Signed-off-by: uditgaurav <[email protected]>
  • Loading branch information
uditgaurav authored Mar 16, 2022
1 parent 8a63701 commit 433e40d
Show file tree
Hide file tree
Showing 16 changed files with 238 additions and 26 deletions.
26 changes: 22 additions & 4 deletions chaoslib/litmus/container-kill/lib/container-kill.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import (
//PrepareContainerKill contains the prepration steps before chaos injection
func PrepareContainerKill(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error {

targetPodList := apiv1.PodList{}
var err error
var podsAffectedPerc int
// Get the target pod details for the chaos execution
// if the target pod is not defined it will derive the random target pod list using pod affected percentage
if experimentsDetails.TargetPods == "" && chaosDetails.AppDetail.Label == "" {
Expand All @@ -33,10 +36,25 @@ func PrepareContainerKill(experimentsDetails *experimentTypes.ExperimentDetails,
"Sequence": experimentsDetails.Sequence,
})

podsAffectedPerc, _ := strconv.Atoi(experimentsDetails.PodsAffectedPerc)
targetPodList, err := common.GetPodList(experimentsDetails.TargetPods, podsAffectedPerc, clients, chaosDetails)
if err != nil {
return err
podsAffectedPerc, _ = strconv.Atoi(experimentsDetails.PodsAffectedPerc)
if experimentsDetails.NodeLabel == "" {
targetPodList, err = common.GetPodList(experimentsDetails.TargetPods, podsAffectedPerc, clients, chaosDetails)
if err != nil {
return err
}
} else {
if experimentsDetails.TargetPods == "" {
targetPodList, err = common.GetPodListFromSpecifiedNodes(experimentsDetails.TargetPods, podsAffectedPerc, experimentsDetails.NodeLabel, clients, chaosDetails)
if err != nil {
return err
}
} else {
log.Infof("TARGET_PODS env is provided, overriding the NODE_LABEL input")
targetPodList, err = common.GetPodList(experimentsDetails.TargetPods, podsAffectedPerc, clients, chaosDetails)
if err != nil {
return err
}
}
}

podNames := []string{}
Expand Down
28 changes: 22 additions & 6 deletions chaoslib/litmus/disk-fill/lib/disk-fill.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@ import (
//PrepareDiskFill contains the prepration steps before chaos injection
func PrepareDiskFill(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error {

targetPodList := apiv1.PodList{}
var err error
var podsAffectedPerc int
// It will contains all the pod & container details required for exec command
execCommandDetails := exec.PodDetails{}

// Get the target pod details for the chaos execution
// if the target pod is not defined it will derive the random target pod list using pod affected percentage
if experimentsDetails.TargetPods == "" && chaosDetails.AppDetail.Label == "" {
return errors.Errorf("please provide one of the appLabel or TARGET_PODS")
}

//setup the tunables if provided in range
setChaosTunables(experimentsDetails)

Expand All @@ -40,10 +41,25 @@ func PrepareDiskFill(experimentsDetails *experimentTypes.ExperimentDetails, clie
"Sequence": experimentsDetails.Sequence,
})

podsAffectedPerc, _ := strconv.Atoi(experimentsDetails.PodsAffectedPerc)
targetPodList, err := common.GetPodList(experimentsDetails.TargetPods, podsAffectedPerc, clients, chaosDetails)
if err != nil {
return err
podsAffectedPerc, _ = strconv.Atoi(experimentsDetails.PodsAffectedPerc)
if experimentsDetails.NodeLabel == "" {
targetPodList, err = common.GetPodList(experimentsDetails.TargetPods, podsAffectedPerc, clients, chaosDetails)
if err != nil {
return err
}
} else {
if experimentsDetails.TargetPods == "" {
targetPodList, err = common.GetPodListFromSpecifiedNodes(experimentsDetails.TargetPods, podsAffectedPerc, experimentsDetails.NodeLabel, clients, chaosDetails)
if err != nil {
return err
}
} else {
log.Infof("TARGET_PODS env is provided, overriding the NODE_LABEL input")
targetPodList, err = common.GetPodList(experimentsDetails.TargetPods, podsAffectedPerc, clients, chaosDetails)
if err != nil {
return err
}
}
}

podNames := []string{}
Expand Down
29 changes: 25 additions & 4 deletions chaoslib/litmus/network-chaos/lib/network-chaos.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import (
//PrepareAndInjectChaos contains the prepration & injection steps
func PrepareAndInjectChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails, args string) error {

targetPodList := apiv1.PodList{}
var err error
var podsAffectedPerc int
// Get the target pod details for the chaos execution
// if the target pod is not defined it will derive the random target pod list using pod affected percentage
if experimentsDetails.TargetPods == "" && chaosDetails.AppDetail.Label == "" {
Expand Down Expand Up @@ -55,10 +58,28 @@ func PrepareAndInjectChaos(experimentsDetails *experimentTypes.ExperimentDetails
"PodsAffectedPerc": experimentsDetails.PodsAffectedPerc,
})
}
podsAffectedPerc, _ := strconv.Atoi(experimentsDetails.PodsAffectedPerc)
targetPodList, err := common.GetPodList(experimentsDetails.TargetPods, podsAffectedPerc, clients, chaosDetails)
if err != nil {
return err
podsAffectedPerc, _ = strconv.Atoi(experimentsDetails.PodsAffectedPerc)
if experimentsDetails.NodeLabel == "" {

//targetPodList, err := common.GetPodListFromSpecifiedNodes(experimentsDetails.TargetPods, experimentsDetails.PodsAffectedPerc, clients, chaosDetails)
targetPodList, err = common.GetPodList(experimentsDetails.TargetPods, podsAffectedPerc, clients, chaosDetails)
if err != nil {
return err
}
} else {
//targetPodList, err := common.GetPodList(experimentsDetails.TargetPods, experimentsDetails.PodsAffectedPerc, clients, chaosDetails)
if experimentsDetails.TargetPods == "" {
targetPodList, err = common.GetPodListFromSpecifiedNodes(experimentsDetails.TargetPods, podsAffectedPerc, experimentsDetails.NodeLabel, clients, chaosDetails)
if err != nil {
return err
}
} else {
log.Infof("TARGET_PODS env is provided, overriding the NODE_LABEL input")
targetPodList, err = common.GetPodList(experimentsDetails.TargetPods, podsAffectedPerc, clients, chaosDetails)
if err != nil {
return err
}
}
}

podNames := []string{}
Expand Down
53 changes: 45 additions & 8 deletions chaoslib/litmus/pod-delete/lib/pod-delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/litmuschaos/litmus-go/pkg/utils/common"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
apiv1 "k8s.io/api/core/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -60,6 +61,9 @@ func PreparePodDelete(experimentsDetails *experimentTypes.ExperimentDetails, cli
// injectChaosInSerialMode delete the target application pods serial mode(one by one)
func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails, eventsDetails *types.EventDetails, resultDetails *types.ResultDetails) error {

targetPodList := apiv1.PodList{}
var err error
var podsAffectedPerc int
// run the probes during chaos
if len(resultDetails.ProbeDetails) != 0 {
if err := probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil {
Expand All @@ -78,10 +82,25 @@ func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetai
if experimentsDetails.TargetPods == "" && chaosDetails.AppDetail.Label == "" {
return errors.Errorf("please provide one of the appLabel or TARGET_PODS")
}
podsAffectedPerc, _ := strconv.Atoi(experimentsDetails.PodsAffectedPerc)
targetPodList, err := common.GetPodList(experimentsDetails.TargetPods, podsAffectedPerc, clients, chaosDetails)
if err != nil {
return err
podsAffectedPerc, _ = strconv.Atoi(experimentsDetails.PodsAffectedPerc)
if experimentsDetails.NodeLabel == "" {
targetPodList, err = common.GetPodList(experimentsDetails.TargetPods, podsAffectedPerc, clients, chaosDetails)
if err != nil {
return err
}
} else {
if experimentsDetails.TargetPods == "" {
targetPodList, err = common.GetPodListFromSpecifiedNodes(experimentsDetails.TargetPods, podsAffectedPerc, experimentsDetails.NodeLabel, clients, chaosDetails)
if err != nil {
return err
}
} else {
log.Infof("TARGET_PODS env is provided, overriding the NODE_LABEL input")
targetPodList, err = common.GetPodList(experimentsDetails.TargetPods, podsAffectedPerc, clients, chaosDetails)
if err != nil {
return err
}
}
}

// deriving the parent name of the target resources
Expand Down Expand Up @@ -158,6 +177,9 @@ func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetai
// injectChaosInParallelMode delete the target application pods in parallel mode (all at once)
func injectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails, eventsDetails *types.EventDetails, resultDetails *types.ResultDetails) error {

targetPodList := apiv1.PodList{}
var err error
var podsAffectedPerc int
// run the probes during chaos
if len(resultDetails.ProbeDetails) != 0 {
if err := probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil {
Expand All @@ -176,10 +198,25 @@ func injectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDet
if experimentsDetails.TargetPods == "" && chaosDetails.AppDetail.Label == "" {
return errors.Errorf("please provide one of the appLabel or TARGET_PODS")
}
podsAffectedPerc, _ := strconv.Atoi(experimentsDetails.PodsAffectedPerc)
targetPodList, err := common.GetPodList(experimentsDetails.TargetPods, podsAffectedPerc, clients, chaosDetails)
if err != nil {
return err
podsAffectedPerc, _ = strconv.Atoi(experimentsDetails.PodsAffectedPerc)
if experimentsDetails.NodeLabel == "" {
targetPodList, err = common.GetPodList(experimentsDetails.TargetPods, podsAffectedPerc, clients, chaosDetails)
if err != nil {
return err
}
} else {
if experimentsDetails.TargetPods == "" {
targetPodList, err = common.GetPodListFromSpecifiedNodes(experimentsDetails.TargetPods, podsAffectedPerc, experimentsDetails.NodeLabel, clients, chaosDetails)
if err != nil {
return err
}
} else {
log.Infof("TARGET_PODS env is provided, overriding the NODE_LABEL input")
targetPodList, err = common.GetPodList(experimentsDetails.TargetPods, podsAffectedPerc, clients, chaosDetails)
if err != nil {
return err
}
}
}

// deriving the parent name of the target resources
Expand Down
26 changes: 22 additions & 4 deletions chaoslib/litmus/stress-chaos/lib/stress-chaos.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import (
//PrepareAndInjectStressChaos contains the prepration & injection steps for the stress experiments.
func PrepareAndInjectStressChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error {

targetPodList := apiv1.PodList{}
var err error
var podsAffectedPerc int
//Setup the tunables if provided in range
SetChaosTunables(experimentsDetails)

Expand Down Expand Up @@ -55,10 +58,25 @@ func PrepareAndInjectStressChaos(experimentsDetails *experimentTypes.ExperimentD
if experimentsDetails.TargetPods == "" && chaosDetails.AppDetail.Label == "" {
return errors.Errorf("Please provide one of the appLabel or TARGET_PODS")
}
PodsAffectedPerc, _ := strconv.Atoi(experimentsDetails.PodsAffectedPerc)
targetPodList, err := common.GetPodList(experimentsDetails.TargetPods, PodsAffectedPerc, clients, chaosDetails)
if err != nil {
return err
podsAffectedPerc, _ = strconv.Atoi(experimentsDetails.PodsAffectedPerc)
if experimentsDetails.NodeLabel == "" {
targetPodList, err = common.GetPodList(experimentsDetails.TargetPods, podsAffectedPerc, clients, chaosDetails)
if err != nil {
return err
}
} else {
if experimentsDetails.TargetPods == "" {
targetPodList, err = common.GetPodListFromSpecifiedNodes(experimentsDetails.TargetPods, podsAffectedPerc, experimentsDetails.NodeLabel, clients, chaosDetails)
if err != nil {
return err
}
} else {
log.Infof("TARGET_PODS env is provided, overriding the NODE_LABEL input")
targetPodList, err = common.GetPodList(experimentsDetails.TargetPods, podsAffectedPerc, clients, chaosDetails)
if err != nil {
return err
}
}
}

podNames := []string{}
Expand Down
1 change: 1 addition & 0 deletions pkg/generic/container-kill/environment/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ func GetENV(experimentDetails *experimentTypes.ExperimentDetails) {
experimentDetails.Sequence = types.Getenv("SEQUENCE", "parallel")
experimentDetails.Signal = types.Getenv("SIGNAL", "SIGKILL")
experimentDetails.TerminationGracePeriodSeconds, _ = strconv.Atoi(types.Getenv("TERMINATION_GRACE_PERIOD_SECONDS", ""))
experimentDetails.NodeLabel = types.Getenv("NODE_LABEL", "")
}
1 change: 1 addition & 0 deletions pkg/generic/container-kill/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ type ExperimentDetails struct {
PodsAffectedPerc string
Sequence string
Signal string
NodeLabel string
}
2 changes: 2 additions & 0 deletions pkg/generic/disk-fill/environment/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ func GetENV(experimentDetails *experimentTypes.ExperimentDetails) {
experimentDetails.EphemeralStorageMebibytes = types.Getenv("EPHEMERAL_STORAGE_MEBIBYTES", "")
experimentDetails.TerminationGracePeriodSeconds, _ = strconv.Atoi(types.Getenv("TERMINATION_GRACE_PERIOD_SECONDS", ""))
experimentDetails.DataBlockSize, _ = strconv.Atoi(types.Getenv("DATA_BLOCK_SIZE", "256"))
experimentDetails.NodeLabel = types.Getenv("NODE_LABEL", "")

}
1 change: 1 addition & 0 deletions pkg/generic/disk-fill/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ type ExperimentDetails struct {
EphemeralStorageMebibytes string
TerminationGracePeriodSeconds int
DataBlockSize int
NodeLabel string
}
1 change: 1 addition & 0 deletions pkg/generic/network-chaos/environment/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func GetENV(experimentDetails *experimentTypes.ExperimentDetails, expName string
experimentDetails.Timeout, _ = strconv.Atoi(types.Getenv("STATUS_CHECK_TIMEOUT", "180"))
experimentDetails.TargetPods = types.Getenv("TARGET_PODS", "")
experimentDetails.PodsAffectedPerc = types.Getenv("PODS_AFFECTED_PERC", "0")
experimentDetails.NodeLabel = types.Getenv("NODE_LABEL", "")
experimentDetails.DestinationIPs = types.Getenv("DESTINATION_IPS", "")
experimentDetails.DestinationHosts = types.Getenv("DESTINATION_HOSTS", "")
experimentDetails.ContainerRuntime = types.Getenv("CONTAINER_RUNTIME", "docker")
Expand Down
1 change: 1 addition & 0 deletions pkg/generic/network-chaos/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ type ExperimentDetails struct {
TerminationGracePeriodSeconds int
Jitter int
NetworkChaosType string
NodeLabel string
}
1 change: 1 addition & 0 deletions pkg/generic/pod-delete/environment/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ func GetENV(experimentDetails *experimentTypes.ExperimentDetails) {
experimentDetails.TargetPods = types.Getenv("TARGET_PODS", "")
experimentDetails.Sequence = types.Getenv("SEQUENCE", "parallel")
experimentDetails.TargetContainer = types.Getenv("TARGET_CONTAINER", "")
experimentDetails.NodeLabel = types.Getenv("NODE_LABEL", "")
}
1 change: 1 addition & 0 deletions pkg/generic/pod-delete/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ type ExperimentDetails struct {
Sequence string
LIBImagePullPolicy string
TargetContainer string
NodeLabel string
}
1 change: 1 addition & 0 deletions pkg/generic/stress-chaos/environment/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func GetENV(experimentDetails *experimentTypes.ExperimentDetails, expName string
experimentDetails.Sequence = types.Getenv("SEQUENCE", "parallel")
experimentDetails.TerminationGracePeriodSeconds, _ = strconv.Atoi(types.Getenv("TERMINATION_GRACE_PERIOD_SECONDS", ""))
experimentDetails.StressImage = types.Getenv("STRESS_IMAGE", "alexeiled/stress-ng:latest-ubuntu")
experimentDetails.NodeLabel = types.Getenv("NODE_LABEL", "")

switch expName {
case "pod-cpu-hog":
Expand Down
1 change: 1 addition & 0 deletions pkg/generic/stress-chaos/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ type ExperimentDetails struct {
MemoryConsumption string
VolumeMountPath string
StressType string
NodeLabel string
}
Loading

0 comments on commit 433e40d

Please sign in to comment.