Skip to content

Commit

Permalink
cherry-pick for 1.8.1 (#134)
Browse files Browse the repository at this point in the history
* chore(socketPath): correcting socketPath env name (#124)

Signed-off-by: shubhamchaudhary <[email protected]>

* chore(network-chaos): Adding ability to inject network chaos w/ pause container (#126)

Signed-off-by: shubhamchaudhary <[email protected]>

* fix(permission-issue): fixing the username permission issue for sockfile (#129)

Signed-off-by: shubhamchaudhary <[email protected]>

* chore(k8sprobe): Adding label-selector field in k8sprobe (#127)

Signed-off-by: shubhamchaudhary <[email protected]>

* Chore/ Splitting different files for network chaos experiment (#128)

* Chore/ Splitting different variables for network chaos experiment

Signed-off-by: Udit Gaurav <[email protected]>

* fix(userid): revert the userid from dockerfile (#131)

Signed-off-by: shubhamchaudhary <[email protected]>

* fix(duplicate): fixing network duplicate exp (#132)

Signed-off-by: shubhamchaudhary <[email protected]>

* chore(network-chaos): splitting network chaos for containerd (#133)

Signed-off-by: shubhamchaudhary <[email protected]>

Co-authored-by: Shubham Chaudhary <[email protected]>
  • Loading branch information
uditgaurav and ispeakc0de authored Sep 18, 2020
1 parent 4c62402 commit bfdb421
Show file tree
Hide file tree
Showing 30 changed files with 449 additions and 142 deletions.
6 changes: 0 additions & 6 deletions build/litmus-go/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ FROM ubuntu:bionic

LABEL maintainer="LitmusChaos"

ENV USER_UID=1001 \
USER_NAME=litmus-go

#Installing necessary ubuntu packages
RUN apt-get update && apt-get install -y curl bash systemd iproute2

Expand All @@ -43,7 +40,4 @@ COPY --from=builder /code/stress-ng/stress-ng /
#Copying Necessary Files
COPY ./build/_output ./litmus/experiments

RUN useradd -ms /bin/bash ${USER_NAME}
WORKDIR /litmus
RUN chown -R ${USER_NAME}:root /litmus
USER ${USER_NAME}
4 changes: 2 additions & 2 deletions chaoslib/litmus/container-kill/lib/container-kill.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func CreateHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clie
Name: "cri-socket",
VolumeSource: apiv1.VolumeSource{
HostPath: &apiv1.HostPathVolumeSource{
Path: experimentsDetails.ContainerPath,
Path: experimentsDetails.SocketPath,
},
},
},
Expand Down Expand Up @@ -183,7 +183,7 @@ func CreateHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clie
VolumeMounts: []apiv1.VolumeMount{
{
Name: "cri-socket",
MountPath: experimentsDetails.ContainerPath,
MountPath: experimentsDetails.SocketPath,
},
{
Name: "cri-config",
Expand Down
24 changes: 24 additions & 0 deletions chaoslib/litmus/network-chaos/lib/corruption/corruption.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package corruption

import (
"strconv"

network_chaos "github.com/litmuschaos/litmus-go/chaoslib/litmus/network-chaos/lib"
clients "github.com/litmuschaos/litmus-go/pkg/clients"
experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/network-chaos/types"
"github.com/litmuschaos/litmus-go/pkg/types"
)

var err error

//PodNetworkCorruptionChaos contains the steps to prepare and inject chaos
func PodNetworkCorruptionChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error {

args := "corrupt " + strconv.Itoa(experimentsDetails.NetworkPacketCorruptionPercentage)
err = network_chaos.PrepareAndInjectChaos(experimentsDetails, clients, resultDetails, eventsDetails, chaosDetails, args)
if err != nil {
return err
}

return nil
}
24 changes: 24 additions & 0 deletions chaoslib/litmus/network-chaos/lib/duplication/duplication.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package duplication

import (
"strconv"

network_chaos "github.com/litmuschaos/litmus-go/chaoslib/litmus/network-chaos/lib"
clients "github.com/litmuschaos/litmus-go/pkg/clients"
experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/network-chaos/types"
"github.com/litmuschaos/litmus-go/pkg/types"
)

var err error

//PodNetworkDuplicationChaos contains the steps to prepare and inject chaos
func PodNetworkDuplicationChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error {

args := "duplicate " + strconv.Itoa(experimentsDetails.NetworkPacketDuplicationPercentage)
err = network_chaos.PrepareAndInjectChaos(experimentsDetails, clients, resultDetails, eventsDetails, chaosDetails, args)
if err != nil {
return err
}

return nil
}
24 changes: 24 additions & 0 deletions chaoslib/litmus/network-chaos/lib/latency/latency.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package latency

import (
"strconv"

network_chaos "github.com/litmuschaos/litmus-go/chaoslib/litmus/network-chaos/lib"
clients "github.com/litmuschaos/litmus-go/pkg/clients"
experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/network-chaos/types"
"github.com/litmuschaos/litmus-go/pkg/types"
)

var err error

//PodNetworkLatencyChaos contains the steps to prepare and inject chaos
func PodNetworkLatencyChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error {

args := "delay " + strconv.Itoa(experimentsDetails.NetworkLatency) + "ms"
err = network_chaos.PrepareAndInjectChaos(experimentsDetails, clients, resultDetails, eventsDetails, chaosDetails, args)
if err != nil {
return err
}

return nil
}
24 changes: 24 additions & 0 deletions chaoslib/litmus/network-chaos/lib/loss/loss.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package loss

import (
"strconv"

network_chaos "github.com/litmuschaos/litmus-go/chaoslib/litmus/network-chaos/lib"
clients "github.com/litmuschaos/litmus-go/pkg/clients"
experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/network-chaos/types"
"github.com/litmuschaos/litmus-go/pkg/types"
)

var err error

//PodNetworkLossChaos contains the steps to prepare and inject chaos
func PodNetworkLossChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error {

args := "loss " + strconv.Itoa(experimentsDetails.NetworkPacketLossPercentage)
err = network_chaos.PrepareAndInjectChaos(experimentsDetails, clients, resultDetails, eventsDetails, chaosDetails, args)
if err != nil {
return err
}

return nil
}
35 changes: 10 additions & 25 deletions chaoslib/litmus/network-chaos/lib/network-chaos.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (

var err error

//PreparePodNetworkChaos contains the prepration steps before chaos injection
func PreparePodNetworkChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error {
//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 {

// 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
Expand Down Expand Up @@ -57,7 +57,7 @@ func PreparePodNetworkChaos(experimentsDetails *experimentTypes.ExperimentDetail
// creating the helper pod to perform network chaos
for _, pod := range targetPodList.Items {
runID := common.GetRunID()
err = CreateHelperPod(experimentsDetails, clients, pod.Name, pod.Spec.NodeName, runID)
err = CreateHelperPod(experimentsDetails, clients, pod.Name, pod.Spec.NodeName, runID, args)
if err != nil {
return errors.Errorf("Unable to create the helper pod, err: %v", err)
}
Expand Down Expand Up @@ -110,7 +110,7 @@ func GetTargetContainer(experimentsDetails *experimentTypes.ExperimentDetails, a
}

// CreateHelperPod derive the attributes for helper pod and create the helper pod
func CreateHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, podName, nodeName, runID string) error {
func CreateHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, podName, nodeName, runID string, args string) error {

privilegedEnable := false
if experimentsDetails.ContainerRuntime == "crio" {
Expand Down Expand Up @@ -138,7 +138,7 @@ func CreateHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clie
Name: "cri-socket",
VolumeSource: apiv1.VolumeSource{
HostPath: &apiv1.HostPathVolumeSource{
Path: experimentsDetails.ContainerPath,
Path: experimentsDetails.SocketPath,
},
},
},
Expand All @@ -158,17 +158,17 @@ func CreateHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clie
Image: experimentsDetails.LIBImage,
ImagePullPolicy: apiv1.PullAlways,
Command: []string{
"bin/bash",
"/bin/bash",
},
Args: []string{
"-c",
"./experiments/network-chaos",
},
Env: GetPodEnv(experimentsDetails, podName),
Env: GetPodEnv(experimentsDetails, podName, args),
VolumeMounts: []apiv1.VolumeMount{
{
Name: "cri-socket",
MountPath: experimentsDetails.ContainerPath,
MountPath: experimentsDetails.SocketPath,
},
{
Name: "cri-config",
Expand All @@ -195,7 +195,7 @@ func CreateHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clie
}

// GetPodEnv derive all the env required for the helper pod
func GetPodEnv(experimentsDetails *experimentTypes.ExperimentDetails, podName string) []apiv1.EnvVar {
func GetPodEnv(experimentsDetails *experimentTypes.ExperimentDetails, podName, args string) []apiv1.EnvVar {

var envVar []apiv1.EnvVar
ENVList := map[string]string{
Expand All @@ -207,7 +207,7 @@ func GetPodEnv(experimentsDetails *experimentTypes.ExperimentDetails, podName st
"CHAOS_ENGINE": experimentsDetails.EngineName,
"CHAOS_UID": string(experimentsDetails.ChaosUID),
"CONTAINER_RUNTIME": experimentsDetails.ContainerRuntime,
"NETEM_COMMAND": GetNetemCommand(experimentsDetails),
"NETEM_COMMAND": args,
"NETWORK_INTERFACE": experimentsDetails.NetworkInterface,
"EXPERIMENT_NAME": experimentsDetails.ExperimentName,
}
Expand Down Expand Up @@ -237,18 +237,3 @@ func GetValueFromDownwardAPI(apiVersion string, fieldPath string) apiv1.EnvVarSo
}
return downwardENV
}

// GetNetemCommand generate the netem command based on the experiment name
func GetNetemCommand(experimentDetails *experimentTypes.ExperimentDetails) string {
var cmd string
if experimentDetails.ExperimentName == "pod-network-loss" {
cmd = "loss " + strconv.Itoa(experimentDetails.NetworkPacketLossPercentage)
} else if experimentDetails.ExperimentName == "pod-network-latency" {
cmd = "delay " + strconv.Itoa(experimentDetails.NetworkLatency) + "ms"
} else if experimentDetails.ExperimentName == "pod-network-corruption" {
cmd = "corrupt " + strconv.Itoa(experimentDetails.NetworkPacketCorruptionPercentage)
} else {
cmd = "duplicate " + strconv.Itoa(experimentDetails.NetworkPacketDuplicationPercentage)
}
return cmd
}
44 changes: 44 additions & 0 deletions chaoslib/pumba/network-chaos/lib/corruption/corruption.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package corruption

import (
"strconv"

network_chaos "github.com/litmuschaos/litmus-go/chaoslib/pumba/network-chaos/lib"
clients "github.com/litmuschaos/litmus-go/pkg/clients"
experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/network-chaos/types"
"github.com/litmuschaos/litmus-go/pkg/types"
)

var err error

//PodNetworkCorruptionChaos contains the steps to prepare and inject chaos
func PodNetworkCorruptionChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error {

args := GetContainerArguments(experimentsDetails)
err = network_chaos.PrepareAndInjectChaos(experimentsDetails, clients, resultDetails, eventsDetails, chaosDetails, args)
if err != nil {
return err
}

return nil
}

// GetContainerArguments derives the args for the pumba pod
func GetContainerArguments(experimentsDetails *experimentTypes.ExperimentDetails) []string {
baseArgs := []string{
"netem",
"--tc-image",
experimentsDetails.TCImage,
"--interface",
experimentsDetails.NetworkInterface,
"--duration",
strconv.Itoa(experimentsDetails.ChaosDuration) + "s",
}

args := baseArgs
args = network_chaos.AddTargetIpsArgs(experimentsDetails.TargetIPs, args)
args = network_chaos.AddTargetIpsArgs(network_chaos.GetIpsForTargetHosts(experimentsDetails.TargetHosts), args)
args = append(args, "corrupt", "--percent", strconv.Itoa(experimentsDetails.NetworkPacketCorruptionPercentage))

return args
}
44 changes: 44 additions & 0 deletions chaoslib/pumba/network-chaos/lib/duplication/duplication.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package duplication

import (
"strconv"

network_chaos "github.com/litmuschaos/litmus-go/chaoslib/pumba/network-chaos/lib"
clients "github.com/litmuschaos/litmus-go/pkg/clients"
experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/network-chaos/types"
"github.com/litmuschaos/litmus-go/pkg/types"
)

var err error

//PodNetworkDuplicationChaos contains the steps to prepare and inject chaos
func PodNetworkDuplicationChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error {

args := GetContainerArguments(experimentsDetails)
err = network_chaos.PrepareAndInjectChaos(experimentsDetails, clients, resultDetails, eventsDetails, chaosDetails, args)
if err != nil {
return err
}

return nil
}

// GetContainerArguments derives the args for the pumba pod
func GetContainerArguments(experimentsDetails *experimentTypes.ExperimentDetails) []string {
baseArgs := []string{
"netem",
"--tc-image",
experimentsDetails.TCImage,
"--interface",
experimentsDetails.NetworkInterface,
"--duration",
strconv.Itoa(experimentsDetails.ChaosDuration) + "s",
}

args := baseArgs
args = network_chaos.AddTargetIpsArgs(experimentsDetails.TargetIPs, args)
args = network_chaos.AddTargetIpsArgs(network_chaos.GetIpsForTargetHosts(experimentsDetails.TargetHosts), args)
args = append(args, "duplicate", "--percent", strconv.Itoa(experimentsDetails.NetworkPacketDuplicationPercentage))

return args
}
44 changes: 44 additions & 0 deletions chaoslib/pumba/network-chaos/lib/latency/latency.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package latency

import (
"strconv"

network_chaos "github.com/litmuschaos/litmus-go/chaoslib/pumba/network-chaos/lib"
clients "github.com/litmuschaos/litmus-go/pkg/clients"
experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/network-chaos/types"
"github.com/litmuschaos/litmus-go/pkg/types"
)

var err error

//PodNetworkLatencyChaos contains the steps to prepare and inject chaos
func PodNetworkLatencyChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error {

args := GetContainerArguments(experimentsDetails)
err = network_chaos.PrepareAndInjectChaos(experimentsDetails, clients, resultDetails, eventsDetails, chaosDetails, args)
if err != nil {
return err
}

return nil
}

// GetContainerArguments derives the args for the pumba pod
func GetContainerArguments(experimentsDetails *experimentTypes.ExperimentDetails) []string {
baseArgs := []string{
"netem",
"--tc-image",
experimentsDetails.TCImage,
"--interface",
experimentsDetails.NetworkInterface,
"--duration",
strconv.Itoa(experimentsDetails.ChaosDuration) + "s",
}

args := baseArgs
args = network_chaos.AddTargetIpsArgs(experimentsDetails.TargetIPs, args)
args = network_chaos.AddTargetIpsArgs(network_chaos.GetIpsForTargetHosts(experimentsDetails.TargetHosts), args)
args = append(args, "delay", "--time", strconv.Itoa(experimentsDetails.NetworkLatency))

return args
}
Loading

0 comments on commit bfdb421

Please sign in to comment.