Skip to content

Commit

Permalink
push docker
Browse files Browse the repository at this point in the history
  • Loading branch information
topahadzi committed Nov 17, 2023
1 parent 5e48cfd commit 0c69b4d
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 133 deletions.
116 changes: 41 additions & 75 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,92 +1,58 @@
---
name: Build
name: docker

on:
pull_request:
branches: [master]
types: [opened, synchronize, reopened]
push:
tags:
- "v*"

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository_owner }}/litmus-node-fault

jobs:
pre-checks:
release:
runs-on: ubuntu-latest
steps:
# Install golang
- uses: actions/setup-go@v2
with:
go-version: 1.18

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

#TODO: Add Dockerfile linting
# Running go-lint
- name: Checking Go-Lint
run : |
sudo apt-get update && sudo apt-get install golint
make gotasks

- name: gofmt check
run: |
if [ "$(gofmt -s -l . | wc -l)" -ne 0 ]
then
echo "The following files were found to be not go formatted:"
gofmt -s -l .
exit 1
fi
- name: golangci-lint
uses: reviewdog/action-golangci-lint@v1

build:
needs: pre-checks
runs-on: ubuntu-latest
steps:
# Install golang
- uses: actions/setup-go@v2
with:
go-version: 1.18
- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
platforms: all
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
- id: docker_meta
uses: docker/metadata-action@v4
with:
version: latest
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
- name: Build and push
uses: docker/build-push-action@v2
- id: docker_build
name: Build and push Docker image
uses: docker/build-push-action@v3
with:
push: false
platforms: linux/amd64
push: true
file: build/Dockerfile
platforms: linux/amd64,linux/arm64
tags: litmuschaos/go-runner:ci
tags: ${{ steps.docker_meta.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }}

trivy:
needs: pre-checks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Install Cosign
uses: sigstore/cosign-installer@main

- name: Build an image from Dockerfile
- name: Sign image with a key
run: |
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'
cosign sign --key env://COSIGN_PRIVATE_KEY ${IMAGE_NAME,,}@${IMAGE_DIGEST} --yes
env:
IMAGE_NAME: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
IMAGE_DIGEST: ${{ steps.docker_build.outputs.digest }}
COSIGN_PRIVATE_KEY: ${{secrets.COSIGN_PRIVATE_KEY}}
COSIGN_PASSWORD: ${{secrets.COSIGN_PASSWORD}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"id_token":"eyJhbGciOiJSUzI1NiIsImtpZCI6IjhlYTFiNWY1YzY5NDU2Y2MyZjVhNzM2MWYwZTQ5NzliIiwidHlwIjoiSldUIn0.eyJpc3MiOiJodHRwczovL2F1dGhlbnRpay52aXJhLnNoL2FwcGxpY2F0aW9uL28va3ViZXJuZXRlcy8iLCJzdWIiOiJ0b3BhaGFkemkiLCJhdWQiOiI1UkVDUkxrOHA0Wmh0TFJCTll5OWhpd3hiUTNZSFh2RHJCUnY4YlExIiwiZXhwIjoxNzAwMDMyMjEwLCJpYXQiOjE2OTk5NDU4MTAsImF1d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OwMuFTAC-V5JJcVpUAE3Mni9GVfErR13BscVbO9ZoSAFG4bZ-osOgGZRIsiMbgy-A2P365_W60NIOgeFx5wtT2WJf-koCOlVHy9MMAD-P1jbMcPChY78I_S4nLIp3ulsewhBaZlVQQpz-WxFBvclFRTTkBq_KSs5wJMxTkdzZCrB0EhDP9ziDcCgW0wizQNiJlkKhOR1GcQWM6wV4rt_D2xs3z3vUDA58uxVjgQqUNTWcM8iKduoz8mGqlwQen3eH-CqIUAsUQqdX0XNO35stpxQI_WEc6XQ","refresh_token":"xutGWgtbRVSkiE6z5v5Qtuk75IskPgT4SfNDdOkyCIUsJ1lE4azQMQmrgqdrFxyHVcXFPLpzXa2PTqzcsDM7rcgXMAz30y8QKFFztOXwmz1yjTBibf7EAkCWFBDi5L8c"}
9 changes: 5 additions & 4 deletions bin/experiment/experiment.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ import (
nodeDrain "github.com/litmuschaos/litmus-go/experiments/generic/node-drain/experiment"
nodeIOStress "github.com/litmuschaos/litmus-go/experiments/generic/node-io-stress/experiment"
nodeMemoryHog "github.com/litmuschaos/litmus-go/experiments/generic/node-memory-hog/experiment"
nodeRestart "github.com/litmuschaos/litmus-go/experiments/generic/node-restart/experiment"
viraNodeRestart "github.com/litmuschaos/litmus-go/experiments/kubernetes/node-restart/experiment"

// nodeRestart "github.com/litmuschaos/litmus-go/experiments/generic/node-restart/experiment"
nodeTaint "github.com/litmuschaos/litmus-go/experiments/generic/node-taint/experiment"
podAutoscaler "github.com/litmuschaos/litmus-go/experiments/generic/pod-autoscaler/experiment"
podCPUHogExec "github.com/litmuschaos/litmus-go/experiments/generic/pod-cpu-hog-exec/experiment"
Expand All @@ -57,6 +57,7 @@ import (
ebsLossByTag "github.com/litmuschaos/litmus-go/experiments/kube-aws/ebs-loss-by-tag/experiment"
ec2TerminateByID "github.com/litmuschaos/litmus-go/experiments/kube-aws/ec2-terminate-by-id/experiment"
ec2TerminateByTag "github.com/litmuschaos/litmus-go/experiments/kube-aws/ec2-terminate-by-tag/experiment"
viraNodeRestart "github.com/litmuschaos/litmus-go/experiments/kubernetes/node-restart/experiment"
springBootFaults "github.com/litmuschaos/litmus-go/experiments/spring-boot/spring-boot-faults/experiment"
vmpoweroff "github.com/litmuschaos/litmus-go/experiments/vmware/vm-poweroff/experiment"

Expand Down Expand Up @@ -149,8 +150,8 @@ func main() {
ebsLossByID.EBSLossByID(clients)
case "ebs-loss-by-tag":
ebsLossByTag.EBSLossByTag(clients)
case "node-restart":
nodeRestart.NodeRestart(clients)
// case "node-restart":
// nodeRestart.NodeRestart(clients)
case "vira-node-restart":
viraNodeRestart.NodeRestart(clients)
case "pod-dns-error":
Expand Down
6 changes: 6 additions & 0 deletions build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,9 @@ COPY --from=dep /sbin/iptables /sbin/

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

USER root
RUN curl -LO https://github.com/kvaps/kubectl-node-shell/raw/master/kubectl-node_shell
RUN chmod +x ./kubectl-node_shell
RUN mv ./kubectl-node_shell /usr/local/bin/kubectl-node_shell
USER litmus
19 changes: 5 additions & 14 deletions chaoslib/litmus/vira/node-restart/lib/node-restart.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ package lib
import (
"context"
"fmt"
"github.com/litmuschaos/litmus-go/pkg/cerrors"
"github.com/palantir/stacktrace"
"os"
"os/exec"
"os/signal"
"strconv"
"strings"
"syscall"
"time"

"github.com/litmuschaos/litmus-go/pkg/cerrors"
"github.com/palantir/stacktrace"

clients "github.com/litmuschaos/litmus-go/pkg/clients"
"github.com/litmuschaos/litmus-go/pkg/events"
experimentTypes "github.com/litmuschaos/litmus-go/pkg/kubernetes/node-restart/types"
Expand All @@ -22,7 +21,6 @@ import (
"github.com/litmuschaos/litmus-go/pkg/types"
"github.com/litmuschaos/litmus-go/pkg/utils/common"
"github.com/litmuschaos/litmus-go/pkg/utils/retry"
apierrors "k8s.io/apimachinery/pkg/api/errors"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand All @@ -31,7 +29,7 @@ var (
inject, abort chan os.Signal
)

//PrepareNodeRestart contains the preparation steps before chaos injection
// PrepareNodeRestart contains the preparation steps before chaos injection
func PrepareNodeRestart(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error {

// inject channel is used to transmit signal notifications.
Expand Down Expand Up @@ -92,9 +90,6 @@ func PrepareNodeRestart(experimentsDetails *experimentTypes.ExperimentDetails, c
log.Info("[Status]: Verify that the Auxiliary Applications are running")
if err = status.CheckAuxiliaryApplicationStatus(experimentsDetails.AuxiliaryAppInfo, experimentsDetails.Timeout, experimentsDetails.Delay, clients); err != nil {
log.Info("[Revert]: Reverting chaos because auxiliary application status check failed")
if uncordonErr := uncordonNode(experimentsDetails, clients, chaosDetails); uncordonErr != nil {
return cerrors.PreserveError{ErrString: fmt.Sprintf("[%s,%s]", stacktrace.RootCause(err).Error(), stacktrace.RootCause(uncordonErr).Error())}
}
return err
}
}
Expand All @@ -105,7 +100,6 @@ func PrepareNodeRestart(experimentsDetails *experimentTypes.ExperimentDetails, c

log.Info("[Chaos]: Stopping the experiment")


//Waiting for the ramp time after chaos injection
if experimentsDetails.RampTime != 0 {
log.Infof("[Ramp]: Waiting for the %vs ramp time after injecting chaos", experimentsDetails.RampTime)
Expand All @@ -124,7 +118,7 @@ func restartNode(experimentsDetails *experimentTypes.ExperimentDetails, clients
default:
log.Infof("[Inject]: Restarting the %v node", experimentsDetails.TargetNode)

command := exec.Command("kubectl", "node_shell", experimentsDetails.TargetNode, "--", "shutdown", "-r", "now")
command := exec.Command("kubectl", "node_shell", experimentsDetails.TargetNode, "--", "shutdown", "-r", "+3")
if err := common.RunCLICommands(command, "", fmt.Sprintf("{node: %s}", experimentsDetails.TargetNode), "failed to restart the target node", cerrors.ErrorTypeChaosInject); err != nil {
return err
}
Expand Down Expand Up @@ -158,9 +152,6 @@ func abortWatcher(experimentsDetails *experimentTypes.ExperimentDetails, clients
// retry thrice for the chaos revert
retry := 3
for retry > 0 {
if err := uncordonNode(experimentsDetails, clients, chaosDetails); err != nil {
log.Errorf("Unable to uncordon the node, err: %v", err)
}
retry--
time.Sleep(1 * time.Second)
}
Expand Down
4 changes: 4 additions & 0 deletions cosign.pub
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-----BEGIN PUBLIC KEY-----
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEecYo6AqKFTb9su1Kcodys3hvO+Fl
3R/vJCyD8/aQR39T+251p/4qCAsjsb4EJ/fWD5rbnilgBCbTIyIARVz7jQ==
-----END PUBLIC KEY-----
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"os"

"github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1"
litmusLIB "github.com/litmuschaos/litmus-go/chaoslib/litmus/kubernete/node-restart/lib"
litmusLIB "github.com/litmuschaos/litmus-go/chaoslib/litmus/vira/node-restart/lib"
"github.com/litmuschaos/litmus-go/pkg/clients"
"github.com/litmuschaos/litmus-go/pkg/events"
experimentEnv "github.com/litmuschaos/litmus-go/pkg/kubernetes/node-restart/environment"
Expand Down
31 changes: 16 additions & 15 deletions pkg/kubernetes/node-restart/environment/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,30 @@ import (
"github.com/litmuschaos/litmus-go/pkg/types"
)

// STEPS TO GETENV OF YOUR CHOICE HERE
// ADDED FOR FEW MANDATORY FIELD

//GetENV fetches all the env variables from the runner pod
// GetENV fetches all the env variables from the runner pod
func GetENV(experimentDetails *experimentTypes.ExperimentDetails) {
experimentDetails.ExperimentName = types.Getenv("EXPERIMENT_NAME", "")
experimentDetails.ExperimentName = types.Getenv("EXPERIMENT_NAME", "node-restart")
experimentDetails.ChaosNamespace = types.Getenv("CHAOS_NAMESPACE", "litmus")
experimentDetails.EngineName = types.Getenv("CHAOSENGINE", "")
experimentDetails.ChaosDuration, _ = strconv.Atoi(types.Getenv("TOTAL_CHAOS_DURATION", "30"))
experimentDetails.ChaosInterval, _ = strconv.Atoi(types.Getenv("CHAOS_INTERVAL", "10"))
experimentDetails.ChaosDuration, _ = strconv.Atoi(types.Getenv("TOTAL_CHAOS_DURATION", "60"))
experimentDetails.RampTime, _ = strconv.Atoi(types.Getenv("RAMP_TIME", "0"))
experimentDetails.AppNS = types.Getenv("APP_NAMESPACE", "")
experimentDetails.AppLabel = types.Getenv("APP_LABEL", "")
experimentDetails.AppKind = types.Getenv("APP_KIND", "")
experimentDetails.AuxiliaryAppInfo = types.Getenv("AUXILIARY_APPINFO","")
experimentDetails.ChaosUID = clientTypes.UID(types.Getenv("CHAOS_UID", ""))
experimentDetails.InstanceID = types.Getenv("INSTANCE_ID", "")
experimentDetails.ChaosPodName = types.Getenv("POD_NAME", "")
experimentDetails.AuxiliaryAppInfo = types.Getenv("AUXILIARY_APPINFO", "")
experimentDetails.TargetNode = types.Getenv("TARGET_NODE", "")
experimentDetails.Delay, _ = strconv.Atoi(types.Getenv("STATUS_CHECK_DELAY", "2"))
experimentDetails.Timeout, _ = strconv.Atoi(types.Getenv("STATUS_CHECK_TIMEOUT", "180"))
experimentDetails.ChaosInjectCmd = types.Getenv("CHAOS_INJECT_COMMAND", "")
experimentDetails.ChaosKillCmd = types.Getenv("CHAOS_KILL_COMMAND", "")
experimentDetails.TargetContainer = types.Getenv("TARGET_CONTAINER", "")
experimentDetails.TargetPods = types.Getenv("TARGET_PODS", "")
experimentDetails.PodsAffectedPerc, _ = strconv.Atoi(types.Getenv("PODS_AFFECTED_PERC", "0"))
experimentDetails.NodeLabel = types.Getenv("NODE_LABEL", "")
experimentDetails.AppNS, experimentDetails.AppKind, experimentDetails.AppLabel = getAppDetails()
}

func getAppDetails() (string, string, string) {
targets := types.Getenv("TARGETS", "")
app := types.GetTargets(targets)
if len(app) != 0 {
return app[0].Namespace, app[0].Kind, app[0].Labels[0]
}
return "", "", ""
}
41 changes: 17 additions & 24 deletions pkg/kubernetes/node-restart/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,24 @@ import (
clientTypes "k8s.io/apimachinery/pkg/types"
)

// ADD THE ATTRIBUTES OF YOUR CHOICE HERE
// FEW MANDATORY ATTRIBUTES ARE ADDED BY DEFAULT

// ExperimentDetails is for collecting all the experiment-related details
type ExperimentDetails struct {
ExperimentName string
EngineName string
ChaosDuration int
ChaosInterval int
RampTime int
AppNS string
AppLabel string
AppKind string
AuxiliaryAppInfo string
ChaosUID clientTypes.UID
InstanceID string
ChaosNamespace string
ChaosPodName string
Timeout int
Delay int
TargetContainer string
ChaosInjectCmd string
ChaosKillCmd string
PodsAffectedPerc int
TargetPods string
ExperimentName string
EngineName string
ChaosDuration int
RampTime int
AppNS string
AppLabel string
AppKind string
ChaosUID clientTypes.UID
InstanceID string
ChaosNamespace string
ChaosPodName string
TargetNode string
AuxiliaryAppInfo string
Timeout int
Delay int
LIBImagePullPolicy string
IsTargetContainerProvided bool
TargetContainer string
NodeLabel string
}

0 comments on commit 0c69b4d

Please sign in to comment.