From 57e5a1e442dd9db7ac665a817de68ed369f58664 Mon Sep 17 00:00:00 2001 From: topahadzi Date: Fri, 17 Nov 2023 16:23:54 +0700 Subject: [PATCH] generate kubeconfig for node shell --- .github/CODEOWNERS | 5 - .github/ISSUE_TEMPLATE.md | 27 -- .github/PULL_REQUEST_TEMPLATE.md | 18 - .github/auto-merge.yml | 23 -- .github/workflows/push.yml | 72 ---- .github/workflows/release.yml | 70 ---- .github/workflows/run-e2e-on-pr-commits.yml | 358 ------------------ .github/workflows/security-scan.yml | 35 -- .../vira/node-restart/lib/node-restart.go | 5 +- 9 files changed, 4 insertions(+), 609 deletions(-) delete mode 100644 .github/CODEOWNERS delete mode 100644 .github/ISSUE_TEMPLATE.md delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/auto-merge.yml delete mode 100644 .github/workflows/push.yml delete mode 100644 .github/workflows/release.yml delete mode 100644 .github/workflows/run-e2e-on-pr-commits.yml delete mode 100644 .github/workflows/security-scan.yml diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS deleted file mode 100644 index fa08998..0000000 --- a/.github/CODEOWNERS +++ /dev/null @@ -1,5 +0,0 @@ -# Lines starting with '#' are comments. -# Each line is a file pattern followed by one or more owners. - -# These owners will be the default owners for everything in the repo. -* @ispeakc0de @ksatchit @uditgaurav diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md deleted file mode 100644 index 6716fbd..0000000 --- a/.github/ISSUE_TEMPLATE.md +++ /dev/null @@ -1,27 +0,0 @@ - - - -## Is this a BUG REPORT or FEATURE REQUEST? - - Choose one: BUG REPORT or FEATURE REQUEST - - - -**What happened**: - -**What you expected to happen**: - -**How to reproduce it (as minimally and precisely as possible)**: - -**Anything else we need to know?**: \ No newline at end of file diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 21d9554..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,18 +0,0 @@ - - -**What this PR does / why we need it**: - -**Which issue this PR fixes** *(optional, in `fixes #(, fixes #, ...)` format, will close that issue when PR gets merged)*: fixes # - -**Special notes for your reviewer**: - -**Checklist:** -- [ ] Fixes # -- [ ] PR messages has document related information -- [ ] Labelled this PR & related issue with `breaking-changes` tag -- [ ] PR messages has breaking changes related information -- [ ] Labelled this PR & related issue with `requires-upgrade` tag -- [ ] PR messages has upgrade related information -- [ ] Commit has unit tests -- [ ] Commit has integration tests -- [ ] E2E run Required for the changes diff --git a/.github/auto-merge.yml b/.github/auto-merge.yml deleted file mode 100644 index 5d95110..0000000 --- a/.github/auto-merge.yml +++ /dev/null @@ -1,23 +0,0 @@ -# Configuration for probot-auto-merge - https://github.com/bobvanderlinden/probot-auto-merge - -reportStatus: true -updateBranch: false -deleteBranchAfterMerge: true -mergeMethod: squash - -minApprovals: - COLLABORATOR: 0 -maxRequestedChanges: - NONE: 0 -blockingLabels: -- DO NOT MERGE -- WIP -- blocked - -# Will merge whenever the above conditions are met, but also -# the owner has approved or merge label was added. -rules: -- minApprovals: - OWNER: 1 -- requiredLabels: - - merge diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml deleted file mode 100644 index e093af6..0000000 --- a/.github/workflows/push.yml +++ /dev/null @@ -1,72 +0,0 @@ ---- -name: Push -on: - push: - branches: - - master - tags-ignore: - - '**' -jobs: - pre-checks: - runs-on: ubuntu-latest - steps: - # Install golang - - uses: actions/setup-go@v2 - with: - go-version: 1.18 - - uses: actions/checkout@v2 - - #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 - - push: - needs: pre-checks - runs-on: ubuntu-latest - steps: - - # Install golang - - uses: actions/setup-go@v2 - with: - go-version: 1.18 - - uses: actions/checkout@v2 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v1 - with: - platforms: all - - - name: Set up Docker Buildx - id: buildx - uses: docker/setup-buildx-action@v1 - with: - version: latest - - - name: Login to Docker Hub - uses: docker/login-action@v1 - with: - username: ${{ secrets.DNAME }} - password: ${{ secrets.DPASS }} - - - name: Build and push - uses: docker/build-push-action@v2 - with: - push: true - file: build/Dockerfile - platforms: linux/amd64,linux/arm64 - tags: litmuschaos/go-runner:ci diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index fcdf080..0000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,70 +0,0 @@ ---- -name: Release -on: - create: - tags: - - '**' - -jobs: - pre-checks: - runs-on: ubuntu-latest - steps: - # Install golang - - uses: actions/setup-go@v2 - with: - go-version: 1.18 - - uses: actions/checkout@v2 - - #TODO: Add Dockerfile linting - # Running go-lint - - name: Checking Go-Lint - run : | - sudo apt-get update && sudo apt-get install golint - make gotasks - push: - needs: pre-checks - runs-on: ubuntu-latest - steps: - # Install golang - - uses: actions/setup-go@v2 - with: - go-version: 1.18 - - uses: actions/checkout@v2 - - - name: Set Tag - run: | - TAG="${GITHUB_REF#refs/*/}" - echo "TAG=${TAG}" >> $GITHUB_ENV - echo "RELEASE_TAG=${TAG}" >> $GITHUB_ENV - - - name: Print Tag info - run: | - echo "RELEASE TAG: ${RELEASE_TAG}" - echo "${RELEASE_TAG}" > ${{ github.workspace }}/tag.txt - - - name: Set up QEMU - uses: docker/setup-qemu-action@v1 - with: - platforms: all - - - name: Set up Docker Buildx - id: buildx - uses: docker/setup-buildx-action@v1 - with: - version: latest - - - name: Login to Docker Hub - uses: docker/login-action@v1 - with: - username: ${{ secrets.DNAME }} - password: ${{ secrets.DPASS }} - - - name: Build and push - uses: docker/build-push-action@v2 - env: - RELEASE_TAG: ${{ env.RELEASE_TAG }} - with: - push: true - file: build/Dockerfile - platforms: linux/amd64,linux/arm64 - tags: litmuschaos/go-runner:${{ env.RELEASE_TAG }},litmuschaos/go-runner:latest diff --git a/.github/workflows/run-e2e-on-pr-commits.yml b/.github/workflows/run-e2e-on-pr-commits.yml deleted file mode 100644 index bfe84f9..0000000 --- a/.github/workflows/run-e2e-on-pr-commits.yml +++ /dev/null @@ -1,358 +0,0 @@ -name: E2E -on: - pull_request: - branches: [master] - types: [opened, synchronize, reopened] - paths-ignore: - - '**.md' - - '**.yml' - - '**.yaml' - -jobs: - # Helm_Install_Generic_Tests: - # runs-on: ubuntu-18.04 - # steps: - - # - uses: actions/checkout@v2 - # with: - # ref: ${{ github.event.pull_request.head.sha }} - - # - name: Generate go binary and build docker image - # run: make build-amd64 - - # #Install and configure a kind cluster - # - name: Installing KinD cluster for the test - # uses: engineerd/setup-kind@v0.5.0 - # with: - # version: "v0.7.0" - # config: "build/kind-cluster/kind-config.yaml" - - # - name: Configuring and testing the Installation - # run: | - # kubectl taint nodes kind-control-plane node-role.kubernetes.io/master- - # kind get kubeconfig --internal >$HOME/.kube/config - # kubectl cluster-info --context kind-kind - # kubectl get nodes - - # - name: Load docker image - # run: /usr/local/bin/kind load docker-image litmuschaos/go-runner:ci - - # - name: Deploy a sample application for chaos injection - # run: | - # kubectl apply -f https://raw.githubusercontent.com/litmuschaos/chaos-ci-lib/master/app/nginx.yml - # kubectl wait --for=condition=Ready pods --all --namespace default --timeout=90s - - # - name: Setting up kubeconfig ENV for Github Chaos Action - # run: echo ::set-env name=KUBE_CONFIG_DATA::$(base64 -w 0 ~/.kube/config) - # env: - # ACTIONS_ALLOW_UNSECURE_COMMANDS: true - - # - name: Setup Litmus - # uses: litmuschaos/github-chaos-actions@master - # env: - # INSTALL_LITMUS: true - - # - name: Running Litmus pod delete chaos experiment - # if: always() - # uses: litmuschaos/github-chaos-actions@master - # env: - # EXPERIMENT_NAME: pod-delete - # EXPERIMENT_IMAGE: litmuschaos/go-runner - # EXPERIMENT_IMAGE_TAG: ci - # IMAGE_PULL_POLICY: IfNotPresent - # JOB_CLEANUP_POLICY: delete - - # - name: Running container kill chaos experiment - # if: always() - # uses: litmuschaos/github-chaos-actions@master - # env: - # EXPERIMENT_NAME: container-kill - # EXPERIMENT_IMAGE: litmuschaos/go-runner - # EXPERIMENT_IMAGE_TAG: ci - # IMAGE_PULL_POLICY: IfNotPresent - # JOB_CLEANUP_POLICY: delete - # CONTAINER_RUNTIME: containerd - - # - name: Running node-cpu-hog chaos experiment - # if: always() - # uses: litmuschaos/github-chaos-actions@master - # env: - # EXPERIMENT_NAME: node-cpu-hog - # EXPERIMENT_IMAGE: litmuschaos/go-runner - # EXPERIMENT_IMAGE_TAG: ci - # IMAGE_PULL_POLICY: IfNotPresent - # JOB_CLEANUP_POLICY: delete - - - # - name: Running node-memory-hog chaos experiment - # if: always() - # uses: litmuschaos/github-chaos-actions@master - # env: - # EXPERIMENT_NAME: node-memory-hog - # EXPERIMENT_IMAGE: litmuschaos/go-runner - # EXPERIMENT_IMAGE_TAG: ci - # IMAGE_PULL_POLICY: IfNotPresent - # JOB_CLEANUP_POLICY: delete - - # - name: Running pod-cpu-hog chaos experiment - # if: always() - # uses: litmuschaos/github-chaos-actions@master - # env: - # EXPERIMENT_NAME: pod-cpu-hog - # EXPERIMENT_IMAGE: litmuschaos/go-runner - # EXPERIMENT_IMAGE_TAG: ci - # IMAGE_PULL_POLICY: IfNotPresent - # JOB_CLEANUP_POLICY: delete - # TARGET_CONTAINER: nginx - # TOTAL_CHAOS_DURATION: 60 - # CPU_CORES: 1 - - # - name: Running pod-memory-hog chaos experiment - # if: always() - # uses: litmuschaos/github-chaos-actions@master - # env: - # EXPERIMENT_NAME: pod-memory-hog - # EXPERIMENT_IMAGE: litmuschaos/go-runner - # EXPERIMENT_IMAGE_TAG: ci - # IMAGE_PULL_POLICY: IfNotPresent - # JOB_CLEANUP_POLICY: delete - # TARGET_CONTAINER: nginx - # TOTAL_CHAOS_DURATION: 60 - # MEMORY_CONSUMPTION: 500 - - # - name: Running pod network corruption chaos experiment - # if: always() - # uses: litmuschaos/github-chaos-actions@master - # env: - # EXPERIMENT_NAME: pod-network-corruption - # EXPERIMENT_IMAGE: litmuschaos/go-runner - # EXPERIMENT_IMAGE_TAG: ci - # IMAGE_PULL_POLICY: IfNotPresent - # JOB_CLEANUP_POLICY: delete - # TARGET_CONTAINER: nginx - # TOTAL_CHAOS_DURATION: 60 - # NETWORK_INTERFACE: eth0 - # CONTAINER_RUNTIME: containerd - - # - name: Running pod network duplication chaos experiment - # if: always() - # uses: litmuschaos/github-chaos-actions@master - # env: - # EXPERIMENT_NAME: pod-network-duplication - # EXPERIMENT_IMAGE: litmuschaos/go-runner - # EXPERIMENT_IMAGE_TAG: ci - # IMAGE_PULL_POLICY: IfNotPresent - # JOB_CLEANUP_POLICY: delete - # TARGET_CONTAINER: nginx - # TOTAL_CHAOS_DURATION: 60 - # NETWORK_INTERFACE: eth0 - # CONTAINER_RUNTIME: containerd - - # - name: Running pod-network-latency chaos experiment - # if: always() - # uses: litmuschaos/github-chaos-actions@master - # env: - # EXPERIMENT_NAME: pod-network-latency - # EXPERIMENT_IMAGE: litmuschaos/go-runner - # EXPERIMENT_IMAGE_TAG: ci - # IMAGE_PULL_POLICY: IfNotPresent - # JOB_CLEANUP_POLICY: delete - # TARGET_CONTAINER: nginx - # TOTAL_CHAOS_DURATION: 60 - # NETWORK_INTERFACE: eth0 - # NETWORK_LATENCY: 60000 - # CONTAINER_RUNTIME: containerd - - # - name: Running pod-network-loss chaos experiment - # if: always() - # uses: litmuschaos/github-chaos-actions@master - # env: - # EXPERIMENT_NAME: pod-network-loss - # EXPERIMENT_IMAGE: litmuschaos/go-runner - # EXPERIMENT_IMAGE_TAG: ci - # IMAGE_PULL_POLICY: IfNotPresent - # JOB_CLEANUP_POLICY: delete - # TARGET_CONTAINER: nginx - # TOTAL_CHAOS_DURATION: 60 - # NETWORK_INTERFACE: eth0 - # NETWORK_PACKET_LOSS_PERCENTAGE: 100 - # CONTAINER_RUNTIME: containerd - - # - name: Running pod autoscaler chaos experiment - # if: always() - # uses: litmuschaos/github-chaos-actions@master - # env: - # EXPERIMENT_NAME: pod-autoscaler - # EXPERIMENT_IMAGE: litmuschaos/go-runner - # EXPERIMENT_IMAGE_TAG: ci - # IMAGE_PULL_POLICY: IfNotPresent - # JOB_CLEANUP_POLICY: delete - # TOTAL_CHAOS_DURATION: 60 - - # - name: Running node-io-stress chaos experiment - # if: always() - # uses: litmuschaos/github-chaos-actions@master - # env: - # EXPERIMENT_NAME: node-io-stress - # EXPERIMENT_IMAGE: litmuschaos/go-runner - # EXPERIMENT_IMAGE_TAG: ci - # IMAGE_PULL_POLICY: IfNotPresent - # JOB_CLEANUP_POLICY: delete - # TOTAL_CHAOS_DURATION: 120 - # FILESYSTEM_UTILIZATION_PERCENTAGE: 10 - - # - name: Uninstall Litmus - # uses: litmuschaos/github-chaos-actions@master - # env: - # LITMUS_CLEANUP: true - - # - name: Deleting KinD cluster - # if: always() - # run: kind delete cluster - - Pod_Level_In_Serial_Mode: - 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 }} - - - name: Generating Go binary and Building docker image - run: | - make build-amd64 - #Install and configure a kind cluster - - name: Installing Prerequisites (K3S Cluster) - env: - KUBECONFIG: /etc/rancher/k3s/k3s.yaml - run: | - curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION=v1.21.11+k3s1 sh -s - --docker --write-kubeconfig-mode 664 - kubectl wait node --all --for condition=ready --timeout=90s - kubectl get nodes - - - uses: actions/checkout@v2 - with: - repository: 'litmuschaos/litmus-e2e' - ref: 'master' - - - name: Running Pod level experiment with affected percentage 100 and in series mode - env: - GO_EXPERIMENT_IMAGE: litmuschaos/go-runner:ci - EXPERIMENT_IMAGE_PULL_POLICY: IfNotPresent - KUBECONFIG: /etc/rancher/k3s/k3s.yaml - run: | - make build-litmus - make app-deploy - make pod-affected-perc-ton-series - - name: Deleting K3S cluster - if: always() - run: /usr/local/bin/k3s-uninstall.sh - - Pod_Level_In_Parallel_Mode: - 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 }} - - - name: Generating Go binary and Building docker image - run: | - make build-amd64 - #Install and configure a kind cluster - - name: Installing Prerequisites (K3S Cluster) - env: - KUBECONFIG: /etc/rancher/k3s/k3s.yaml - run: | - curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION=v1.21.11+k3s1 sh -s - --docker --write-kubeconfig-mode 664 - kubectl wait node --all --for condition=ready --timeout=90s - kubectl get nodes - - uses: actions/checkout@v2 - with: - repository: 'litmuschaos/litmus-e2e' - ref: 'master' - - - name: Running Pod level experiment with affected percentage 100 and in parallel mode - env: - GO_EXPERIMENT_IMAGE: litmuschaos/go-runner:ci - EXPERIMENT_IMAGE_PULL_POLICY: IfNotPresent - KUBECONFIG: /etc/rancher/k3s/k3s.yaml - run: | - make build-litmus - make app-deploy - make pod-affected-perc-ton-parallel - - name: Deleting K3S cluster - if: always() - run: /usr/local/bin/k3s-uninstall.sh - - Node_Level_Tests: - 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 }} - - - name: Generating Go binary and Building docker image - run: | - make build-amd64 - - - name: Create KinD Cluster - run: kind create cluster --config build/kind-cluster/kind-config.yaml - - - name: Configuring and testing the Installation - run: | - kubectl taint nodes kind-control-plane node-role.kubernetes.io/control-plane- - kubectl cluster-info --context kind-kind - kubectl wait node --all --for condition=ready --timeout=90s - kubectl get nodes - - - name: Load image on the nodes of the cluster - run: | - kind load docker-image --name=kind litmuschaos/go-runner:ci - - - uses: actions/checkout@v2 - with: - repository: 'litmuschaos/litmus-e2e' - ref: 'master' - - - name: Setup litmus and deploy application - env: - KUBECONFIG: /home/runner/.kube/config - run: | - make build-litmus - make app-deploy - - - name: Running Node Drain experiments - env: - GO_EXPERIMENT_IMAGE: litmuschaos/go-runner:ci - EXPERIMENT_IMAGE_PULL_POLICY: IfNotPresent - KUBECONFIG: /home/runner/.kube/config - run: make node-drain - - - name: Running Node Taint experiments - if: always() - env: - GO_EXPERIMENT_IMAGE: litmuschaos/go-runner:ci - EXPERIMENT_IMAGE_PULL_POLICY: IfNotPresent - KUBECONFIG: /home/runner/.kube/config - run: make node-taint - - - name: Deleting KinD cluster - if: always() - run: kind delete cluster diff --git a/.github/workflows/security-scan.yml b/.github/workflows/security-scan.yml deleted file mode 100644 index 613d6ff..0000000 --- a/.github/workflows/security-scan.yml +++ /dev/null @@ -1,35 +0,0 @@ ---- -name: Security Scan -on: - workflow_dispatch: - -jobs: - snyk: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@master - - name: Run Snyk to check for vulnerabilities - uses: snyk/actions/golang@master - env: - SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} - - trivy: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - with: - ref: ${{ github.event.pull_request.head.sha }} - - - name: Build an image from Dockerfile - 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' diff --git a/chaoslib/litmus/vira/node-restart/lib/node-restart.go b/chaoslib/litmus/vira/node-restart/lib/node-restart.go index 2d20970..c2e1e51 100644 --- a/chaoslib/litmus/vira/node-restart/lib/node-restart.go +++ b/chaoslib/litmus/vira/node-restart/lib/node-restart.go @@ -117,7 +117,10 @@ func restartNode(experimentsDetails *experimentTypes.ExperimentDetails, clients os.Exit(0) default: log.Infof("[Inject]: Restarting the %v node", experimentsDetails.TargetNode) - + exec.Command("kubectl", "config", "set-cluster", "kubernetes", "--certificate-authority=/var/run/secrets/kubernetes.io/serviceaccount/ca.crt", "--server=https://kubernetes.default.svc") + exec.Command("kubectl", "config", "set-credentials", "sa", "--token", "$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)") + exec.Command("kubectl", "config", "set-context", "default", "--cluster", "kubernetes", "--user=sa") + exec.Command("kubectl", "config", "use-context", "default") 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