From 42f9ccc802112f26fb408a7549ef9978aa6bf98c Mon Sep 17 00:00:00 2001 From: Udit Gaurav <35391335+uditgaurav@users.noreply.github.com> Date: Fri, 18 Dec 2020 00:02:36 +0530 Subject: [PATCH] chore(enhanc): Make socket path tunable from ENV and refactor Makefile (#242) (#243) Signed-off-by: Udit Gaurav --- Makefile | 17 +++++++++++------ chaoslib/pumba/cpu-chaos/lib/cpu-chaos.go | 4 ++-- chaoslib/pumba/memory-chaos/lib/memory-chaos.go | 4 ++-- .../pumba/pod-io-stress/lib/pod-io-stress.go | 4 ++-- .../pod-cpu-hog/environment/environment.go | 1 + pkg/generic/pod-cpu-hog/types/types.go | 1 + .../pod-io-stress/environment/environment.go | 1 + pkg/generic/pod-io-stress/types/types.go | 1 + .../pod-memory-hog/environment/environment.go | 1 + pkg/generic/pod-memory-hog/types/types.go | 1 + 10 files changed, 23 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 9bb334473..acfa66f4b 100644 --- a/Makefile +++ b/Makefile @@ -7,6 +7,11 @@ # IS_DOCKER_INSTALLED = $(shell which docker >> /dev/null 2>&1; echo $$?) +# Docker info +DOCKER_REPO ?= litmuschaos +DOCKER_IMAGE ?= go-runner +DOCKER_TAG ?= ci + PACKAGES = $(shell go list ./... | grep -v '/vendor/') .PHONY: all @@ -75,7 +80,7 @@ build: @echo "-------------------------" @echo "--> Build go-runner image" @echo "-------------------------" - @sudo docker buildx build --file build/litmus-go/Dockerfile --progress plane --platform linux/arm64,linux/amd64 --no-cache --tag litmuschaos/go-runner:ci . + @sudo docker buildx build --file build/litmus-go/Dockerfile --progress plane --platform linux/arm64,linux/amd64 --no-cache --tag $(DOCKER_REPO)/$(DOCKER_IMAGE):$(DOCKER_TAG) . .PHONY: build-amd64 build-amd64: @@ -87,7 +92,7 @@ build-amd64: @echo "-------------------------" @echo "--> Build go-runner image" @echo "-------------------------" - @sudo docker build --file build/litmus-go/Dockerfile --tag litmuschaos/go-runner:ci . --build-arg TARGETARCH=amd64 + @sudo docker build --file build/litmus-go/Dockerfile --tag $(DOCKER_REPO)/$(DOCKER_IMAGE):$(DOCKER_TAG) . --build-arg TARGETARCH=amd64 .PHONY: push-amd64 push-amd64: @@ -95,7 +100,7 @@ push-amd64: @echo "------------------------------" @echo "--> Pushing image" @echo "------------------------------" - @sudo docker push litmuschaos/go-runner:ci + @sudo docker push $(DOCKER_REPO)/$(DOCKER_IMAGE):$(DOCKER_TAG) .PHONY: push push: litmus-go-push @@ -104,7 +109,7 @@ litmus-go-push: @echo "-------------------" @echo "--> go-runner image" @echo "-------------------" - REPONAME="litmuschaos" IMGNAME="go-runner" IMGTAG="ci" ./build/push + REPONAME="$(DOCKER_REPO)" IMGNAME="$(DOCKER_IMAGE)" IMGTAG="$(DOCKER_TAG)" ./build/push .PHONY: trivy-check trivy-check: @@ -112,6 +117,6 @@ trivy-check: @echo "------------------------" @echo "---> Running Trivy Check" @echo "------------------------" - @./trivy --exit-code 0 --severity HIGH --no-progress litmuschaos/go-runner:ci - @./trivy --exit-code 0 --severity CRITICAL --no-progress litmuschaos/go-runner:ci + @./trivy --exit-code 0 --severity HIGH --no-progress $(DOCKER_REPO)/$(DOCKER_IMAGE):$(DOCKER_TAG) + @./trivy --exit-code 0 --severity CRITICAL --no-progress $(DOCKER_REPO)/$(DOCKER_IMAGE):$(DOCKER_TAG) diff --git a/chaoslib/pumba/cpu-chaos/lib/cpu-chaos.go b/chaoslib/pumba/cpu-chaos/lib/cpu-chaos.go index 584cc6451..ddd492f56 100644 --- a/chaoslib/pumba/cpu-chaos/lib/cpu-chaos.go +++ b/chaoslib/pumba/cpu-chaos/lib/cpu-chaos.go @@ -190,7 +190,7 @@ func CreateHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clie Name: "dockersocket", VolumeSource: apiv1.VolumeSource{ HostPath: &apiv1.HostPathVolumeSource{ - Path: "/var/run/docker.sock", + Path: experimentsDetails.SocketPath, }, }, }, @@ -204,7 +204,7 @@ func CreateHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clie VolumeMounts: []apiv1.VolumeMount{ { Name: "dockersocket", - MountPath: "/var/run/docker.sock", + MountPath: experimentsDetails.SocketPath, }, }, ImagePullPolicy: apiv1.PullPolicy(experimentsDetails.LIBImagePullPolicy), diff --git a/chaoslib/pumba/memory-chaos/lib/memory-chaos.go b/chaoslib/pumba/memory-chaos/lib/memory-chaos.go index dfbd9a0bf..ae2106877 100644 --- a/chaoslib/pumba/memory-chaos/lib/memory-chaos.go +++ b/chaoslib/pumba/memory-chaos/lib/memory-chaos.go @@ -190,7 +190,7 @@ func CreateHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clie Name: "dockersocket", VolumeSource: apiv1.VolumeSource{ HostPath: &apiv1.HostPathVolumeSource{ - Path: "/var/run/docker.sock", + Path: experimentsDetails.SocketPath, }, }, }, @@ -204,7 +204,7 @@ func CreateHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clie VolumeMounts: []apiv1.VolumeMount{ { Name: "dockersocket", - MountPath: "/var/run/docker.sock", + MountPath: experimentsDetails.SocketPath, }, }, ImagePullPolicy: apiv1.PullPolicy(experimentsDetails.LIBImagePullPolicy), diff --git a/chaoslib/pumba/pod-io-stress/lib/pod-io-stress.go b/chaoslib/pumba/pod-io-stress/lib/pod-io-stress.go index e78e82e90..dea8615c7 100644 --- a/chaoslib/pumba/pod-io-stress/lib/pod-io-stress.go +++ b/chaoslib/pumba/pod-io-stress/lib/pod-io-stress.go @@ -192,7 +192,7 @@ func CreateHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clie Name: "dockersocket", VolumeSource: apiv1.VolumeSource{ HostPath: &apiv1.HostPathVolumeSource{ - Path: "/var/run/docker.sock", + Path: experimentsDetails.SocketPath, }, }, }, @@ -206,7 +206,7 @@ func CreateHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clie VolumeMounts: []apiv1.VolumeMount{ { Name: "dockersocket", - MountPath: "/var/run/docker.sock", + MountPath: experimentsDetails.SocketPath, }, }, ImagePullPolicy: apiv1.PullPolicy(experimentsDetails.LIBImagePullPolicy), diff --git a/pkg/generic/pod-cpu-hog/environment/environment.go b/pkg/generic/pod-cpu-hog/environment/environment.go index c2a563ad4..c2e1ea127 100644 --- a/pkg/generic/pod-cpu-hog/environment/environment.go +++ b/pkg/generic/pod-cpu-hog/environment/environment.go @@ -35,6 +35,7 @@ func GetENV(experimentDetails *experimentTypes.ExperimentDetails) { experimentDetails.LIBImagePullPolicy = Getenv("LIB_IMAGE_PULL_POLICY", "Always") experimentDetails.TargetContainer = Getenv("TARGET_CONTAINER", "") experimentDetails.Sequence = Getenv("SEQUENCE", "parallel") + experimentDetails.SocketPath = Getenv("SOCKET_PATH", "/var/run/docker.sock") } diff --git a/pkg/generic/pod-cpu-hog/types/types.go b/pkg/generic/pod-cpu-hog/types/types.go index 722773ac5..3bfa1b0cf 100644 --- a/pkg/generic/pod-cpu-hog/types/types.go +++ b/pkg/generic/pod-cpu-hog/types/types.go @@ -32,5 +32,6 @@ type ExperimentDetails struct { Annotations map[string]string TargetContainer string Sequence string + SocketPath string Resources corev1.ResourceRequirements } diff --git a/pkg/generic/pod-io-stress/environment/environment.go b/pkg/generic/pod-io-stress/environment/environment.go index 06bbc5a33..f92669ab6 100644 --- a/pkg/generic/pod-io-stress/environment/environment.go +++ b/pkg/generic/pod-io-stress/environment/environment.go @@ -34,6 +34,7 @@ func GetENV(experimentDetails *experimentTypes.ExperimentDetails) { experimentDetails.PodsAffectedPerc, _ = strconv.Atoi(Getenv("PODS_AFFECTED_PERC", "0")) experimentDetails.Sequence = Getenv("SEQUENCE", "parallel") experimentDetails.VolumeMountPath = Getenv("VOLUME_MOUNT_PATH", "") + experimentDetails.SocketPath = Getenv("SOCKET_PATH", "/var/run/docker.sock") } diff --git a/pkg/generic/pod-io-stress/types/types.go b/pkg/generic/pod-io-stress/types/types.go index eab666cff..e8cc9d5c9 100644 --- a/pkg/generic/pod-io-stress/types/types.go +++ b/pkg/generic/pod-io-stress/types/types.go @@ -31,5 +31,6 @@ type ExperimentDetails struct { PodsAffectedPerc int Sequence string VolumeMountPath string + SocketPath string Resources corev1.ResourceRequirements } diff --git a/pkg/generic/pod-memory-hog/environment/environment.go b/pkg/generic/pod-memory-hog/environment/environment.go index eb95d46a1..103d4ca7d 100644 --- a/pkg/generic/pod-memory-hog/environment/environment.go +++ b/pkg/generic/pod-memory-hog/environment/environment.go @@ -34,6 +34,7 @@ func GetENV(experimentDetails *experimentTypes.ExperimentDetails) { experimentDetails.LIBImagePullPolicy = Getenv("LIB_IMAGE_PULL_POLICY", "Always") experimentDetails.TargetContainer = Getenv("TARGET_CONTAINER", "") experimentDetails.Sequence = Getenv("SEQUENCE", "parallel") + experimentDetails.SocketPath = Getenv("SOCKET_PATH", "/var/run/docker.sock") } // Getenv fetch the env and set the default value, if any diff --git a/pkg/generic/pod-memory-hog/types/types.go b/pkg/generic/pod-memory-hog/types/types.go index 46c8a16f7..5d71ccf79 100644 --- a/pkg/generic/pod-memory-hog/types/types.go +++ b/pkg/generic/pod-memory-hog/types/types.go @@ -31,5 +31,6 @@ type ExperimentDetails struct { Annotations map[string]string TargetContainer string Sequence string + SocketPath string Resources corev1.ResourceRequirements }