Skip to content

Commit

Permalink
[cherrypick for 2.1.1] (#453)
Browse files Browse the repository at this point in the history
* update(version): updating kubernetes version (#450)

Signed-off-by: shubham chaudhary <[email protected]>

* Chore(secured-image): Add litmus hardened alpine image as base image (#448)

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

* Chore(helper): Add termination grace period seconds to the helper pods and tolerationSeconds in kubelet and docker svc kill experiment helper (#433)

* Chore(helper): Add termination grace period seconds to the helper pods

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

* Add tolerationSeconds in kubelet and docker svc kill experiment

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

* chore(labels): passing labels to the helper pod (#451)

Signed-off-by: shubham chaudhary <[email protected]>

* resolved conflicts

Signed-off-by: shubham chaudhary <[email protected]>

* VMWare VM-Poweroff Experiment Enhancements (#449)

* stopVM and startVM moved to vm-operations.go,added error check in api calls, modified function signatures to remove dependency on expexperiment specific types.go

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

* added chaos injection functionality for multiple VMs; added chaos parallel and serial chaos injection

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

* added functionality for waiting through the duration of fully starting and fully stopping the VM

Co-authored-by: Udit Gaurav <[email protected]>
Co-authored-by: Neelanjan Manna <[email protected]>
  • Loading branch information
3 people authored Oct 1, 2021
1 parent b32b2e4 commit 0ffc453
Show file tree
Hide file tree
Showing 108 changed files with 1,244 additions and 1,314 deletions.
24 changes: 12 additions & 12 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,20 @@ jobs:
needs: pre-checks
runs-on: ubuntu-latest
steps:
# Install golang
- uses: actions/setup-go@v2
with:
go-version: 1.16

- uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha }}

- name: Build image for trivy scan
run: make build-amd64

- name: setup trivy
- name: Build an image from Dockerfile
run: |
wget https://github.com/aquasecurity/trivy/releases/download/v0.11.0/trivy_0.11.0_Linux-64bit.tar.gz
tar zxvf trivy_0.11.0_Linux-64bit.tar.gz
make trivy-check
docker build -f build/Dockerfile -t docker.io/litmuschaos/go-runner:${{ github.sha }} . --build-arg TARGETARCH=amd64
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
image-ref: 'docker.io/litmuschaos/go-runner:${{ github.sha }}'
format: 'table'
exit-code: '1'
ignore-unfixed: true
vuln-type: 'os,library'
severity: 'CRITICAL,HIGH'
78 changes: 12 additions & 66 deletions build/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
FROM golang:1.16 AS builder
# Multi-stage docker build
# Build stage
FROM golang:alpine AS builder

ARG TARGETOS=linux
ARG TARGETARCH
Expand All @@ -12,79 +14,23 @@ RUN export GOOS=${TARGETOS} && \
RUN CGO_ENABLED=0 go build -o /output/experiments ./bin/experiment
RUN CGO_ENABLED=0 go build -o /output/helpers ./bin/helper


FROM alpine:3.13

LABEL maintainer="LitmusChaos"

ARG USER=litmus

ENV GLIBC_REPO=https://github.com/sgerrand/alpine-pkg-glibc
ENV GLIBC_VERSION=2.30-r0
ARG TARGETARCH

RUN rm -rf /var/lib/apt/lists/*
FROM alpine:3.14.2 AS dep

# Install generally useful things
RUN apk --update add \
sudo \
htop\
bash\
make\
git \
curl\
iproute2\
stress-ng\
openssh-client\
# libc6-compat \
sshpass

RUN set -ex && \
apk --update add libstdc++ curl ca-certificates && \
for pkg in glibc-${GLIBC_VERSION} glibc-bin-${GLIBC_VERSION}; \
do curl -sSL ${GLIBC_REPO}/releases/download/${GLIBC_VERSION}/${pkg}.apk -o /tmp/${pkg}.apk; done && \
apk add --allow-untrusted /tmp/*.apk && \
rm -v /tmp/*.apk && \
/usr/glibc-compat/sbin/ldconfig /lib /usr/glibc-compat/lib
iproute2

# Change default shell from ash to bash
RUN sed -i -e "s/bin\/ash/bin\/bash/" /etc/passwd
# Packaging stage
# Image source: https://github.com/litmuschaos/test-tools/blob/master/custom/hardened-alpine/experiment/Dockerfile
# The base image is non-root (have litmus user) with default litmus directory.
FROM litmuschaos/experiment-alpine

#Installing Kubectl
ENV KUBE_LATEST_VERSION="v1.18.0"
RUN curl -L https://storage.googleapis.com/kubernetes-release/release/${KUBE_LATEST_VERSION}/bin/linux/${TARGETARCH}/kubectl -o /usr/local/bin/kubectl && \
chmod +x /usr/local/bin/kubectl

#Installing crictl binaries
RUN curl -L https://github.com/kubernetes-sigs/cri-tools/releases/download/v1.16.0/crictl-v1.16.0-linux-${TARGETARCH}.tar.gz --output crictl-v1.16.0-linux-${TARGETARCH}.tar.gz && \
tar zxvf crictl-v1.16.0-linux-${TARGETARCH}.tar.gz -C /usr/local/bin

#Installing pumba binaries
ENV PUMBA_VERSION="0.7.7"
RUN curl -L https://github.com/alexei-led/pumba/releases/download/${PUMBA_VERSION}/pumba_linux_${TARGETARCH} --output /usr/local/bin/pumba && chmod +x /usr/local/bin/pumba

#Installing promql cli binaries
RUN curl -L https://github.com/litmuschaos/test-tools/releases/download/1.13.6/promql-linux-${TARGETARCH} --output /usr/local/bin/promql && chmod +x /usr/local/bin/promql

#Installing nsutil cli binaries
RUN curl -L https://github.com/litmuschaos/test-tools/releases/download/1.13.6/nsutil-linux-${TARGETARCH} --output /usr/local/bin/nsutil && chmod +x /usr/local/bin/nsutil

#Installing pause cli binaries
RUN curl -L https://github.com/litmuschaos/test-tools/releases/download/1.13.6/pause-linux-${TARGETARCH} --output /usr/local/bin/pause && chmod +x /usr/local/bin/pause

#Installing dns_interceptor cli binaries
RUN curl -L https://github.com/litmuschaos/test-tools/releases/download/1.13.6/dns_interceptor --output /usr/local/bin/dns_interceptor && chmod +x /usr/local/bin/dns_interceptor
LABEL maintainer="LitmusChaos"

COPY --from=docker:19.03 /usr/local/bin/docker /usr/local/bin/
COPY --from=builder /output/ /litmus
COPY --from=dep /usr/bin/sudo /usr/bin/
COPY --from=dep /sbin/tc /sbin/

#Copying Necessary Files
COPY ./pkg/cloud/aws/common/ssm-docs/LitmusChaos-AWS-SSM-Docs.yml ./litmus/LitmusChaos-AWS-SSM-Docs.yml

#add new user
RUN adduser -D -S $USER \
&& echo "$USER ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/$USER \
&& chmod 0440 /etc/sudoers.d/$USER

USER $USER
WORKDIR /litmus
1 change: 1 addition & 0 deletions chaoslib/litmus/azure-disk-loss/lib/azure-disk-loss.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetai
common.SetTargets(diskName, "detached", "VirtualDisk", chaosDetails)

// run the probes during chaos
// the OnChaos probes execution will start in the first iteration and keep running for the entire chaos duration
if len(resultDetails.ProbeDetails) != 0 && i == 0 {
if err := probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil {
return err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetai
}

// Run the probes during chaos
// the OnChaos probes execution will start in the first iteration and keep running for the entire chaos duration
if len(resultDetails.ProbeDetails) != 0 && i == 0 {
if err = probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil {
return err
Expand Down
59 changes: 17 additions & 42 deletions chaoslib/litmus/container-kill/lib/container-kill.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func PrepareContainerKill(experimentsDetails *experimentTypes.ExperimentDetails,
}

if experimentsDetails.EngineName != "" {
if err := setHelperData(experimentsDetails, clients); err != nil {
if err := common.SetHelperData(chaosDetails, clients); err != nil {
return err
}
}
Expand Down Expand Up @@ -106,7 +106,7 @@ func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetai
"ContainerName": experimentsDetails.TargetContainer,
})
runID := common.GetRunID()
if err := createHelperPod(experimentsDetails, clients, pod.Name, pod.Spec.NodeName, runID, labelSuffix); err != nil {
if err := createHelperPod(experimentsDetails, clients, chaosDetails, pod.Name, pod.Spec.NodeName, runID, labelSuffix); err != nil {
return errors.Errorf("unable to create the helper pod, err: %v", err)
}

Expand All @@ -125,7 +125,7 @@ func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetai
podStatus, err := status.WaitForCompletion(experimentsDetails.ChaosNamespace, appLabel, clients, experimentsDetails.ChaosDuration+experimentsDetails.Timeout, experimentsDetails.ExperimentName)
if err != nil || podStatus == "Failed" {
common.DeleteHelperPodBasedOnJobCleanupPolicy(experimentsDetails.ExperimentName+"-helper-"+runID, appLabel, chaosDetails, clients)
return errors.Errorf("helper pod failed, err: %v", err)
return common.HelperFailedError(err)
}

//Deleting all the helper pod for container-kill chaos
Expand Down Expand Up @@ -158,7 +158,7 @@ func injectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDet
"ContainerName": experimentsDetails.TargetContainer,
})
runID := common.GetRunID()
if err := createHelperPod(experimentsDetails, clients, pod.Name, pod.Spec.NodeName, runID, labelSuffix); err != nil {
if err := createHelperPod(experimentsDetails, clients, chaosDetails, pod.Name, pod.Spec.NodeName, runID, labelSuffix); err != nil {
return errors.Errorf("unable to create the helper pod, err: %v", err)
}
}
Expand All @@ -178,7 +178,7 @@ func injectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDet
podStatus, err := status.WaitForCompletion(experimentsDetails.ChaosNamespace, appLabel, clients, experimentsDetails.ChaosDuration+experimentsDetails.Timeout, experimentsDetails.ExperimentName)
if err != nil || podStatus == "Failed" {
common.DeleteAllHelperPodBasedOnJobCleanupPolicy(appLabel, chaosDetails, clients)
return errors.Errorf("helper pod failed, err: %v", err)
return common.HelperFailedError(err)
}

//Deleting all the helper pod for container-kill chaos
Expand All @@ -191,30 +191,27 @@ func injectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDet
}

// createHelperPod derive the attributes for helper pod and create the helper pod
func createHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, podName, nodeName, runID, labelSuffix string) error {
func createHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails, podName, nodeName, runID, labelSuffix string) error {

privilegedEnable := false
if experimentsDetails.ContainerRuntime == "crio" {
privilegedEnable = true
}
terminationGracePeriodSeconds := int64(experimentsDetails.TerminationGracePeriodSeconds)

helperPod := &apiv1.Pod{
ObjectMeta: v1.ObjectMeta{
Name: experimentsDetails.ExperimentName + "-helper-" + runID,
Namespace: experimentsDetails.ChaosNamespace,
Labels: map[string]string{
"app": experimentsDetails.ExperimentName + "-helper-" + labelSuffix,
"name": experimentsDetails.ExperimentName + "-helper-" + runID,
"chaosUID": string(experimentsDetails.ChaosUID),
"app.kubernetes.io/part-of": "litmus",
},
Annotations: experimentsDetails.Annotations,
Name: experimentsDetails.ExperimentName + "-helper-" + runID,
Namespace: experimentsDetails.ChaosNamespace,
Labels: common.GetHelperLabels(chaosDetails.Labels, runID, labelSuffix, experimentsDetails.ExperimentName),
Annotations: chaosDetails.Annotations,
},
Spec: apiv1.PodSpec{
ServiceAccountName: experimentsDetails.ChaosServiceAccount,
ImagePullSecrets: experimentsDetails.ImagePullSecrets,
RestartPolicy: apiv1.RestartPolicyNever,
NodeName: nodeName,
ServiceAccountName: experimentsDetails.ChaosServiceAccount,
ImagePullSecrets: chaosDetails.ImagePullSecrets,
RestartPolicy: apiv1.RestartPolicyNever,
NodeName: nodeName,
TerminationGracePeriodSeconds: &terminationGracePeriodSeconds,
Volumes: []apiv1.Volume{
{
Name: "cri-socket",
Expand All @@ -237,7 +234,7 @@ func createHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clie
"-c",
"./helpers -name container-kill",
},
Resources: experimentsDetails.Resources,
Resources: chaosDetails.Resources,
Env: getPodEnv(experimentsDetails, podName),
VolumeMounts: []apiv1.VolumeMount{
{
Expand Down Expand Up @@ -280,25 +277,3 @@ func getPodEnv(experimentsDetails *experimentTypes.ExperimentDetails, podName st

return envDetails.ENV
}

// setHelperData derive the data from experiment pod and sets into experimentDetails struct
// which can be used to create helper pod
func setHelperData(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets) error {
// Get Chaos Pod Annotation
var err error
experimentsDetails.Annotations, err = common.GetChaosPodAnnotation(experimentsDetails.ChaosPodName, experimentsDetails.ChaosNamespace, clients)
if err != nil {
return errors.Errorf("unable to get annotations, err: %v", err)
}
// Get Resource Requirements
experimentsDetails.Resources, err = common.GetChaosPodResourceRequirements(experimentsDetails.ChaosPodName, experimentsDetails.ExperimentName, experimentsDetails.ChaosNamespace, clients)
if err != nil {
return errors.Errorf("unable to get resource requirements, err: %v", err)
}
// Get ImagePullSecrets
experimentsDetails.ImagePullSecrets, err = common.GetImagePullSecrets(experimentsDetails.ChaosPodName, experimentsDetails.ChaosNamespace, clients)
if err != nil {
return errors.Errorf("unable to get imagePullSecrets, err: %v", err)
}
return nil
}
51 changes: 12 additions & 39 deletions chaoslib/litmus/disk-fill/lib/disk-fill.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func PrepareDiskFill(experimentsDetails *experimentTypes.ExperimentDetails, clie
}

if experimentsDetails.EngineName != "" {
if err := setHelperData(experimentsDetails, clients); err != nil {
if err := common.SetHelperData(chaosDetails, clients); err != nil {
return err
}
}
Expand Down Expand Up @@ -103,7 +103,7 @@ func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetai
// creating the helper pod to perform disk-fill chaos
for _, pod := range targetPodList.Items {
runID := common.GetRunID()
if err := createHelperPod(experimentsDetails, clients, pod.Name, pod.Spec.NodeName, runID, labelSuffix); err != nil {
if err := createHelperPod(experimentsDetails, clients, chaosDetails, pod.Name, pod.Spec.NodeName, runID, labelSuffix); err != nil {
return errors.Errorf("unable to create the helper pod, err: %v", err)
}

Expand All @@ -122,7 +122,7 @@ func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetai
podStatus, err := status.WaitForCompletion(experimentsDetails.ChaosNamespace, appLabel, clients, experimentsDetails.ChaosDuration+experimentsDetails.Timeout, experimentsDetails.ExperimentName)
if err != nil || podStatus == "Failed" {
common.DeleteHelperPodBasedOnJobCleanupPolicy(experimentsDetails.ExperimentName+"-helper-"+runID, appLabel, chaosDetails, clients)
return errors.Errorf("helper pod failed due to, err: %v", err)
return common.HelperFailedError(err)
}

//Deleting all the helper pod for disk-fill chaos
Expand Down Expand Up @@ -151,7 +151,7 @@ func injectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDet
// creating the helper pod to perform disk-fill chaos
for _, pod := range targetPodList.Items {
runID := common.GetRunID()
if err := createHelperPod(experimentsDetails, clients, pod.Name, pod.Spec.NodeName, runID, labelSuffix); err != nil {
if err := createHelperPod(experimentsDetails, clients, chaosDetails, pod.Name, pod.Spec.NodeName, runID, labelSuffix); err != nil {
return errors.Errorf("unable to create the helper pod, err: %v", err)
}
}
Expand All @@ -171,7 +171,7 @@ func injectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDet
podStatus, err := status.WaitForCompletion(experimentsDetails.ChaosNamespace, appLabel, clients, experimentsDetails.ChaosDuration+experimentsDetails.Timeout, experimentsDetails.ExperimentName)
if err != nil || podStatus == "Failed" {
common.DeleteAllHelperPodBasedOnJobCleanupPolicy(appLabel, chaosDetails, clients)
return errors.Errorf("helper pod failed due to, err: %v", err)
return common.HelperFailedError(err)
}

//Deleting all the helper pod for disk-fill chaos
Expand All @@ -184,26 +184,21 @@ func injectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDet
}

// createHelperPod derive the attributes for helper pod and create the helper pod
func createHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, appName, appNodeName, runID, labelSuffix string) error {
func createHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails, appName, appNodeName, runID, labelSuffix string) error {

mountPropagationMode := apiv1.MountPropagationHostToContainer
terminationGracePeriodSeconds := int64(experimentsDetails.TerminationGracePeriodSeconds)

helperPod := &apiv1.Pod{
ObjectMeta: v1.ObjectMeta{
Name: experimentsDetails.ExperimentName + "-helper-" + runID,
Namespace: experimentsDetails.ChaosNamespace,
Labels: map[string]string{
"app": experimentsDetails.ExperimentName + "-helper-" + labelSuffix,
"name": experimentsDetails.ExperimentName + "-helper-" + runID,
"chaosUID": string(experimentsDetails.ChaosUID),
"app.kubernetes.io/part-of": "litmus",
},
Annotations: experimentsDetails.Annotations,
Name: experimentsDetails.ExperimentName + "-helper-" + runID,
Namespace: experimentsDetails.ChaosNamespace,
Labels: common.GetHelperLabels(chaosDetails.Labels, runID, labelSuffix, experimentsDetails.ExperimentName),
Annotations: chaosDetails.Annotations,
},
Spec: apiv1.PodSpec{
RestartPolicy: apiv1.RestartPolicyNever,
ImagePullSecrets: experimentsDetails.ImagePullSecrets,
ImagePullSecrets: chaosDetails.ImagePullSecrets,
NodeName: appNodeName,
ServiceAccountName: experimentsDetails.ChaosServiceAccount,
TerminationGracePeriodSeconds: &terminationGracePeriodSeconds,
Expand All @@ -229,7 +224,7 @@ func createHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clie
"-c",
"./helpers -name disk-fill",
},
Resources: experimentsDetails.Resources,
Resources: chaosDetails.Resources,
Env: getPodEnv(experimentsDetails, appName),
VolumeMounts: []apiv1.VolumeMount{
{
Expand Down Expand Up @@ -267,25 +262,3 @@ func getPodEnv(experimentsDetails *experimentTypes.ExperimentDetails, podName st

return envDetails.ENV
}

// setHelperData derive the data from experiment pod and sets into experimentDetails struct
// which can be used to create helper pod
func setHelperData(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets) error {
// Get Chaos Pod Annotation
var err error
experimentsDetails.Annotations, err = common.GetChaosPodAnnotation(experimentsDetails.ChaosPodName, experimentsDetails.ChaosNamespace, clients)
if err != nil {
return errors.Errorf("unable to get annotations, err: %v", err)
}
// Get Resource Requirements
experimentsDetails.Resources, err = common.GetChaosPodResourceRequirements(experimentsDetails.ChaosPodName, experimentsDetails.ExperimentName, experimentsDetails.ChaosNamespace, clients)
if err != nil {
return errors.Errorf("unable to get resource requirements, err: %v", err)
}
// Get ImagePullSecrets
experimentsDetails.ImagePullSecrets, err = common.GetImagePullSecrets(experimentsDetails.ChaosPodName, experimentsDetails.ChaosNamespace, clients)
if err != nil {
return errors.Errorf("unable to get imagePullSecrets, err: %v", err)
}
return nil
}
Loading

0 comments on commit 0ffc453

Please sign in to comment.