├── .github ├── CODEOWNERS ├── ISSUE_TEMPLATE.md ├── PULL_REQUEST_TEMPLATE.md ├── auto-merge.yml └── workflows │ ├── build.yml │ ├── e2e.yml │ ├── push.yml │ ├── release.yml │ └── security-scan.yml ├── .gitignore ├── .gitlab-ci.yml ├── CONTRIBUTING.md ├── LICENSE ├── Makefile ├── NOTICE.md ├── README.md ├── api └── litmuschaos │ └── v1alpha1 │ ├── chaosengine_types.go │ ├── chaosexperiment_types.go │ ├── chaosresult_types.go │ ├── groupversion_info.go │ └── zz_generated.deepcopy.go ├── build └── Dockerfile ├── controllers ├── chaosengine_controller.go └── chaosengine_controller_test.go ├── deploy ├── chaos_crds.yaml ├── crds │ ├── chaosengine_crd.yaml │ ├── chaosexperiment_crd.yaml │ └── chaosresults_crd.yaml ├── operator.yaml └── rbac.yaml ├── docs ├── chaos-operator-architecture.png └── developer.md ├── go.mod ├── go.sum ├── hack ├── boilerplate.go.txt └── update-codegen.sh ├── main.go ├── pkg ├── analytics │ ├── analytics.go │ └── uuid.go ├── client │ ├── clientset │ │ └── versioned │ │ │ ├── clientset.go │ │ │ ├── doc.go │ │ │ ├── fake │ │ │ ├── clientset_generated.go │ │ │ ├── doc.go │ │ │ └── register.go │ │ │ ├── scheme │ │ │ ├── doc.go │ │ │ └── register.go │ │ │ └── typed │ │ │ └── litmuschaos │ │ │ └── v1alpha1 │ │ │ ├── chaosengine.go │ │ │ ├── chaosexperiment.go │ │ │ ├── chaosresult.go │ │ │ ├── doc.go │ │ │ ├── fake │ │ │ ├── doc.go │ │ │ ├── fake_chaosengine.go │ │ │ ├── fake_chaosexperiment.go │ │ │ ├── fake_chaosresult.go │ │ │ └── fake_litmuschaos_client.go │ │ │ ├── generated_expansion.go │ │ │ └── litmuschaos_client.go │ ├── dynamic │ │ └── dynamic.go │ ├── informers │ │ └── externalversions │ │ │ ├── factory.go │ │ │ ├── generic.go │ │ │ ├── internalinterfaces │ │ │ └── factory_interfaces.go │ │ │ └── litmuschaos │ │ │ ├── interface.go │ │ │ └── v1alpha1 │ │ │ ├── chaosengine.go │ │ │ ├── chaosexperiment.go │ │ │ ├── chaosresult.go │ │ │ └── interface.go │ ├── kubernetes │ │ └── kubernetes.go │ └── listers │ │ └── litmuschaos │ │ └── v1alpha1 │ │ ├── chaosengine.go │ │ ├── chaosexperiment.go │ │ ├── chaosresult.go │ │ └── expansion_generated.go ├── types │ └── types.go └── utils │ ├── retry │ └── retry.go │ ├── types.go │ ├── utils.go │ ├── utils_fuzz_test.go │ └── volumeUtils.go └── tests ├── bdd └── bdd_test.go └── manifest └── pod_delete_rbac.yaml /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | # Lines starting with '#' are comments. 2 | # Each line is a file pattern followed by one or more owners. 3 | 4 | # These owners will be the default owners for everything in the repo. 5 | * @ksatchit @ispeakc0de @imrajdas -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ## Is this a BUG REPORT or FEATURE REQUEST? 5 | 6 | Choose one: BUG REPORT or FEATURE REQUEST 7 | 8 | 20 | 21 | **What happened**: 22 | 23 | **What you expected to happen**: 24 | 25 | **How to reproduce it (as minimally and precisely as possible)**: 26 | 27 | **Anything else we need to know?**: -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | **What this PR does / why we need it**: 4 | 5 | **Which issue this PR fixes** *(optional, in `fixes #(, fixes #, ...)` format, will close that issue when PR gets merged)*: fixes # 6 | 7 | **Special notes for your reviewer**: 8 | 9 | **Checklist:** 10 | - [ ] Fixes # 11 | - [ ] Labelled this PR & related issue with `documentation` tag 12 | - [ ] PR messages has document related information 13 | - [ ] Labelled this PR & related issue with `breaking-changes` tag 14 | - [ ] PR messages has breaking changes related information 15 | - [ ] Labelled this PR & related issue with `requires-upgrade` tag 16 | - [ ] PR messages has upgrade related information 17 | - [ ] Commit has unit tests 18 | - [ ] Commit has integration tests -------------------------------------------------------------------------------- /.github/auto-merge.yml: -------------------------------------------------------------------------------- 1 | # Configuration for probot-auto-merge - https://github.com/bobvanderlinden/probot-auto-merge 2 | 3 | reportStatus: true 4 | updateBranch: false 5 | deleteBranchAfterMerge: true 6 | mergeMethod: squash 7 | 8 | minApprovals: 9 | COLLABORATOR: 0 10 | maxRequestedChanges: 11 | NONE: 0 12 | blockingLabels: 13 | - DO NOT MERGE 14 | - WIP 15 | - blocked 16 | 17 | # Will merge whenever the above conditions are met, but also 18 | # the owner has approved or merge label was added. 19 | rules: 20 | - minApprovals: 21 | OWNER: 1 22 | - requiredLabels: 23 | - merge 24 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: build-pipeline 2 | on: 3 | pull_request: 4 | branches: [master] 5 | types: [opened, synchronize, reopened] 6 | 7 | jobs: 8 | pre-checks: 9 | runs-on: ubuntu-latest 10 | steps: 11 | # Install golang 12 | - uses: actions/setup-go@v2 13 | with: 14 | go-version: 1.22 15 | 16 | # Checkout to the latest commit 17 | # On specific directory/path 18 | - name: Checkout 19 | uses: actions/checkout@v2 20 | 21 | - name: gofmt check 22 | run: make gofmt-check 23 | 24 | - name: golangci-lint 25 | uses: reviewdog/action-golangci-lint@v2 26 | with: 27 | golangci_lint_flags: "--timeout=10m" 28 | 29 | - name: unused-package check 30 | run: make unused-package-check 31 | 32 | trivy: 33 | needs: pre-checks 34 | runs-on: ubuntu-latest 35 | steps: 36 | - uses: actions/checkout@v2 37 | with: 38 | ref: ${{ github.event.pull_request.head.sha }} 39 | 40 | - name: Build an image from Dockerfile 41 | run: | 42 | docker build -f build/Dockerfile -t docker.io/litmuschaos/chaos-operator:${{ github.sha }} . --build-arg TARGETPLATFORM=linux/amd64 43 | 44 | - name: Run Trivy vulnerability scanner 45 | uses: aquasecurity/trivy-action@master 46 | with: 47 | image-ref: 'docker.io/litmuschaos/chaos-operator:${{ github.sha }}' 48 | format: 'table' 49 | exit-code: '1' 50 | ignore-unfixed: true 51 | vuln-type: 'os,library' 52 | severity: 'CRITICAL,HIGH' 53 | 54 | gitleaks-scan: 55 | runs-on: ubuntu-latest 56 | steps: 57 | - uses: actions/checkout@v3 58 | with: 59 | fetch-depth: 0 60 | - name: Run GitLeaks 61 | run: | 62 | wget https://github.com/gitleaks/gitleaks/releases/download/v8.18.2/gitleaks_8.18.2_linux_x64.tar.gz && \ 63 | tar -zxvf gitleaks_8.18.2_linux_x64.tar.gz && \ 64 | sudo mv gitleaks /usr/local/bin && gitleaks detect --source . -v 65 | 66 | image-build: 67 | runs-on: ubuntu-latest 68 | needs: pre-checks 69 | steps: 70 | # Checkout to the latest commit 71 | # On specific directory/path 72 | - name: Checkout 73 | uses: actions/checkout@v2 74 | 75 | - name: Build Docker Image 76 | env: 77 | DOCKER_REPO: litmuschaos 78 | DOCKER_IMAGE: chaos-operator 79 | DOCKER_TAG: ci 80 | run: | 81 | make build-amd64 82 | docker save -o ${{ github.workspace }}/image.tar litmuschaos/chaos-operator:ci 83 | chmod +x ${{ github.workspace }}/image.tar 84 | 85 | - name: Upload artifact 86 | uses: actions/upload-artifact@v4 87 | with: 88 | name: myimage 89 | path: | 90 | ${{ github.workspace }}/image.tar 91 | 92 | tests: 93 | runs-on: ubuntu-latest 94 | needs: image-build 95 | steps: 96 | # Install golang 97 | - uses: actions/setup-go@v2 98 | with: 99 | go-version: 1.22 100 | 101 | # Checkout to the latest commit 102 | # On specific directory/path 103 | - name: Checkout 104 | uses: actions/checkout@v2 105 | 106 | #Install and configure a kind cluster 107 | - name: Installing Prerequisites (K3S Cluster) 108 | env: 109 | KUBECONFIG: /etc/rancher/k3s/k3s.yaml 110 | run: | 111 | curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION=v1.20.14-rc1+k3s1 sh -s - --docker --write-kubeconfig-mode 664 112 | kubectl wait node --all --for condition=ready --timeout=90s 113 | mkdir -p $HOME/.kube 114 | cp /etc/rancher/k3s/k3s.yaml $HOME/.kube/config 115 | kubectl get nodes 116 | 117 | - name: Dependency checks 118 | run: | 119 | make deps 120 | 121 | - name: Download artifact 122 | uses: actions/download-artifact@v4 123 | with: 124 | name: myimage 125 | path: ${{ github.workspace }} 126 | 127 | - name: Load Docker image 128 | run: | 129 | docker load --input ${{ github.workspace }}/image.tar 130 | shell: bash 131 | 132 | - name: Running Go BDD Test 133 | run: | 134 | go mod tidy 135 | make test 136 | -------------------------------------------------------------------------------- /.github/workflows/e2e.yml: -------------------------------------------------------------------------------- 1 | name: ChaosOperator-E2E-pipeline 2 | on: 3 | issue_comment: 4 | types: [created] 5 | 6 | jobs: 7 | Tests: 8 | if: contains(github.event.comment.html_url, '/pull/') && startsWith(github.event.comment.body, '/run-e2e') 9 | runs-on: ubuntu-latest 10 | steps: 11 | 12 | - name: Notification for e2e Start 13 | uses: peter-evans/create-or-update-comment@v1 14 | with: 15 | comment-id: "${{ github.event.comment.id }}" 16 | body: | 17 | **** 18 | **Test Status:** The e2e test has been started please wait for the results ... 19 | 20 | - uses: actions/setup-go@v2 21 | with: 22 | go-version: 1.22 23 | 24 | - name: Setting up GOPATH 25 | run: | 26 | echo ::set-env name=GOPATH::${GITHUB_WORKSPACE}/go 27 | env: 28 | ACTIONS_ALLOW_UNSECURE_COMMANDS: true 29 | 30 | #Using the last commit id of pull request 31 | - uses: octokit/request-action@v2.x 32 | id: get_PR_commits 33 | with: 34 | route: GET /repos/:repo/pulls/:pull_number/commits 35 | repo: ${{ github.repository }} 36 | pull_number: ${{ github.event.issue.number }} 37 | env: 38 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 39 | 40 | - name: set commit to output 41 | id: getcommit 42 | run: | 43 | prsha=$(echo $response | jq '.[-1].sha' | tr -d '"') 44 | echo "::set-output name=sha::$prsha" 45 | env: 46 | response: ${{ steps.get_PR_commits.outputs.data }} 47 | 48 | - uses: actions/checkout@v2 49 | with: 50 | ref: ${{steps.getcommit.outputs.sha}} 51 | path: go/src/github.com/litmuschaos/chaos-operator 52 | 53 | - name: Build docker image 54 | run: | 55 | export PATH=$PATH:$(go env GOPATH)/bin 56 | cd ${GOPATH}/src/github.com/litmuschaos/chaos-operator 57 | make build 58 | sudo docker build --file build/Dockerfile --tag litmuschaos/chaos-operator:ci . --build-arg TARGETARCH=amd64 59 | 60 | #Install and configure a kind cluster 61 | - name: Installing Prerequisites (KinD Cluster) 62 | uses: engineerd/setup-kind@v0.5.0 63 | with: 64 | version: "v0.22.0" 65 | 66 | - name: Configuring and testing kind Installation 67 | run: | 68 | kubectl cluster-info 69 | kubectl get pods -n kube-system 70 | echo "current-context:" $(kubectl config current-context) 71 | echo "environment-kubeconfig:" ${KUBECONFIG} 72 | kubectl get nodes 73 | 74 | - name: Load image on the nodes of the cluster 75 | run: | 76 | kind load docker-image --name=kind litmuschaos/chaos-operator:ci 77 | 78 | - name: Getting litmus-e2e repository 79 | run: | 80 | cd ${GOPATH}/src/github.com/litmuschaos/ 81 | git clone https://github.com/litmuschaos/litmus-e2e.git -b master 82 | 83 | - name: Install LitmusChaos 84 | run: | 85 | export PATH=$PATH:$(go env GOPATH)/bin 86 | cd ${GOPATH}/src/github.com/litmuschaos/litmus-e2e 87 | go test tests/install-litmus_test.go -v -count=1 88 | env: 89 | OPERATOR_IMAGE: litmuschaos/chaos-operator:ci 90 | IMAGE_PULL_POLICY: IfNotPresent 91 | KUBECONFIG: /home/runner/.kube/config 92 | 93 | - name: Run Admin mode test 94 | if: startsWith(github.event.comment.body, '/run-e2e-admin-mode') || startsWith(github.event.comment.body, '/run-e2e-all') 95 | run: | 96 | export PATH=$PATH:$(go env GOPATH)/bin 97 | cd ${GOPATH}/src/github.com/litmuschaos/litmus-e2e 98 | go test components/operator/admin-mode_test.go -v -count=1 99 | env: 100 | KUBECONFIG: /home/runner/.kube/config 101 | 102 | - name: Run Reconcile Resiliency test 103 | if: startsWith(github.event.comment.body, '/run-e2e-reconcile-resiliency') || startsWith(github.event.comment.body, '/run-e2e-all') 104 | run: | 105 | export PATH=$PATH:$(go env GOPATH)/bin 106 | cd ${GOPATH}/src/github.com/litmuschaos/litmus-e2e 107 | go test components/operator/reconcile-resiliency_test.go -v -count=1 108 | env: 109 | KUBECONFIG: /home/runner/.kube/config 110 | 111 | - name: Check the test run 112 | if: | 113 | startsWith(github.event.comment.body, '/run-e2e-admin-mode') || startsWith(github.event.comment.body, '/run-e2e-reconcile-resiliency') || 114 | startsWith(github.event.comment.body, '/run-e2e-all') 115 | run: | 116 | echo ::set-env name=TEST_RUN::true 117 | env: 118 | ACTIONS_ALLOW_UNSECURE_COMMANDS: true 119 | 120 | - name: Check for all the jobs are succeeded 121 | if: ${{ success() && env.TEST_RUN == 'true' }} 122 | uses: peter-evans/create-or-update-comment@v1 123 | with: 124 | comment-id: "${{ github.event.comment.id }}" 125 | body: | 126 | **Test Result:** All tests are passed 127 | **Logs:** [${{ env.RUN_ID }}](https://github.com/litmuschaos/chaos-operator/actions/runs/${{ env.RUN_ID }}) 128 | 129 | reactions: hooray 130 | env: 131 | RUN_ID: ${{ github.run_id }} 132 | 133 | - name: Check for any job failed 134 | if: ${{ failure() }} 135 | uses: peter-evans/create-or-update-comment@v1 136 | with: 137 | comment-id: "${{ github.event.comment.id }}" 138 | body: | 139 | **Test Failed:** Some tests are failed please check 140 | **Logs:** [${{ env.RUN_ID }}](https://github.com/litmuschaos/chaos-operator/actions/runs/${{ env.RUN_ID }}) 141 | reactions: confused 142 | env: 143 | RUN_ID: ${{ github.run_id }} 144 | 145 | - name: Deleting KinD cluster 146 | if: ${{ always() }} 147 | run: kind delete cluster 148 | 149 | - name: Check if any test ran or not 150 | if: env.TEST_RUN != 'true' 151 | uses: peter-evans/create-or-update-comment@v1 152 | with: 153 | comment-id: "${{ github.event.comment.id }}" 154 | body: | 155 | **Test Result:** No test found try /run-e2e-all 156 | **Logs:** [${{ env.RUN_ID }}](https://github.com/litmuschaos/chaos-operator/actions/runs/${{ env.RUN_ID }}) 157 | reactions: eyes 158 | env: 159 | RUN_ID: ${{ github.run_id }} 160 | -------------------------------------------------------------------------------- /.github/workflows/push.yml: -------------------------------------------------------------------------------- 1 | name: push-pipeline 2 | on: 3 | push: 4 | branches: 5 | - master 6 | tags-ignore: 7 | - '**' 8 | 9 | jobs: 10 | pre-checks: 11 | runs-on: ubuntu-latest 12 | steps: 13 | # Install golang 14 | - uses: actions/setup-go@v2 15 | with: 16 | go-version: 1.22 17 | 18 | # Checkout to the latest commit 19 | # On specific directory/path 20 | - name: Checkout 21 | uses: actions/checkout@v2 22 | 23 | - name: gofmt check 24 | run: make gofmt-check 25 | 26 | - name: golangci-lint 27 | uses: reviewdog/action-golangci-lint@v2 28 | 29 | - name: unused-package check 30 | run: make unused-package-check 31 | 32 | image-build: 33 | runs-on: ubuntu-latest 34 | steps: 35 | # Checkout to the latest commit 36 | # On specific directory/path 37 | - name: Checkout 38 | uses: actions/checkout@v2 39 | 40 | - name: Set up QEMU 41 | uses: docker/setup-qemu-action@v1 42 | with: 43 | platforms: all 44 | 45 | - name: Set up Docker Buildx 46 | id: buildx 47 | uses: docker/setup-buildx-action@v1 48 | with: 49 | version: latest 50 | 51 | - name: login to GitHub Container Registry 52 | run: echo ${{ secrets.DPASS }} | docker login -u ${{ secrets.DNAME }} --password-stdin 53 | 54 | - name: Build & Push Docker Image 55 | env: 56 | DOCKER_REPO: ${{ secrets.DOCKER_REPO }} 57 | DOCKER_IMAGE: ${{ secrets.DOCKER_IMAGE }} 58 | DOCKER_TAG: ci 59 | DNAME: ${{ secrets.DNAME }} 60 | DPASS: ${{ secrets.DPASS }} 61 | run: make push-chaos-operator -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: release-pipeline 2 | on: 3 | create: 4 | tags: 5 | - '**' 6 | 7 | jobs: 8 | pre-checks: 9 | runs-on: ubuntu-latest 10 | steps: 11 | # Install golang 12 | - uses: actions/setup-go@v2 13 | with: 14 | go-version: 1.22 15 | 16 | # Checkout to the latest commit 17 | # On specific directory/path 18 | - name: Checkout 19 | uses: actions/checkout@v2 20 | 21 | image-build: 22 | runs-on: ubuntu-latest 23 | steps: 24 | # Checkout to the latest commit 25 | # On specific directory/path 26 | - name: Checkout 27 | uses: actions/checkout@v2 28 | 29 | - name: Set up QEMU 30 | uses: docker/setup-qemu-action@v1 31 | with: 32 | platforms: all 33 | 34 | - name: Set up Docker Buildx 35 | id: buildx 36 | uses: docker/setup-buildx-action@v1 37 | with: 38 | version: latest 39 | 40 | - name: login to GitHub Container Registry 41 | run: echo ${{ secrets.DPASS }} | docker login -u ${{ secrets.DNAME }} --password-stdin 42 | 43 | - name: Set Tag 44 | run: | 45 | TAG="${GITHUB_REF#refs/*/}" 46 | echo "TAG=${TAG}" >> $GITHUB_ENV 47 | echo "RELEASE_TAG=${TAG}" >> $GITHUB_ENV 48 | 49 | - name: Build & Push Docker Image with version tag 50 | env: 51 | DOCKER_REPO: ${{ secrets.DOCKER_REPO }} 52 | DOCKER_IMAGE: ${{ secrets.DOCKER_IMAGE }} 53 | DOCKER_TAG: ${RELEASE_TAG} 54 | DNAME: ${{ secrets.DNAME }} 55 | DPASS: ${{ secrets.DPASS }} 56 | run: make push-chaos-operator 57 | 58 | - name: Build & Push Docker Image with latest 59 | env: 60 | DOCKER_REPO: ${{ secrets.DOCKER_REPO }} 61 | DOCKER_IMAGE: ${{ secrets.DOCKER_IMAGE }} 62 | DOCKER_TAG: latest 63 | DNAME: ${{ secrets.DNAME }} 64 | DPASS: ${{ secrets.DPASS }} 65 | run: make push-chaos-operator 66 | -------------------------------------------------------------------------------- /.github/workflows/security-scan.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: Security Scan 3 | on: 4 | workflow_dispatch: 5 | 6 | jobs: 7 | trivy: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/checkout@master 11 | - name: Build an image from Dockerfile 12 | run: | 13 | docker build -f build/Dockerfile -t docker.io/litmuschaos/chaos-operator:${{ github.sha }} . --build-arg TARGETARCH=amd64 14 | 15 | - name: Run Trivy vulnerability scanner 16 | uses: aquasecurity/trivy-action@master 17 | with: 18 | image-ref: 'docker.io/litmuschaos/chaos-operator:${{ github.sha }}' 19 | format: 'table' 20 | exit-code: '1' 21 | ignore-unfixed: true 22 | vuln-type: 'os,library' 23 | severity: 'CRITICAL,HIGH' 24 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build/_output 2 | *.swp 3 | *.orig 4 | .idea/ 5 | coverage.txt 6 | bin -------------------------------------------------------------------------------- /.gitlab-ci.yml: -------------------------------------------------------------------------------- 1 | --- 2 | stages: 3 | - setup 4 | - build 5 | - test 6 | - push 7 | - baseline 8 | - cleanup 9 | 10 | ClusterSetup: 11 | 12 | stage: setup 13 | tags: 14 | - setup 15 | script: 16 | - chmod 755 ./build/gitlab/stages/1-cluster-setup/gcp 17 | - ./build/gitlab/stages/1-cluster-setup/gcp 18 | 19 | artifacts: 20 | when: always 21 | paths: 22 | - .kube/ 23 | 24 | Build: 25 | 26 | stage: build 27 | tags: 28 | - build 29 | script: 30 | - export COMMIT=${CI_COMMIT_SHORT_SHA} 31 | - export GOPATH=$HOME/go 32 | - export GOROOT=/usr/local/go 33 | - export PATH=$HOME/go/bin:$PATH 34 | - mkdir -p $HOME/go/src/github.com/${REPONAME}/${IMAGENAME} 35 | - rsync -az --delete ${CI_PROJECT_DIR}/ ${GOPATH}/src/github.com/${REPONAME}/${IMAGENAME}/ #CI_PROJECT_DIR is full path where project is cloned 36 | - go env 37 | - cd ${GOPATH}/src/github.com/${REPONAME}/${IMAGENAME} 38 | - make deps 39 | - make gotasks 40 | 41 | Test: 42 | 43 | stage: test 44 | tags: 45 | - test 46 | script: 47 | - cd ${HOME}/go/src/github.com/${REPONAME}/${IMAGENAME} 48 | - make test 49 | 50 | Push: 51 | 52 | stage: push 53 | tags: 54 | - push 55 | script: 56 | - cd ${HOME}/go/src/github.com/${REPONAME}/${IMAGENAME} 57 | - sudo make dockerops 58 | 59 | baseline-image: 60 | 61 | when: always 62 | stage: baseline 63 | tags: 64 | - test 65 | only: 66 | refs: 67 | - /^(v[0-9][.][0-9][.]x|master)?$/ 68 | script: 69 | - pwd 70 | - export BRANCH=${CI_COMMIT_REF_NAME} 71 | - echo $BRANCH 72 | - export COMMIT=${CI_COMMIT_SHORT_SHA} 73 | - echo $COMMIT 74 | - git clone https://github.com/litmuschaos/litmus-e2e.git 75 | - cd litmus-e2e 76 | - git checkout ${BASELINE_BRANCH} 77 | - cd baseline 78 | - ansible-playbook commit-writer.yml --extra-vars "branch=$BRANCH repo=$CI_PROJECT_NAME commit=$COMMIT" 79 | - git status 80 | - git add baseline 81 | - git status 82 | - git commit -m "updated $CI_PROJECT_NAME commit:$COMMIT" 83 | - git push http://${YOUR_USERNAME}:${PERSONAL_ACCESS_TOKEN}@github.com/litmuschaos/litmus-e2e.git --all 84 | 85 | ClusterCleanup: 86 | 87 | when: always 88 | stage: cleanup 89 | tags: 90 | - cleanup 91 | script: 92 | - chmod 755 ./build/gitlab/stages/2-cluster-cleanup/cluster-cleanup 93 | - ./build/gitlab/stages/2-cluster-cleanup/cluster-cleanup 94 | 95 | artifacts: 96 | when: always 97 | paths: 98 | - .kube/ 99 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to Litmus Chaos-Operator 2 | 3 | Litmus is an Apache 2.0 Licensed project and uses the standard GitHub pull requests process to review and accept contributions. 4 | 5 | There are several areas of Litmus that could use your help. For starters, you could help in improving the sections in this document by either creating a new issue describing the improvement or submitting a pull request to this repository. 6 | 7 | - If you are a first-time contributor, please see [Steps to Contribute](#steps-to-contribute). 8 | - If you would like to suggest new tests to be added to litmus, please go ahead and [create a new issue](https://github.com/litmuschaos/litmus/issues/new) describing your test. All you need to do is specify the workload type and the operations that you would like to perform on the workload. 9 | - If you would like to work on something more involved, please connect with the Litmus Contributors. 10 | - If you would like to make code contributions, all your commits should be signed with Developer Certificate of Origin. See [Sign your work](#sign-your-work). 11 | 12 | ## Steps to Contribute 13 | 14 | - Find an issue to work on or create a new issue. The issues are maintained at [litmuschaos/litmus](https://github.com/litmuschaos/litmus/issues). You can pick up from a list of [good-first-issues](https://github.com/litmuschaos/litmus/labels/good%20first%20issue). 15 | - Claim your issue by commenting your intent to work on it to avoid duplication of efforts. 16 | - Fork the repository on GitHub. 17 | - Create a branch from where you want to base your work (usually master). 18 | - Make your changes. 19 | - Relevant coding style guidelines are the [Go Code Review Comments](https://code.google.com/p/go-wiki/wiki/CodeReviewComments) and the _Formatting and style_ section of Peter Bourgon's [Go: Best Practices for Production Environments](http://peter.bourgon.org/go-in-production/#formatting-and-style). 20 | - If there is any schema changes then you need to generate the auto-generated file using below steps. 21 | - Since we have used operator-sdk framework to bootstrap this repo/controller, we are using a utility provided by them to generate deepcopy functions. First, download the operator-sdk binary into your workspace. Ref: https://v0-18-x.sdk.operatorframework.io/docs/install-operator-sdk/#install-from-github-release 22 | - Once it is placed in your $GOBIN, you can execute the following command while at the root of the chaos-operator repo. 23 | ```bash 24 | operator-sdk generate k8s 25 | ``` 26 | - An additional step we have been doing of late is using the code-gen utility to check for any generated code needs with schema changes. 27 | ```bash 28 | ./hack/update-codegen.sh 29 | ``` 30 | 31 | - Commit your changes by making sure the commit messages convey the need and notes about the commit. 32 | - Push your changes to the branch in your fork of the repository. 33 | - Submit a pull request to the original repository. See [Pull Request checklist](#pull-request-checklist) 34 | 35 | ## Pull Request Checklist 36 | 37 | - Rebase to the current master branch before submitting your pull request. 38 | - Commits should be as small as possible. Each commit should follow the checklist below: 39 | - For code changes, add tests relevant to the fixed bug or new feature 40 | - Pass the compile and tests - includes spell checks, formatting, etc 41 | - Commit header (first line) should convey what changed 42 | - Commit body should include details such as why the changes are required and how the proposed changes 43 | - DCO Signed 44 | 45 | - If your PR is not getting reviewed or you need a specific person to review it, please reach out to the Litmus contributors at the [Litmus slack channel](https://app.slack.com/client/T09NY5SBT/CNXNB0ZTN) 46 | 47 | ## Sign your work 48 | 49 | We use the Developer Certificate of Origin (DCO) as an additional safeguard for the LitmusChaos project. This is a well established and widely used mechanism to assure that contributors have confirmed their right to license their contribution under the project's license. Please add a line to every git commit message: 50 | 51 | ```sh 52 | Signed-off-by: Random J Developer 53 | ``` 54 | 55 | Use your real name (sorry, no pseudonyms or anonymous contributions). The email id should match the email id provided in your GitHub profile. 56 | If you set your `user.name` and `user.email` in git config, you can sign your commit automatically with `git commit -s`. 57 | 58 | You can also use git [aliases](https://git-scm.com/book/tr/v2/Git-Basics-Git-Aliases) like `git config --global alias.ci 'commit -s'`. Now you can commit with `git ci` and the commit will be signed. 59 | 60 | ## Setting up your Development Environment 61 | 62 | This project is implemented using Go and uses the standard golang tools for development and build. In addition, this project heavily relies on Docker and Kubernetes. It is expected that the contributors. 63 | 64 | - are familiar with working with Go 65 | - are familiar with Docker containers 66 | - are familiar with Kubernetes and have access to a Kubernetes cluster or Minikube to test the changes. 67 | 68 | For setting up a Development environment on your local host, see the detailed instructions [here](./docs/developer.md). 69 | 70 | ## Community 71 | 72 | The litmus community will have a monthly community sync-up on 3rd Wednesday 22.00-23.00IST / 18.30-19.30CEST 73 | - The community meeting details are available [here](https://hackmd.io/a4Zu_sH4TZGeih-xCimi3Q). Please feel free to join the community meeting. 74 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2019 LitmusChaos Authors 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for building Chaos Operator 2 | # Reference Guide - https://www.gnu.org/software/make/manual/make.html 3 | 4 | IS_DOCKER_INSTALLED = $(shell which docker >> /dev/null 2>&1; echo $$?) 5 | 6 | # docker info 7 | DOCKER_REGISTRY ?= docker.io 8 | DOCKER_REPO ?= litmuschaos 9 | DOCKER_IMAGE ?= chaos-operator 10 | DOCKER_TAG ?= ci 11 | 12 | .PHONY: help 13 | help: 14 | @echo "" 15 | @echo "Usage:-" 16 | @echo "\tmake deps -- sets up dependencies for image build" 17 | @echo "\tmake build-chaos-operator -- builds multi-arch image" 18 | @echo "\tmake push-chaos-operator -- pushes the multi-arch image" 19 | @echo "\tmake build-amd64 -- builds the amd64 image" 20 | @echo "" 21 | 22 | .PHONY: all 23 | all: deps unused-package-check build-chaos-operator test 24 | 25 | .PHONY: deps 26 | deps: _build_check_docker godeps 27 | 28 | _build_check_docker: 29 | @if [ $(IS_DOCKER_INSTALLED) -eq 1 ]; \ 30 | then echo "" \ 31 | && echo "ERROR:\tdocker is not installed. Please install it before build." \ 32 | && echo "" \ 33 | && exit 1; \ 34 | fi; 35 | 36 | .PHONY: godeps 37 | godeps: 38 | @echo "" 39 | @echo "INFO:\tverifying dependencies for chaos operator build ..." 40 | @go get -u -v golang.org/x/lint/golint 41 | @go get -u -v golang.org/x/tools/cmd/goimports 42 | 43 | .PHONY: test 44 | test: 45 | @echo "------------------" 46 | @echo "--> Run Go Test" 47 | @echo "------------------" 48 | @go test ./... -coverprofile=coverage.txt -covermode=atomic -v 49 | 50 | .PHONY: unused-package-check 51 | unused-package-check: 52 | @echo "------------------" 53 | @echo "--> Check unused packages for the chaos-operator" 54 | @echo "------------------" 55 | @tidy=$$(go mod tidy); \ 56 | if [ -n "$${tidy}" ]; then \ 57 | echo "go mod tidy checking failed!"; echo "$${tidy}"; echo; \ 58 | fi 59 | 60 | gofmt-check: 61 | @echo "------------------" 62 | @echo "--> Check unused packages for the chaos-operator" 63 | @echo "------------------" 64 | @gfmt=$$(gofmt -s -l . | wc -l); \ 65 | if [ "$${gfmt}" -ne 0 ]; then \ 66 | echo "The following files were found to be not go formatted:"; \ 67 | gofmt -s -l .; \ 68 | exit 1; \ 69 | fi 70 | 71 | 72 | .PHONY: build-chaos-operator 73 | build-chaos-operator: 74 | @echo "-------------------------" 75 | @echo "--> Build go-runner image" 76 | @echo "-------------------------" 77 | @docker buildx build --file build/Dockerfile --progress plain --no-cache --platform linux/arm64,linux/amd64 --tag $(DOCKER_REGISTRY)/$(DOCKER_REPO)/$(DOCKER_IMAGE):$(DOCKER_TAG) . 78 | 79 | .PHONY: push-chaos-operator 80 | push-chaos-operator: 81 | @echo "------------------------------" 82 | @echo "--> Pushing image" 83 | @echo "------------------------------" 84 | @docker buildx build --file build/Dockerfile --progress plain --no-cache --push --platform linux/arm64,linux/amd64 --tag $(DOCKER_REGISTRY)/$(DOCKER_REPO)/$(DOCKER_IMAGE):$(DOCKER_TAG) . 85 | 86 | .PHONY: build-amd64 87 | build-amd64: 88 | @echo "-------------------------" 89 | @echo "--> Build go-runner image" 90 | @echo "-------------------------" 91 | @docker build -f build/Dockerfile --no-cache -t $(DOCKER_REGISTRY)/$(DOCKER_REPO)/$(DOCKER_IMAGE):$(DOCKER_TAG) . --build-arg TARGETPLATFORM="linux/amd64" 92 | 93 | ## Location to install dependencies to 94 | LOCALBIN ?= $(shell pwd)/bin 95 | $(LOCALBIN): 96 | mkdir -p $(LOCALBIN) 97 | CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen 98 | CONTROLLER_TOOLS_VERSION ?= v0.9.0 99 | 100 | .PHONY: controller-gen 101 | controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary. 102 | $(CONTROLLER_GEN): $(LOCALBIN) 103 | GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION) 104 | 105 | 106 | .PHONY: manifests 107 | manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects. 108 | $(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases 109 | 110 | .PHONY: generate 111 | generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations. 112 | $(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..." 113 | -------------------------------------------------------------------------------- /NOTICE.md: -------------------------------------------------------------------------------- 1 | The source code developed for the LitmusChaos Project is licensed under Apache 2.0. 2 | 3 | However, the LitmusChaos project contains modified subcomponents from other Open Source Projects with separate copyright notices and license terms. 4 | 5 | Your use of the source code for these subcomponents is subject to the terms and conditions as defined by those source projects. 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Litmus chaos-operator for injecting chaos experiments on Kubernetes 2 | 3 | [![Slack Channel](https://img.shields.io/badge/Slack-Join-purple)](https://slack.litmuschaos.io) 4 | ![GitHub Workflow](https://github.com/litmuschaos/chaos-operator/actions/workflows/push.yml/badge.svg?branch=master) 5 | [![Docker Pulls](https://img.shields.io/docker/pulls/litmuschaos/chaos-operator.svg)](https://hub.docker.com/r/litmuschaos/chaos-operator) 6 | [![GitHub issues](https://img.shields.io/github/issues/litmuschaos/chaos-operator)](https://github.com/litmuschaos/chaos-operator/issues) 7 | [![Twitter Follow](https://img.shields.io/twitter/follow/litmuschaos?style=social)](https://twitter.com/LitmusChaos) 8 | [![Codacy Badge](https://api.codacy.com/project/badge/Grade/2597079b1b5240d3866a6deb4112a2f2)](https://www.codacy.com/manual/litmuschaos/chaos-operator?utm_source=github.com&utm_medium=referral&utm_content=litmuschaos/chaos-operator&utm_campaign=Badge_Grade) 9 | [![Go Report Card](https://goreportcard.com/badge/github.com/litmuschaos/chaos-operator)](https://goreportcard.com/report/github.com/litmuschaos/chaos-operator) 10 | [![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/5290/badge)](https://bestpractices.coreinfrastructure.org/projects/5290) 11 | [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Flitmuschaos%2Fchaos-operator.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Flitmuschaos%2Fchaos-operator?ref=badge_shield) 12 | [![codecov](https://codecov.io/gh/litmuschaos/chaos-operator/branch/master/graph/badge.svg)](https://codecov.io/gh/litmuschaos/chaos-operator) 13 | [![YouTube Channel](https://img.shields.io/badge/YouTube-Subscribe-red)](https://www.youtube.com/channel/UCa57PMqmz_j0wnteRa9nCaw) 14 |

15 | 16 | Litmus chaos operator is used by Kubernetes application developers and SREs to inject chaos into the applications 17 | and Kubernetes infrastructure in a managed fashion. Its objective is to make the process of validation and 18 | hardening of application workloads on Kubernetes easy by automating the execution of chaos experiments. A sample chaos 19 | injection workflow could be as simple as: 20 | 21 | - Install the Litmus infrastructure components (RBAC, CRDs), the Operator & Experiment custom resource bundles via the operator manifest 22 | - Annotate the application under test (AUT), enabling it for chaos 23 | - Create a ChaosEngine custom resource tied to the AUT, which describes the experiment to be executed 24 | 25 | Benefits provided by the Chaos Operator include: 26 | 27 | - Standardised chaos experiment spec 28 | - Categorized chaos bundles for stateless/stateful/vendor-specific 29 | - Test-Run resiliency 30 | - Ability to chaos run as a background service based on annotations 31 | 32 | ## What is a chaos operator and how is it built? 33 | 34 | The Chaos Operator is a Kubernetes Operator, which are nothing but custom-controllers with direct access to Kubernetes API 35 | that can manage the lifecycle of certain resources or applications, while always trying to ensure the resource is in the "desired 36 | state". The logic that ensures this is commonly called "reconcile" function. 37 | 38 | The Chaos Operator is built using the popular [Operator-SDK](https://github.com/operator-framework/operator-sdk/) framework, 39 | which provides bootstrap support for new operator projects, allowing teams to focus on business/operational logic. 40 | 41 | The Litmus Chaos Operator helps reconcile the state of the ChaosEngine, a custom resource that holds the chaos intent 42 | specified by a developer/devops engineer against a particular stateless/stateful Kubernetes deployment. The operator performs 43 | specific actions upon CRUD of the ChaosEngine, its primary resource. The operator also defines a secondary resource (the engine 44 | runner pod), which is created & managed by it in order to implement the reconcile functions. 45 | 46 | ## What is a chaos engine? 47 | 48 | The ChaosEngine is the core schema that defines the chaos workflow for a given application. Currently, it defines the following: 49 | 50 | - Application info (namespace, labels, kind) of primary (AUT) and auxiliary (dependent) applications 51 | - ServiceAccount used for execution of the experiment 52 | - Flag to turn on/off chaos annotation checks on applications 53 | - Chaos Experiment to be executed on the application 54 | - Attributes of the experiments (overrides defaults specified in the experiment CRs) 55 | - Flag to retain/cleanup chaos resources after experiment execution 56 | 57 | The ChaosEngine is the referenced as the owner of the secondary (reconcile) resource with Kubernetes deletePropagation 58 | ensuring these also are removed upon deletion of the ChaosEngine CR. 59 | 60 | Here is a sample ChaosEngineSpec for reference: 61 | 62 | ## What is a litmus chaos chart and how can I use it? 63 | 64 | Litmus Chaos Charts are used to install "Chaos Experiment Bundles" & are categorized based on the nature 65 | of the experiments (general Kubernetes chaos, vendor/provider specific chaos - such as, OpenEBS or 66 | application-specific chaos, say NuoDB). They consist of custom resources that hold low-level chaos(test) 67 | parameters which are queried by the operator in order to execute the experiments. The spec.definition._fields_ 68 | and their corresponding _values_ are used to construct the eventual execution artifact that runs the chaos 69 | experiment (typically, the litmusbook, which is a K8s job resource). It also defines the permissions necessary 70 | to execute the experiment. 71 | 72 | Here is a sample ChaosEngineSpec for reference: 73 | 74 | ```yaml 75 | apiVersion: litmuschaos.io/v1alpha1 76 | description: 77 | message: | 78 | Deletes a pod belonging to a deployment/statefulset/daemonset 79 | kind: ChaosExperiment 80 | metadata: 81 | name: pod-delete 82 | labels: 83 | name: pod-delete 84 | app.kubernetes.io/part-of: litmus 85 | app.kubernetes.io/component: chaosexperiment 86 | app.kubernetes.io/version: latest 87 | spec: 88 | definition: 89 | scope: Namespaced 90 | permissions: 91 | - apiGroups: 92 | - "" 93 | - "apps" 94 | - "batch" 95 | - "litmuschaos.io" 96 | resources: 97 | - "deployments" 98 | - "jobs" 99 | - "pods" 100 | - "configmaps" 101 | - "chaosengines" 102 | - "chaosexperiments" 103 | - "chaosresults" 104 | verbs: 105 | - "create" 106 | - "list" 107 | - "get" 108 | - "patch" 109 | - "update" 110 | - "delete" 111 | image: "litmuschaos/go-runner:latest" 112 | imagePullPolicy: Always 113 | args: 114 | - -c 115 | - ./experiments -name pod-delete 116 | command: 117 | - /bin/bash 118 | env: 119 | 120 | - name: TOTAL_CHAOS_DURATION 121 | value: '15' 122 | 123 | # Period to wait before/after injection of chaos in sec 124 | - name: RAMP_TIME 125 | value: '' 126 | 127 | - name: FORCE 128 | value: 'true' 129 | 130 | - name: CHAOS_INTERVAL 131 | value: '5' 132 | 133 | ## percentage of total pods to target 134 | - name: PODS_AFFECTED_PERC 135 | value: '' 136 | 137 | - name: LIB 138 | value: 'litmus' 139 | 140 | - name: TARGET_PODS 141 | value: '' 142 | 143 | ## it defines the sequence of chaos execution for multiple target pods 144 | ## supported values: serial, parallel 145 | - name: SEQUENCE 146 | value: 'parallel' 147 | labels: 148 | name: pod-delete 149 | app.kubernetes.io/part-of: litmus 150 | app.kubernetes.io/component: experiment-job 151 | app.kubernetes.io/version: latest 152 | ``` 153 | 154 | ## How to get started? 155 | 156 | Refer the LitmusChaos documentation [litmus docs](https://docs.litmuschaos.io) 157 | 158 | ## How do I contribute? 159 | 160 | You can contribute by raising issues, improving the documentation, contributing to the core framework and tooling, etc. 161 | 162 | Head over to the [Contribution guide](CONTRIBUTING.md) 163 | 164 | ## License 165 | [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Flitmuschaos%2Fchaos-operator.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Flitmuschaos%2Fchaos-operator?ref=badge_large) 166 | -------------------------------------------------------------------------------- /api/litmuschaos/v1alpha1/chaosexperiment_types.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 LitmusChaos Authors 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package v1alpha1 18 | 19 | import ( 20 | corev1 "k8s.io/api/core/v1" 21 | rbacV1 "k8s.io/api/rbac/v1" 22 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 23 | ) 24 | 25 | // ChaosExperimentSpec defines the desired state of ChaosExperiment 26 | // An experiment is the definition of a chaos test and is listed as an item 27 | // in the chaos engine to be run against a given app. 28 | type ChaosExperimentSpec struct { 29 | // Definition carries low-level chaos options 30 | Definition ExperimentDef `json:"definition"` 31 | } 32 | 33 | // ChaosExperimentStatus defines the observed state of ChaosExperiment 34 | type ChaosExperimentStatus struct { 35 | // INSERT ADDITIONAL STATUS FIELD - define observed state of cluster 36 | // Important: Run "make" to regenerate code after modifying this file 37 | } 38 | 39 | // ConfigMap is an simpler implementation of corev1.ConfigMaps, needed for experiments 40 | type ConfigMap struct { 41 | Data map[string]string `json:"data,omitempty"` 42 | Name string `json:"name"` 43 | MountPath string `json:"mountPath"` 44 | } 45 | 46 | // Secret is an simpler implementation of corev1.Secret 47 | type Secret struct { 48 | Name string `json:"name"` 49 | MountPath string `json:"mountPath"` 50 | } 51 | 52 | // HostFile is an simpler implementation of corev1.HostPath, needed for experiments 53 | type HostFile struct { 54 | Name string `json:"name"` 55 | MountPath string `json:"mountPath"` 56 | NodePath string `json:"nodePath"` 57 | Type corev1.HostPathType `json:"type,omitempty"` 58 | } 59 | 60 | // ExperimentDef defines information about nature of chaos & components subjected to it 61 | type ExperimentDef struct { 62 | // Default labels of the runner pod 63 | // +optional 64 | Labels map[string]string `json:"labels"` 65 | // Image of the chaos experiment 66 | Image string `json:"image"` 67 | // ImagePullPolicy of the chaos experiment container 68 | ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"` 69 | //Scope specifies the service account scope (& thereby blast radius) of the experiment 70 | Scope string `json:"scope"` 71 | // List of Permission needed for a service account to execute experiment 72 | Permissions []rbacV1.PolicyRule `json:"permissions"` 73 | // List of ENV vars passed to executor pod 74 | ENVList []corev1.EnvVar `json:"env"` 75 | // Defines command to invoke experiment 76 | Command []string `json:"command"` 77 | // Defines arguments to runner's entrypoint command 78 | Args []string `json:"args"` 79 | // ConfigMaps contains a list of ConfigMaps 80 | ConfigMaps []ConfigMap `json:"configMaps,omitempty"` 81 | // Secrets contains a list of Secrets 82 | Secrets []Secret `json:"secrets,omitempty"` 83 | // HostFileVolume defines the host directory/file to be mounted 84 | HostFileVolumes []HostFile `json:"hostFileVolumes,omitempty"` 85 | // Annotations that needs to be provided in the pod for pod that is getting created 86 | ExperimentAnnotations map[string]string `json:"experimentAnnotations,omitempty"` 87 | // SecurityContext holds security configuration that will be applied to a container 88 | SecurityContext SecurityContext `json:"securityContext,omitempty"` 89 | // HostPID is need to be provided in the chaospod 90 | HostPID bool `json:"hostPID,omitempty"` 91 | } 92 | 93 | // SecurityContext defines the security contexts of the pod and container. 94 | type SecurityContext struct { 95 | // PodSecurityContext holds security configuration that will be applied to a pod 96 | PodSecurityContext corev1.PodSecurityContext `json:"podSecurityContext,omitempty"` 97 | // ContainerSecurityContext holds security configuration that will be applied to a container 98 | ContainerSecurityContext corev1.SecurityContext `json:"containerSecurityContext,omitempty"` 99 | } 100 | 101 | //+kubebuilder:object:root=true 102 | //+kubebuilder:subresource:status 103 | // +genclient 104 | // +resource:path=chaosexperiment 105 | 106 | // ChaosExperiment is the Schema for the chaosexperiments API 107 | type ChaosExperiment struct { 108 | metav1.TypeMeta `json:",inline"` 109 | metav1.ObjectMeta `json:"metadata,omitempty"` 110 | 111 | Spec ChaosExperimentSpec `json:"spec,omitempty"` 112 | Status ChaosExperimentStatus `json:"status,omitempty"` 113 | } 114 | 115 | //+kubebuilder:object:root=true 116 | 117 | // ChaosExperimentList contains a list of ChaosExperiment 118 | type ChaosExperimentList struct { 119 | metav1.TypeMeta `json:",inline"` 120 | metav1.ListMeta `json:"metadata,omitempty"` 121 | Items []ChaosExperiment `json:"items"` 122 | } 123 | 124 | func init() { 125 | SchemeBuilder.Register(&ChaosExperiment{}, &ChaosExperimentList{}) 126 | } 127 | -------------------------------------------------------------------------------- /api/litmuschaos/v1alpha1/chaosresult_types.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 LitmusChaos Authors 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package v1alpha1 18 | 19 | import ( 20 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 21 | ) 22 | 23 | // ChaosResultSpec defines the desired state of ChaosResult 24 | // The chaosresult holds the status of a chaos experiment that is listed as an item 25 | // in the chaos engine to be run against a given app. 26 | type ChaosResultSpec struct { 27 | // EngineName defines the name of chaosEngine 28 | EngineName string `json:"engine,omitempty"` 29 | // ExperimentName defines the name of chaosexperiment 30 | ExperimentName string `json:"experiment"` 31 | // InstanceID defines the instance id 32 | InstanceID string `json:"instance,omitempty"` 33 | } 34 | 35 | // ResultPhase is typecasted to string for supporting the values below. 36 | type ResultPhase string 37 | 38 | const ( 39 | // ResultPhaseRunning is phase of chaosresult which is in running state 40 | ResultPhaseRunning ResultPhase = "Running" 41 | // ResultPhaseCompleted is phase of chaosresult which is in completed state 42 | ResultPhaseCompleted ResultPhase = "Completed" 43 | // Retained For Backward Compatibility: ResultPhaseCompletedWithError is phase of chaosresult when probe is failed in 3.0beta5 44 | ResultPhaseCompletedWithError ResultPhase = "Completed_With_Error" 45 | // ResultPhaseCompletedWithProbeFailure is phase of chaosresult when probe is failed from 3.0beta6 46 | ResultPhaseCompletedWithProbeFailure ResultPhase = "Completed_With_Probe_Failure" 47 | // ResultPhaseStopped is phase of chaosresult which is in stopped state 48 | ResultPhaseStopped ResultPhase = "Stopped" 49 | // ResultPhaseError is phase of chaosresult, which indicates that the experiment is terminated due to an error 50 | ResultPhaseError ResultPhase = "Error" 51 | ) 52 | 53 | // ResultVerdict is typecasted to string for supporting the values below. 54 | type ResultVerdict string 55 | 56 | const ( 57 | // ResultVerdictPassed is verdict of chaosresult when experiment passed 58 | ResultVerdictPassed ResultVerdict = "Pass" 59 | // ResultVerdictFailed is verdict of chaosresult when experiment failed 60 | ResultVerdictFailed ResultVerdict = "Fail" 61 | // ResultVerdictStopped is verdict of chaosresult when experiment aborted 62 | ResultVerdictStopped ResultVerdict = "Stopped" 63 | // ResultVerdictAwaited is verdict of chaosresult when experiment is yet to evaluated(experiment is in running state) 64 | ResultVerdictAwaited ResultVerdict = "Awaited" 65 | // ResultVerdictError is verdict of chaosresult when experiment is completed because of an error 66 | ResultVerdictError ResultVerdict = "Error" 67 | ) 68 | 69 | type ProbeVerdict string 70 | 71 | const ( 72 | ProbeVerdictPassed ProbeVerdict = "Passed" 73 | ProbeVerdictFailed ProbeVerdict = "Failed" 74 | ProbeVerdictNA ProbeVerdict = "N/A" 75 | ProbeVerdictAwaited ProbeVerdict = "Awaited" 76 | ) 77 | 78 | // ChaosResultStatus defines the observed state of ChaosResult 79 | type ChaosResultStatus struct { 80 | // ExperimentStatus contains the status,verdict of the experiment 81 | ExperimentStatus TestStatus `json:"experimentStatus"` 82 | // ProbeStatus contains the status of the probe 83 | ProbeStatuses []ProbeStatuses `json:"probeStatuses,omitempty"` 84 | // History contains cumulative values of verdicts 85 | History *HistoryDetails `json:"history,omitempty"` 86 | } 87 | 88 | // HistoryDetails contains cumulative values of verdicts 89 | type HistoryDetails struct { 90 | PassedRuns int `json:"passedRuns"` 91 | FailedRuns int `json:"failedRuns"` 92 | StoppedRuns int `json:"stoppedRuns"` 93 | Targets []TargetDetails `json:"targets,omitempty"` 94 | } 95 | 96 | // TargetDetails contains target details for the experiment and the chaos status 97 | type TargetDetails struct { 98 | Name string `json:"name,omitempty"` 99 | Kind string `json:"kind,omitempty"` 100 | ChaosStatus string `json:"chaosStatus,omitempty"` 101 | } 102 | 103 | // ProbeStatus defines information about the status and result of the probes 104 | type ProbeStatuses struct { 105 | // Name defines the name of probe 106 | Name string `json:"name,omitempty"` 107 | // Type defined the type of probe, supported values: K8sProbe, HttpProbe, CmdProbe 108 | Type string `json:"type,omitempty"` 109 | // Mode defined the mode of probe, supported values: SOT, EOT, Edge, OnChaos, Continuous 110 | Mode string `json:"mode,omitempty"` 111 | // Status defines whether a probe is pass or fail 112 | Status ProbeStatus `json:"status,omitempty"` 113 | } 114 | 115 | // ProbeStatus defines information about the status and result of the probes 116 | type ProbeStatus struct { 117 | // Verdict defines the verdict of the probe, range: Passed, Failed, N/A 118 | Verdict ProbeVerdict `json:"verdict,omitempty"` 119 | // Description defines the description of probe status 120 | Description string `json:"description,omitempty"` 121 | } 122 | 123 | // TestStatus defines information about the status and results of a chaos experiment 124 | type TestStatus struct { 125 | // Phase defines whether an experiment is running or completed 126 | Phase ResultPhase `json:"phase"` 127 | // Verdict defines whether an experiment result is pass or fail 128 | Verdict ResultVerdict `json:"verdict"` 129 | // ErrorOutput defines error message and error code 130 | ErrorOutput *ErrorOutput `json:"errorOutput,omitempty"` 131 | // ProbeSuccessPercentage defines the score of the probes 132 | ProbeSuccessPercentage string `json:"probeSuccessPercentage,omitempty"` 133 | } 134 | 135 | // ErrorOutput defines error reason and error code 136 | type ErrorOutput struct { 137 | // ErrorCode defines error code of the experiment 138 | ErrorCode string `json:"errorCode,omitempty"` 139 | // Reason contains the error reason 140 | Reason string `json:"reason,omitempty"` 141 | } 142 | 143 | //+kubebuilder:object:root=true 144 | //+kubebuilder:subresource:status 145 | // +genclient 146 | // +resource:path=chaosresult 147 | 148 | // ChaosResult is the Schema for the chaosresults API 149 | type ChaosResult struct { 150 | metav1.TypeMeta `json:",inline"` 151 | metav1.ObjectMeta `json:"metadata,omitempty"` 152 | 153 | Spec ChaosResultSpec `json:"spec,omitempty"` 154 | Status ChaosResultStatus `json:"status,omitempty"` 155 | } 156 | 157 | //+kubebuilder:object:root=true 158 | 159 | // ChaosResultList contains a list of ChaosResult 160 | type ChaosResultList struct { 161 | metav1.TypeMeta `json:",inline"` 162 | metav1.ListMeta `json:"metadata,omitempty"` 163 | Items []ChaosResult `json:"items"` 164 | } 165 | 166 | func init() { 167 | SchemeBuilder.Register(&ChaosResult{}, &ChaosResultList{}) 168 | } 169 | -------------------------------------------------------------------------------- /api/litmuschaos/v1alpha1/groupversion_info.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 LitmusChaos Authors 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Package v1alpha1 contains API Schema definitions for the litmuschaos.io v1alpha1 API group 18 | // +kubebuilder:object:generate=true 19 | // +groupName=litmuschaos.io 20 | package v1alpha1 21 | 22 | import ( 23 | "k8s.io/apimachinery/pkg/runtime/schema" 24 | "sigs.k8s.io/controller-runtime/pkg/scheme" 25 | ) 26 | 27 | var ( 28 | // SchemeGroupVersion is group version used to register these objects 29 | SchemeGroupVersion = schema.GroupVersion{Group: "litmuschaos.io", Version: "v1alpha1"} 30 | 31 | // SchemeBuilder is used to add go types to the GroupVersionKind scheme 32 | SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion} 33 | 34 | // AddToScheme adds the types in this group-version to the given scheme. 35 | AddToScheme = SchemeBuilder.AddToScheme 36 | ) 37 | 38 | // Resource takes an unqualified resource and returns a Group qualified GroupResource 39 | func Resource(resource string) schema.GroupResource { 40 | return SchemeGroupVersion.WithResource(resource).GroupResource() 41 | } 42 | -------------------------------------------------------------------------------- /build/Dockerfile: -------------------------------------------------------------------------------- 1 | # Multi-stage docker build 2 | # Build stage 3 | FROM golang:alpine AS builder 4 | 5 | LABEL maintainer="LitmusChaos" 6 | 7 | ARG TARGETPLATFORM 8 | 9 | ADD . /chaos-operator 10 | WORKDIR /chaos-operator 11 | 12 | RUN export GOOS=$(echo ${TARGETPLATFORM} | cut -d / -f1) && \ 13 | export GOARCH=$(echo ${TARGETPLATFORM} | cut -d / -f2) 14 | 15 | RUN go env 16 | 17 | RUN CGO_ENABLED=0 go build -buildvcs=false -o /output/chaos-operator -v ./main.go 18 | 19 | # Packaging stage 20 | FROM registry.access.redhat.com/ubi9/ubi-minimal:9.5 21 | 22 | LABEL maintainer="LitmusChaos" 23 | 24 | ENV OPERATOR=/usr/local/bin/chaos-operator 25 | 26 | COPY --from=builder /output/chaos-operator ${OPERATOR} 27 | RUN chown 65534:0 ${OPERATOR} && chmod 755 ${OPERATOR} 28 | 29 | USER 65534 30 | 31 | ENTRYPOINT ["/usr/local/bin/chaos-operator"] 32 | -------------------------------------------------------------------------------- /deploy/crds/chaosresults_crd.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apiextensions.k8s.io/v1 2 | kind: CustomResourceDefinition 3 | metadata: 4 | name: chaosresults.litmuschaos.io 5 | spec: 6 | group: litmuschaos.io 7 | names: 8 | kind: ChaosResult 9 | listKind: ChaosResultList 10 | plural: chaosresults 11 | singular: chaosresult 12 | scope: Namespaced 13 | versions: 14 | - name: v1alpha1 15 | schema: 16 | openAPIV3Schema: 17 | type: object 18 | properties: 19 | apiVersion: 20 | description: 'APIVersion defines the versioned schema of this representation 21 | of an object. Servers should convert recognized schemas to the latest 22 | internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#resources' 23 | type: string 24 | kind: 25 | description: 'Kind is a string value representing the REST resource this 26 | object represents. Servers may infer this from the endpoint the client 27 | submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds' 28 | type: string 29 | metadata: 30 | type: object 31 | spec: 32 | x-kubernetes-preserve-unknown-fields: true 33 | type: object 34 | status: 35 | x-kubernetes-preserve-unknown-fields: true 36 | type: object 37 | served: true 38 | storage: true 39 | subresources: {} 40 | conversion: 41 | strategy: None -------------------------------------------------------------------------------- /deploy/operator.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | labels: 5 | app.kubernetes.io/name: litmus 6 | # provide unique instance-id if applicable 7 | # app.kubernetes.io/instance: litmus-abcxzy 8 | app.kubernetes.io/version: ci 9 | app.kubernetes.io/component: operator 10 | app.kubernetes.io/part-of: litmus 11 | app.kubernetes.io/managed-by: kubectl 12 | name: litmus 13 | name: litmus 14 | namespace: litmus 15 | spec: 16 | replicas: 1 17 | selector: 18 | matchLabels: 19 | name: chaos-operator 20 | template: 21 | metadata: 22 | labels: 23 | app.kubernetes.io/name: litmus 24 | # provide unique instance-id if applicable 25 | # app.kubernetes.io/instance: litmus-abcxzy 26 | app.kubernetes.io/version: ci 27 | app.kubernetes.io/component: operator 28 | app.kubernetes.io/part-of: litmus 29 | app.kubernetes.io/managed-by: kubectl 30 | name: chaos-operator 31 | spec: 32 | serviceAccountName: litmus 33 | containers: 34 | - name: chaos-operator 35 | image: litmuschaos/chaos-operator:ci 36 | command: 37 | - chaos-operator 38 | args: 39 | - -leader-elect=true 40 | imagePullPolicy: IfNotPresent 41 | env: 42 | - name: CHAOS_RUNNER_IMAGE 43 | value: "litmuschaos.docker.scarf.sh/litmuschaos/chaos-runner:ci" 44 | - name: WATCH_NAMESPACE 45 | value: "" 46 | - name: POD_NAME 47 | valueFrom: 48 | fieldRef: 49 | fieldPath: metadata.name 50 | - name: POD_NAMESPACE 51 | valueFrom: 52 | fieldRef: 53 | fieldPath: metadata.namespace 54 | - name: OPERATOR_NAME 55 | value: "chaos-operator" 56 | -------------------------------------------------------------------------------- /deploy/rbac.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Namespace 3 | metadata: 4 | name: litmus 5 | --- 6 | apiVersion: v1 7 | kind: ServiceAccount 8 | metadata: 9 | name: litmus 10 | namespace: litmus 11 | labels: 12 | app.kubernetes.io/name: litmus 13 | # provide unique instance-id if applicable 14 | # app.kubernetes.io/instance: litmus-abcxzy 15 | app.kubernetes.io/version: ci 16 | app.kubernetes.io/component: operator-serviceaccount 17 | app.kubernetes.io/part-of: litmus 18 | app.kubernetes.io/managed-by: kubectl 19 | name: litmus 20 | --- 21 | apiVersion: rbac.authorization.k8s.io/v1 22 | kind: ClusterRole 23 | metadata: 24 | name: litmus 25 | labels: 26 | app.kubernetes.io/name: litmus 27 | # provide unique instance-id if applicable 28 | # app.kubernetes.io/instance: litmus-abcxzy 29 | app.kubernetes.io/version: ci 30 | app.kubernetes.io/component: operator-clusterrole 31 | app.kubernetes.io/part-of: litmus 32 | app.kubernetes.io/managed-by: kubectl 33 | name: litmus 34 | rules: 35 | - apiGroups: [""] 36 | resources: ["replicationcontrollers","secrets"] 37 | verbs: ["get","list"] 38 | - apiGroups: ["apps.openshift.io"] 39 | resources: ["deploymentconfigs"] 40 | verbs: ["get","list"] 41 | - apiGroups: ["apps"] 42 | resources: ["deployments", "daemonsets", "replicasets", "statefulsets"] 43 | verbs: ["get","list"] 44 | - apiGroups: ["batch"] 45 | resources: ["jobs"] 46 | verbs: ["get","list","deletecollection"] 47 | - apiGroups: ["argoproj.io"] 48 | resources: ["rollouts"] 49 | verbs: ["get","list"] 50 | - apiGroups: [""] 51 | resources: ["pods","configmaps","events","services"] 52 | verbs: ["get","create","update","patch","delete","list","watch","deletecollection"] 53 | - apiGroups: ["litmuschaos.io"] 54 | resources: ["chaosengines","chaosexperiments","chaosresults"] 55 | verbs: ["get","create","update","patch","delete","list","watch","deletecollection"] 56 | - apiGroups: ["apiextensions.k8s.io"] 57 | resources: ["customresourcedefinitions"] 58 | verbs: ["list","get"] 59 | - apiGroups: ["litmuschaos.io"] 60 | resources: ["chaosengines/finalizers"] 61 | verbs: ["update"] 62 | - apiGroups: ["coordination.k8s.io"] 63 | resources: ["leases"] 64 | verbs: ["get","create","list","update","delete"] 65 | --- 66 | apiVersion: rbac.authorization.k8s.io/v1 67 | kind: ClusterRoleBinding 68 | metadata: 69 | name: litmus 70 | labels: 71 | app.kubernetes.io/name: litmus 72 | # provide unique instance-id if applicable 73 | # app.kubernetes.io/instance: litmus-abcxzy 74 | app.kubernetes.io/version: ci 75 | app.kubernetes.io/component: operator-clusterrolebinding 76 | app.kubernetes.io/part-of: litmus 77 | app.kubernetes.io/managed-by: kubectl 78 | name: litmus 79 | roleRef: 80 | apiGroup: rbac.authorization.k8s.io 81 | kind: ClusterRole 82 | name: litmus 83 | subjects: 84 | - kind: ServiceAccount 85 | name: litmus 86 | namespace: litmus -------------------------------------------------------------------------------- /docs/chaos-operator-architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/litmuschaos/chaos-operator/af8244e53a0d2649ad9b78322470617b1f3fd69e/docs/chaos-operator-architecture.png -------------------------------------------------------------------------------- /docs/developer.md: -------------------------------------------------------------------------------- 1 | # Development Workflow 2 | 3 | ## Chaos-Operator Architecture 4 | 5 | ![Chaos-Operator Architecture](./docs/chaos-operator-architecture.png) 6 | 7 | ## Prerequisites 8 | 9 | * You have Go 1.10+ installed on your local host/development machine. 10 | * You have Docker installed on your local host/development machine. Docker is required for building chaos-operator component container images and to push them into a Kubernetes cluster for testing. 11 | 12 | ## Initial Setup 13 | 14 | ### Fork in the cloud 15 | 16 | 1. Visit https://github.com/litmuschaos/chaos-operator. 17 | 2. Click `Fork` button (top right) to establish a cloud-based fork. 18 | 19 | ### Clone fork to local host 20 | 21 | Place `litmuschaos/chaos-operator` code on your `GOPATH` using the following cloning procedure. 22 | Create your clone: 23 | 24 | ```sh 25 | 26 | mkdir -p $GOPATH/src/github.com/litmuschaos 27 | cd $GOPATH/src/github.com/litmuschaos 28 | 29 | # Note: Here $user is your GitHub profile name 30 | git clone https://github.com/$user/chaos-operator.git 31 | 32 | # Configure remote upstream 33 | cd $GOPATH/src/github.com/litmuschaos/chaos-operator 34 | git remote add upstream https://github.com/litmuschaos/chaos-operator.git 35 | 36 | # Never push to upstream master 37 | git remote set-url --push upstream no_push 38 | 39 | # Confirm that your remotes make sense 40 | git remote -v 41 | ``` 42 | 43 | ## Development 44 | 45 | ### Always sync your local repository 46 | 47 | Open a terminal on your local host. Change directory to the chaos-operator fork root. 48 | 49 | ```sh 50 | $ cd $GOPATH/src/github.com/litmuschaos/chaos-operator 51 | ``` 52 | 53 | Checkout the master branch. 54 | 55 | ```sh 56 | $ git checkout master 57 | Switched to branch 'master' 58 | Your branch is up-to-date with 'origin/master'. 59 | ``` 60 | 61 | Recall that origin/master is a branch on your remote GitHub repository. 62 | Make sure you have the upstream remote litmuschaos/chaos-operator by listing them. 63 | 64 | ```sh 65 | $ git remote -v 66 | origin https://github.com/$user/chaos-operator.git (fetch) 67 | origin https://github.com/$user/chaos-operator.git (push) 68 | upstream https://github.com/litmuschaos/chaos-operator.git (fetch) 69 | upstream no_push (push) 70 | ``` 71 | 72 | If the upstream is missing, add it by using below command. 73 | 74 | ```sh 75 | $ git remote add upstream https://github.com/litmuschaos/chaos-operator.git 76 | ``` 77 | 78 | Fetch all the changes from the upstream master branch. 79 | 80 | ```sh 81 | $ git fetch upstream master 82 | remote: Counting objects: 141, done. 83 | remote: Compressing objects: 100% (29/29), done. 84 | remote: Total 141 (delta 52), reused 46 (delta 46), pack-reused 66 85 | Receiving objects: 100% (141/141), 112.43 KiB | 0 bytes/s, done. 86 | Resolving deltas: 100% (79/79), done. 87 | From github.com:litmuschaos/chaos-operator 88 | * branch master -> FETCH_HEAD 89 | ``` 90 | 91 | Rebase your local master with the upstream/master. 92 | 93 | ```sh 94 | $ git rebase upstream/master 95 | First, rewinding head to replay your work on top of it... 96 | Fast-forwarded master to upstream/master. 97 | ``` 98 | 99 | This command applies all the commits from the upstream master to your local master. 100 | 101 | Check the status of your local branch. 102 | 103 | ```sh 104 | $ git status 105 | On branch master 106 | Your branch is ahead of 'origin/master' by 38 commits. 107 | (use "git push" to publish your local commits) 108 | nothing to commit, working directory clean 109 | ``` 110 | 111 | Your local repository now has all the changes from the upstream remote. You need to push the changes to your own remote fork which is origin master. 112 | 113 | Push the rebased master to origin master. 114 | 115 | ```sh 116 | $ git push origin master 117 | Username for 'https://github.com': $user 118 | Password for 'https://$user@github.com': 119 | Counting objects: 223, done. 120 | Compressing objects: 100% (38/38), done. 121 | Writing objects: 100% (69/69), 8.76 KiB | 0 bytes/s, done. 122 | Total 69 (delta 53), reused 47 (delta 31) 123 | To https://github.com/$user/chaos-operator.git 124 | 8e107a9..5035fa1 master -> master 125 | ``` 126 | 127 | ### Create a new feature branch to work on your issue 128 | 129 | Your branch name should have the format `XYZ-descriptive` where `XYZ` is the issue number you are working on followed by some descriptive text. For example: 130 | 131 | ```sh 132 | $ git checkout -b 256-fix-reconsiler 133 | Switched to a new branch '256-reconsiler' 134 | ``` 135 | 136 | ### Make your changes and build them 137 | 138 | ```sh 139 | cd $GOPATH/src/github.com/litmuschaos/chaos-operator 140 | make all 141 | ``` 142 | 143 | Check your linting. 144 | 145 | ```sh 146 | make lint 147 | ``` 148 | 149 | ### Test your changes 150 | 151 | - Replace the image with the builded image [here](../deploy/operator.yaml) 152 | 153 | - Run the choos-operator in kubernetes cluster 154 | ```sh 155 | cd $GOPATH/src/github.com/litmuschaos/chaos-operator 156 | kubectl apply -f ./deploy/chaos_crds.yaml 157 | kubectl apply -f ./deploy/rbac.yaml 158 | kubectl apply -f ./deploy/operator.yaml 159 | ``` 160 | - Run the chaos by following the [Litmus Docs](https://docs.litmuschaos.io/docs/getstarted/#install-chaos-experiments) 161 | 162 | - Verify the changes 163 | 164 | ### Keep your branch in sync 165 | 166 | [Rebasing](https://git-scm.com/docs/git-rebase) is very important to keep your branch in sync with the changes being made by others and to avoid huge merge conflicts while raising your Pull Requests. You will always have to rebase before raising the PR. 167 | 168 | ```sh 169 | git fetch upstream 170 | git rebase upstream/master 171 | ``` 172 | 173 | While you rebase your changes, you must resolve any conflicts that might arise and build and test your changes using the above steps. 174 | 175 | ## Submission 176 | 177 | ### Create a pull request 178 | 179 | Before you raise the Pull Requests, ensure you have reviewed the checklist in the [CONTRIBUTING GUIDE](../CONTRIBUTING.md): 180 | - Ensure that you have re-based your changes with the upstream using the steps above. 181 | - Ensure that you have added the required unit tests for the bug fixes or new feature that you have introduced. 182 | - Ensure your commits history is clean with proper header and descriptions. 183 | 184 | Go to the [litmuschaos/chaos-operator github](https://github.com/litmuschaos/chaos-operator) and follow the Open Pull Request link to raise your PR from your development branch. 185 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/litmuschaos/chaos-operator 2 | 3 | go 1.22 4 | 5 | require ( 6 | github.com/go-logr/logr v1.4.2 7 | github.com/google/go-cmp v0.5.9 // indirect 8 | github.com/jpillora/go-ogle-analytics v0.0.0-20161213085824-14b04e0594ef 9 | github.com/litmuschaos/elves v0.0.0-20230607095010-c7119636b529 10 | github.com/pkg/errors v0.9.1 11 | github.com/spf13/pflag v1.0.5 // indirect 12 | golang.org/x/oauth2 v0.7.0 // indirect 13 | k8s.io/api v0.26.15 14 | k8s.io/apimachinery v0.26.15 15 | k8s.io/client-go v12.0.0+incompatible 16 | sigs.k8s.io/controller-runtime v0.14.6 17 | ) 18 | 19 | require ( 20 | github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 21 | github.com/google/martian v2.1.0+incompatible 22 | github.com/onsi/ginkgo v1.16.5 23 | github.com/onsi/gomega v1.24.2 24 | github.com/stretchr/testify v1.8.2 25 | k8s.io/klog v1.0.0 26 | ) 27 | 28 | require ( 29 | github.com/beorn7/perks v1.0.1 // indirect 30 | github.com/cespare/xxhash/v2 v2.2.0 // indirect 31 | github.com/davecgh/go-spew v1.1.1 // indirect 32 | github.com/emicklei/go-restful/v3 v3.9.0 // indirect 33 | github.com/evanphx/json-patch v4.12.0+incompatible // indirect 34 | github.com/evanphx/json-patch/v5 v5.6.0 // indirect 35 | github.com/fsnotify/fsnotify v1.6.0 // indirect 36 | github.com/go-logr/zapr v1.2.3 // indirect 37 | github.com/go-openapi/jsonpointer v0.19.5 // indirect 38 | github.com/go-openapi/jsonreference v0.20.0 // indirect 39 | github.com/go-openapi/swag v0.19.14 // indirect 40 | github.com/gogo/protobuf v1.3.2 // indirect 41 | github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect 42 | github.com/golang/protobuf v1.5.4 // indirect 43 | github.com/google/gnostic v0.5.7-v3refs // indirect 44 | github.com/google/gofuzz v1.1.0 // indirect 45 | github.com/google/uuid v1.3.0 // indirect 46 | github.com/imdario/mergo v0.3.12 // indirect 47 | github.com/josharian/intern v1.0.0 // indirect 48 | github.com/json-iterator/go v1.1.12 // indirect 49 | github.com/mailru/easyjson v0.7.6 // indirect 50 | github.com/matttproud/golang_protobuf_extensions v1.0.2 // indirect 51 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect 52 | github.com/modern-go/reflect2 v1.0.2 // indirect 53 | github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect 54 | github.com/nxadm/tail v1.4.8 // indirect 55 | github.com/pmezard/go-difflib v1.0.0 // indirect 56 | github.com/prometheus/client_golang v1.14.0 // indirect 57 | github.com/prometheus/client_model v0.3.0 // indirect 58 | github.com/prometheus/common v0.37.0 // indirect 59 | github.com/prometheus/procfs v0.8.0 // indirect 60 | go.uber.org/atomic v1.7.0 // indirect 61 | go.uber.org/multierr v1.6.0 // indirect 62 | go.uber.org/zap v1.24.0 // indirect 63 | golang.org/x/net v0.19.0 // indirect 64 | golang.org/x/sys v0.15.0 // indirect 65 | golang.org/x/term v0.15.0 // indirect 66 | golang.org/x/text v0.14.0 // indirect 67 | golang.org/x/time v0.3.0 // indirect 68 | gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect 69 | google.golang.org/appengine v1.6.7 // indirect 70 | google.golang.org/protobuf v1.33.0 // indirect 71 | gopkg.in/inf.v0 v0.9.1 // indirect 72 | gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect 73 | gopkg.in/yaml.v2 v2.4.0 // indirect 74 | gopkg.in/yaml.v3 v3.0.1 // indirect 75 | k8s.io/apiextensions-apiserver v0.26.1 // indirect 76 | k8s.io/component-base v0.26.15 // indirect 77 | k8s.io/klog/v2 v2.80.1 // indirect 78 | k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 // indirect 79 | k8s.io/utils v0.0.0-20221128185143-99ec85e7a448 // indirect 80 | sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect 81 | sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect 82 | sigs.k8s.io/yaml v1.3.0 // indirect 83 | ) 84 | 85 | // Pinned to kubernetes-1.26 86 | replace ( 87 | sigs.k8s.io/controller-runtime => sigs.k8s.io/controller-runtime v0.14.6 88 | github.com/go-logr/logr => github.com/go-logr/logr v1.4.2 89 | k8s.io/api => k8s.io/api v0.26.15 90 | k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.26.15 91 | k8s.io/apimachinery => k8s.io/apimachinery v0.26.15 92 | k8s.io/client-go => k8s.io/client-go v0.26.15 93 | k8s.io/cloud-provider => k8s.io/cloud-provider v0.26.15 94 | k8s.io/cluster-bootstrap => k8s.io/cluster-bootstrap v0.26.15 95 | k8s.io/component-base => k8s.io/component-base v0.26.15 96 | k8s.io/cri-api => k8s.io/cri-api v0.26.15 97 | k8s.io/csi-translation-lib => k8s.io/csi-translation-lib v0.26.15 98 | k8s.io/klog/v2 => k8s.io/klog/v2 v2.80.1 99 | k8s.io/kube-aggregator => k8s.io/kube-aggregator v0.26.15 100 | k8s.io/kube-controller-manager => k8s.io/kube-controller-manager v0.26.15 101 | k8s.io/kube-proxy => k8s.io/kube-proxy v0.26.15 102 | k8s.io/kube-scheduler => k8s.io/kube-scheduler v0.26.15 103 | k8s.io/kubelet => k8s.io/kubelet v0.26.15 104 | k8s.io/legacy-cloud-providers => k8s.io/legacy-cloud-providers v0.26.15 105 | k8s.io/sample-apiserver => k8s.io/sample-apiserver v0.26.15 106 | ) 107 | 108 | replace github.com/docker/docker => github.com/moby/moby v0.7.3-0.20190826074503-38ab9da00309 // Required by Helm 109 | 110 | replace github.com/Azure/go-autorest => github.com/Azure/go-autorest v14.2.0+incompatible 111 | -------------------------------------------------------------------------------- /hack/boilerplate.go.txt: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 LitmusChaos Authors 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ -------------------------------------------------------------------------------- /hack/update-codegen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | #Copyright 2019 LitmusChaos Authors 4 | # 5 | #Licensed under the Apache License, Version 2.0 (the "License"); 6 | #you may not use this file except in compliance with the License. 7 | #You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | #Unless required by applicable law or agreed to in writing, software 12 | #distributed under the License is distributed on an "AS IS" BASIS, 13 | #WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | #See the License for the specific language governing permissions and 15 | #limitations under the License. 16 | # 17 | 18 | set -e 19 | 20 | if [[ -z $GOPATH ]]; then 21 | echo "Setting GOPATH to ~/go" 22 | GOPATH=~/go 23 | fi 24 | 25 | if [[ ! -d "${GOPATH}/src/k8s.io/code-generator" ]]; then 26 | echo ">>>>>> k8s.io/code-generator of v0.20.0 missing from GOPATH" 27 | echo ">>>>>> Cloning https://github.com/kubernetes/code-generator with tag v0.20.0 under '${GOPATH}/src/k8s.io'" 28 | git clone -b v0.20.0 https://github.com/kubernetes/code-generator ${GOPATH}/src/k8s.io/code-generator 29 | fi 30 | # Switching to v0.15.12 if already cloned 31 | git --git-dir=${GOPATH}/src/k8s.io/code-generator/.git --work-tree=${GOPATH}/src/k8s.io/code-generator checkout v0.20.0 32 | 33 | ${GOPATH}/src/k8s.io/code-generator/generate-groups.sh client,lister,informer \ 34 | github.com/litmuschaos/chaos-operator/pkg/client github.com/litmuschaos/chaos-operator/api \ 35 | litmuschaos:v1alpha1 36 | 37 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 LitmusChaos Authors 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package main 18 | 19 | import ( 20 | "flag" 21 | "fmt" 22 | "os" 23 | "runtime" 24 | "strings" 25 | 26 | "github.com/litmuschaos/chaos-operator/pkg/analytics" 27 | "github.com/pkg/errors" 28 | 29 | // Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.) 30 | // to ensure that exec-entrypoint and run can make use of them. 31 | _ "k8s.io/client-go/plugin/pkg/client/auth" 32 | 33 | schemeruntime "k8s.io/apimachinery/pkg/runtime" 34 | utilruntime "k8s.io/apimachinery/pkg/util/runtime" 35 | clientgoscheme "k8s.io/client-go/kubernetes/scheme" 36 | ctrl "sigs.k8s.io/controller-runtime" 37 | "sigs.k8s.io/controller-runtime/pkg/healthz" 38 | "sigs.k8s.io/controller-runtime/pkg/log/zap" 39 | 40 | litmuschaosiov1alpha1 "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" 41 | "github.com/litmuschaos/chaos-operator/controllers" 42 | //+kubebuilder:scaffold:imports 43 | ) 44 | 45 | var ( 46 | scheme = schemeruntime.NewScheme() 47 | setupLog = ctrl.Log.WithName("setup") 48 | ) 49 | 50 | func init() { 51 | utilruntime.Must(clientgoscheme.AddToScheme(scheme)) 52 | utilruntime.Must(litmuschaosiov1alpha1.AddToScheme(scheme)) 53 | //+kubebuilder:scaffold:scheme 54 | } 55 | 56 | func main() { 57 | var metricsAddr string 58 | var enableLeaderElection bool 59 | var probeAddr string 60 | flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.") 61 | flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.") 62 | flag.BoolVar(&enableLeaderElection, "leader-elect", false, 63 | "Enable leader election for controller manager. "+ 64 | "Enabling this will ensure there is only one active controller manager.") 65 | opts := zap.Options{ 66 | Development: true, 67 | } 68 | opts.BindFlags(flag.CommandLine) 69 | flag.Parse() 70 | 71 | ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts))) 72 | 73 | printVersion() 74 | 75 | namespace, found := os.LookupEnv("WATCH_NAMESPACE") 76 | if !found { 77 | setupLog.Error(errors.New("WATCH_NAMESPACE env is not set"), "failed to get watch namespace") 78 | os.Exit(1) 79 | } 80 | 81 | // Trigger the Analytics if it's enabled 82 | if isAnalytics := strings.ToUpper(os.Getenv("ANALYTICS")); isAnalytics != "FALSE" { 83 | if err := analytics.TriggerAnalytics(); err != nil { 84 | setupLog.Error(err, "failed to trigger analytics") 85 | } 86 | } 87 | 88 | mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{ 89 | Scheme: scheme, 90 | MetricsBindAddress: metricsAddr, 91 | Port: 9443, 92 | HealthProbeBindAddress: probeAddr, 93 | LeaderElection: enableLeaderElection, 94 | LeaderElectionID: "chaos-operator.lock", 95 | Namespace: namespace, 96 | // LeaderElectionReleaseOnCancel defines if the leader should step down voluntarily 97 | // when the Manager ends. This requires the binary to immediately end when the 98 | // Manager is stopped, otherwise, this setting is unsafe. Setting this significantly 99 | // speeds up voluntary leader transitions as the new leader don't have to wait 100 | // LeaseDuration time first. 101 | // 102 | // In the default scaffold provided, the program ends immediately after 103 | // the manager stops, so would be fine to enable this option. However, 104 | // if you are doing or is intended to do any operation such as perform cleanups 105 | // after the manager stops then its usage might be unsafe. 106 | // LeaderElectionReleaseOnCancel: true, 107 | }) 108 | if err != nil { 109 | setupLog.Error(err, "unable to start manager") 110 | os.Exit(1) 111 | } 112 | 113 | if err = (&controllers.ChaosEngineReconciler{ 114 | Client: mgr.GetClient(), 115 | Scheme: mgr.GetScheme(), 116 | Recorder: mgr.GetEventRecorderFor("chaos-operator"), 117 | }).SetupWithManager(mgr); err != nil { 118 | setupLog.Error(err, "unable to create controller", "controller", "ChaosEngine") 119 | os.Exit(1) 120 | } 121 | //+kubebuilder:scaffold:builder 122 | 123 | if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil { 124 | setupLog.Error(err, "unable to set up health check") 125 | os.Exit(1) 126 | } 127 | if err := mgr.AddReadyzCheck("readyz", healthz.Ping); err != nil { 128 | setupLog.Error(err, "unable to set up ready check") 129 | os.Exit(1) 130 | } 131 | 132 | setupLog.Info("starting manager") 133 | if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil { 134 | setupLog.Error(err, "problem running manager") 135 | os.Exit(1) 136 | } 137 | 138 | } 139 | 140 | func printVersion() { 141 | setupLog.Info(fmt.Sprintf("Go Version: %s", runtime.Version())) 142 | setupLog.Info(fmt.Sprintf("Go OS/Arch: %s/%s", runtime.GOOS, runtime.GOARCH)) 143 | } 144 | -------------------------------------------------------------------------------- /pkg/analytics/analytics.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 LitmusChaos Authors 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package analytics 18 | 19 | import ( 20 | "fmt" 21 | 22 | ga "github.com/jpillora/go-ogle-analytics" 23 | ) 24 | 25 | const ( 26 | // ClientID contains TrackingID of the application 27 | clientID = "UA-92076314-21" 28 | 29 | // supported event categories 30 | 31 | // Category category notifies installation of a component of Litmus Infrastructure 32 | category = "Litmus-Infra" 33 | 34 | // supported event actions 35 | 36 | // Action is sent when the installation is triggered 37 | action = "Installation" 38 | 39 | // supported event labels 40 | 41 | // Label denotes event is associated to which Litmus component 42 | label = "Chaos-Operator" 43 | ) 44 | 45 | // TriggerAnalytics is responsible for sending out events 46 | func TriggerAnalytics() error { 47 | client, err := ga.NewClient(clientID) 48 | if err != nil { 49 | return fmt.Errorf("new client generation failed, error : %s", err) 50 | } 51 | // sets the clientUUID to operator uid 52 | ClientUUID, err = getUID() 53 | if err != nil { 54 | return err 55 | } 56 | client.ClientID(ClientUUID) 57 | if err := client.Send(ga.NewEvent(category, action).Label(label)); err != nil { 58 | return fmt.Errorf("analytics event sending failed, error: %s", err) 59 | } 60 | return nil 61 | } 62 | -------------------------------------------------------------------------------- /pkg/analytics/uuid.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 LitmusChaos Authors 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package analytics 18 | 19 | import ( 20 | "context" 21 | "fmt" 22 | "os" 23 | 24 | clientset "github.com/litmuschaos/chaos-operator/pkg/client/kubernetes" 25 | core_v1 "k8s.io/api/core/v1" 26 | v1 "k8s.io/apimachinery/pkg/apis/meta/v1" 27 | "k8s.io/client-go/kubernetes" 28 | ) 29 | 30 | // ClientUUID contains clientUUID for analytics 31 | var ClientUUID string 32 | 33 | // it derives the UID of the chaos-operator deployment 34 | // and used it for the analytics 35 | func getUID() (string, error) { 36 | // creates kubernetes client 37 | clients, err := clientset.CreateClientSet() 38 | if err != nil { 39 | return "", err 40 | } 41 | // deriving operator pod name & namespace 42 | podName := os.Getenv("POD_NAME") 43 | podNamespace := os.Getenv("POD_NAMESPACE") 44 | if podName == "" || podNamespace == "" { 45 | return podName, fmt.Errorf("POD_NAME or POD_NAMESPACE ENV not set") 46 | } 47 | // get operator pod details 48 | pod, err := clients.CoreV1().Pods(podNamespace).Get(context.Background(), podName, v1.GetOptions{}) 49 | if err != nil { 50 | return "", fmt.Errorf("unable to get %s pod in %s namespace", podName, podNamespace) 51 | } 52 | return getOperatorUID(pod, clients) 53 | } 54 | 55 | // it returns the deployment name, derived from the owner references 56 | func getDeploymentName(pod *core_v1.Pod, clients *kubernetes.Clientset) (string, error) { 57 | for _, own := range pod.OwnerReferences { 58 | if own.Kind == "ReplicaSet" { 59 | rs, err := clients.AppsV1().ReplicaSets(pod.Namespace).Get(context.Background(), own.Name, v1.GetOptions{}) 60 | if err != nil { 61 | return "", err 62 | } 63 | for _, own := range rs.OwnerReferences { 64 | if own.Kind == "Deployment" { 65 | return own.Name, nil 66 | } 67 | } 68 | } 69 | } 70 | return "", fmt.Errorf("no deployment found for %v pod", pod.Name) 71 | } 72 | 73 | // it returns the uid of the chaos-operator deployment 74 | func getOperatorUID(pod *core_v1.Pod, clients *kubernetes.Clientset) (string, error) { 75 | // derive the deployment name belongs to operator pod 76 | deployName, err := getDeploymentName(pod, clients) 77 | if err != nil { 78 | return "", err 79 | } 80 | 81 | deploy, err := clients.AppsV1().Deployments(pod.Namespace).Get(context.Background(), deployName, v1.GetOptions{}) 82 | if err != nil { 83 | return "", fmt.Errorf("unable to get %s deployment in %s namespace", deployName, pod.Namespace) 84 | } 85 | if string(deploy.UID) == "" { 86 | return "", fmt.Errorf("unable to find the deployment uid") 87 | } 88 | return string(deploy.UID), nil 89 | } 90 | -------------------------------------------------------------------------------- /pkg/client/clientset/versioned/clientset.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Code generated by client-gen. DO NOT EDIT. 18 | 19 | package versioned 20 | 21 | import ( 22 | "fmt" 23 | 24 | litmuschaosv1alpha1 "github.com/litmuschaos/chaos-operator/pkg/client/clientset/versioned/typed/litmuschaos/v1alpha1" 25 | discovery "k8s.io/client-go/discovery" 26 | rest "k8s.io/client-go/rest" 27 | flowcontrol "k8s.io/client-go/util/flowcontrol" 28 | ) 29 | 30 | type Interface interface { 31 | Discovery() discovery.DiscoveryInterface 32 | LitmuschaosV1alpha1() litmuschaosv1alpha1.LitmuschaosV1alpha1Interface 33 | } 34 | 35 | // Clientset contains the clients for groups. Each group has exactly one 36 | // version included in a Clientset. 37 | type Clientset struct { 38 | *discovery.DiscoveryClient 39 | litmuschaosV1alpha1 *litmuschaosv1alpha1.LitmuschaosV1alpha1Client 40 | } 41 | 42 | // LitmuschaosV1alpha1 retrieves the LitmuschaosV1alpha1Client 43 | func (c *Clientset) LitmuschaosV1alpha1() litmuschaosv1alpha1.LitmuschaosV1alpha1Interface { 44 | return c.litmuschaosV1alpha1 45 | } 46 | 47 | // Discovery retrieves the DiscoveryClient 48 | func (c *Clientset) Discovery() discovery.DiscoveryInterface { 49 | if c == nil { 50 | return nil 51 | } 52 | return c.DiscoveryClient 53 | } 54 | 55 | // NewForConfig creates a new Clientset for the given config. 56 | // If config's RateLimiter is not set and QPS and Burst are acceptable, 57 | // NewForConfig will generate a rate-limiter in configShallowCopy. 58 | func NewForConfig(c *rest.Config) (*Clientset, error) { 59 | configShallowCopy := *c 60 | if configShallowCopy.RateLimiter == nil && configShallowCopy.QPS > 0 { 61 | if configShallowCopy.Burst <= 0 { 62 | return nil, fmt.Errorf("burst is required to be greater than 0 when RateLimiter is not set and QPS is set to greater than 0") 63 | } 64 | configShallowCopy.RateLimiter = flowcontrol.NewTokenBucketRateLimiter(configShallowCopy.QPS, configShallowCopy.Burst) 65 | } 66 | var cs Clientset 67 | var err error 68 | cs.litmuschaosV1alpha1, err = litmuschaosv1alpha1.NewForConfig(&configShallowCopy) 69 | if err != nil { 70 | return nil, err 71 | } 72 | 73 | cs.DiscoveryClient, err = discovery.NewDiscoveryClientForConfig(&configShallowCopy) 74 | if err != nil { 75 | return nil, err 76 | } 77 | return &cs, nil 78 | } 79 | 80 | // NewForConfigOrDie creates a new Clientset for the given config and 81 | // panics if there is an error in the config. 82 | func NewForConfigOrDie(c *rest.Config) *Clientset { 83 | var cs Clientset 84 | cs.litmuschaosV1alpha1 = litmuschaosv1alpha1.NewForConfigOrDie(c) 85 | 86 | cs.DiscoveryClient = discovery.NewDiscoveryClientForConfigOrDie(c) 87 | return &cs 88 | } 89 | 90 | // New creates a new Clientset for the given RESTClient. 91 | func New(c rest.Interface) *Clientset { 92 | var cs Clientset 93 | cs.litmuschaosV1alpha1 = litmuschaosv1alpha1.New(c) 94 | 95 | cs.DiscoveryClient = discovery.NewDiscoveryClient(c) 96 | return &cs 97 | } 98 | -------------------------------------------------------------------------------- /pkg/client/clientset/versioned/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Code generated by client-gen. DO NOT EDIT. 18 | 19 | // This package has the automatically generated clientset. 20 | package versioned 21 | -------------------------------------------------------------------------------- /pkg/client/clientset/versioned/fake/clientset_generated.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Code generated by client-gen. DO NOT EDIT. 18 | 19 | package fake 20 | 21 | import ( 22 | clientset "github.com/litmuschaos/chaos-operator/pkg/client/clientset/versioned" 23 | litmuschaosv1alpha1 "github.com/litmuschaos/chaos-operator/pkg/client/clientset/versioned/typed/litmuschaos/v1alpha1" 24 | fakelitmuschaosv1alpha1 "github.com/litmuschaos/chaos-operator/pkg/client/clientset/versioned/typed/litmuschaos/v1alpha1/fake" 25 | "k8s.io/apimachinery/pkg/runtime" 26 | "k8s.io/apimachinery/pkg/watch" 27 | "k8s.io/client-go/discovery" 28 | fakediscovery "k8s.io/client-go/discovery/fake" 29 | "k8s.io/client-go/testing" 30 | ) 31 | 32 | // NewSimpleClientset returns a clientset that will respond with the provided objects. 33 | // It's backed by a very simple object tracker that processes creates, updates and deletions as-is, 34 | // without applying any validations and/or defaults. It shouldn't be considered a replacement 35 | // for a real clientset and is mostly useful in simple unit tests. 36 | func NewSimpleClientset(objects ...runtime.Object) *Clientset { 37 | o := testing.NewObjectTracker(scheme, codecs.UniversalDecoder()) 38 | for _, obj := range objects { 39 | if err := o.Add(obj); err != nil { 40 | panic(err) 41 | } 42 | } 43 | 44 | cs := &Clientset{tracker: o} 45 | cs.discovery = &fakediscovery.FakeDiscovery{Fake: &cs.Fake} 46 | cs.AddReactor("*", "*", testing.ObjectReaction(o)) 47 | cs.AddWatchReactor("*", func(action testing.Action) (handled bool, ret watch.Interface, err error) { 48 | gvr := action.GetResource() 49 | ns := action.GetNamespace() 50 | watch, err := o.Watch(gvr, ns) 51 | if err != nil { 52 | return false, nil, err 53 | } 54 | return true, watch, nil 55 | }) 56 | 57 | return cs 58 | } 59 | 60 | // Clientset implements clientset.Interface. Meant to be embedded into a 61 | // struct to get a default implementation. This makes faking out just the method 62 | // you want to test easier. 63 | type Clientset struct { 64 | testing.Fake 65 | discovery *fakediscovery.FakeDiscovery 66 | tracker testing.ObjectTracker 67 | } 68 | 69 | func (c *Clientset) Discovery() discovery.DiscoveryInterface { 70 | return c.discovery 71 | } 72 | 73 | func (c *Clientset) Tracker() testing.ObjectTracker { 74 | return c.tracker 75 | } 76 | 77 | var _ clientset.Interface = &Clientset{} 78 | 79 | // LitmuschaosV1alpha1 retrieves the LitmuschaosV1alpha1Client 80 | func (c *Clientset) LitmuschaosV1alpha1() litmuschaosv1alpha1.LitmuschaosV1alpha1Interface { 81 | return &fakelitmuschaosv1alpha1.FakeLitmuschaosV1alpha1{Fake: &c.Fake} 82 | } 83 | -------------------------------------------------------------------------------- /pkg/client/clientset/versioned/fake/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Code generated by client-gen. DO NOT EDIT. 18 | 19 | // This package has the automatically generated fake clientset. 20 | package fake 21 | -------------------------------------------------------------------------------- /pkg/client/clientset/versioned/fake/register.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Code generated by client-gen. DO NOT EDIT. 18 | 19 | package fake 20 | 21 | import ( 22 | litmuschaosv1alpha1 "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" 23 | v1 "k8s.io/apimachinery/pkg/apis/meta/v1" 24 | runtime "k8s.io/apimachinery/pkg/runtime" 25 | schema "k8s.io/apimachinery/pkg/runtime/schema" 26 | serializer "k8s.io/apimachinery/pkg/runtime/serializer" 27 | utilruntime "k8s.io/apimachinery/pkg/util/runtime" 28 | ) 29 | 30 | var scheme = runtime.NewScheme() 31 | var codecs = serializer.NewCodecFactory(scheme) 32 | 33 | var localSchemeBuilder = runtime.SchemeBuilder{ 34 | litmuschaosv1alpha1.AddToScheme, 35 | } 36 | 37 | // AddToScheme adds all types of this clientset into the given scheme. This allows composition 38 | // of clientsets, like in: 39 | // 40 | // import ( 41 | // "k8s.io/client-go/kubernetes" 42 | // clientsetscheme "k8s.io/client-go/kubernetes/scheme" 43 | // aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" 44 | // ) 45 | // 46 | // kclientset, _ := kubernetes.NewForConfig(c) 47 | // _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) 48 | // 49 | // After this, RawExtensions in Kubernetes types will serialize kube-aggregator types 50 | // correctly. 51 | var AddToScheme = localSchemeBuilder.AddToScheme 52 | 53 | func init() { 54 | v1.AddToGroupVersion(scheme, schema.GroupVersion{Version: "v1"}) 55 | utilruntime.Must(AddToScheme(scheme)) 56 | } 57 | -------------------------------------------------------------------------------- /pkg/client/clientset/versioned/scheme/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Code generated by client-gen. DO NOT EDIT. 18 | 19 | // This package contains the scheme of the automatically generated clientset. 20 | package scheme 21 | -------------------------------------------------------------------------------- /pkg/client/clientset/versioned/scheme/register.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Code generated by client-gen. DO NOT EDIT. 18 | 19 | package scheme 20 | 21 | import ( 22 | litmuschaosv1alpha1 "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" 23 | v1 "k8s.io/apimachinery/pkg/apis/meta/v1" 24 | runtime "k8s.io/apimachinery/pkg/runtime" 25 | schema "k8s.io/apimachinery/pkg/runtime/schema" 26 | serializer "k8s.io/apimachinery/pkg/runtime/serializer" 27 | utilruntime "k8s.io/apimachinery/pkg/util/runtime" 28 | ) 29 | 30 | var Scheme = runtime.NewScheme() 31 | var Codecs = serializer.NewCodecFactory(Scheme) 32 | var ParameterCodec = runtime.NewParameterCodec(Scheme) 33 | var localSchemeBuilder = runtime.SchemeBuilder{ 34 | litmuschaosv1alpha1.AddToScheme, 35 | } 36 | 37 | // AddToScheme adds all types of this clientset into the given scheme. This allows composition 38 | // of clientsets, like in: 39 | // 40 | // import ( 41 | // "k8s.io/client-go/kubernetes" 42 | // clientsetscheme "k8s.io/client-go/kubernetes/scheme" 43 | // aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" 44 | // ) 45 | // 46 | // kclientset, _ := kubernetes.NewForConfig(c) 47 | // _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) 48 | // 49 | // After this, RawExtensions in Kubernetes types will serialize kube-aggregator types 50 | // correctly. 51 | var AddToScheme = localSchemeBuilder.AddToScheme 52 | 53 | func init() { 54 | v1.AddToGroupVersion(Scheme, schema.GroupVersion{Version: "v1"}) 55 | utilruntime.Must(AddToScheme(Scheme)) 56 | } 57 | -------------------------------------------------------------------------------- /pkg/client/clientset/versioned/typed/litmuschaos/v1alpha1/chaosengine.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Code generated by client-gen. DO NOT EDIT. 18 | 19 | package v1alpha1 20 | 21 | import ( 22 | "context" 23 | "time" 24 | 25 | v1alpha1 "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" 26 | scheme "github.com/litmuschaos/chaos-operator/pkg/client/clientset/versioned/scheme" 27 | v1 "k8s.io/apimachinery/pkg/apis/meta/v1" 28 | types "k8s.io/apimachinery/pkg/types" 29 | watch "k8s.io/apimachinery/pkg/watch" 30 | rest "k8s.io/client-go/rest" 31 | ) 32 | 33 | // ChaosEnginesGetter has a method to return a ChaosEngineInterface. 34 | // A group's client should implement this interface. 35 | type ChaosEnginesGetter interface { 36 | ChaosEngines(namespace string) ChaosEngineInterface 37 | } 38 | 39 | // ChaosEngineInterface has methods to work with ChaosEngine resources. 40 | type ChaosEngineInterface interface { 41 | Create(ctx context.Context, chaosEngine *v1alpha1.ChaosEngine, opts v1.CreateOptions) (*v1alpha1.ChaosEngine, error) 42 | Update(ctx context.Context, chaosEngine *v1alpha1.ChaosEngine, opts v1.UpdateOptions) (*v1alpha1.ChaosEngine, error) 43 | UpdateStatus(ctx context.Context, chaosEngine *v1alpha1.ChaosEngine, opts v1.UpdateOptions) (*v1alpha1.ChaosEngine, error) 44 | Delete(ctx context.Context, name string, opts v1.DeleteOptions) error 45 | DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error 46 | Get(ctx context.Context, name string, opts v1.GetOptions) (*v1alpha1.ChaosEngine, error) 47 | List(ctx context.Context, opts v1.ListOptions) (*v1alpha1.ChaosEngineList, error) 48 | Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) 49 | Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.ChaosEngine, err error) 50 | ChaosEngineExpansion 51 | } 52 | 53 | // chaosEngines implements ChaosEngineInterface 54 | type chaosEngines struct { 55 | client rest.Interface 56 | ns string 57 | } 58 | 59 | // newChaosEngines returns a ChaosEngines 60 | func newChaosEngines(c *LitmuschaosV1alpha1Client, namespace string) *chaosEngines { 61 | return &chaosEngines{ 62 | client: c.RESTClient(), 63 | ns: namespace, 64 | } 65 | } 66 | 67 | // Get takes name of the chaosEngine, and returns the corresponding chaosEngine object, and an error if there is any. 68 | func (c *chaosEngines) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.ChaosEngine, err error) { 69 | result = &v1alpha1.ChaosEngine{} 70 | err = c.client.Get(). 71 | Namespace(c.ns). 72 | Resource("chaosengines"). 73 | Name(name). 74 | VersionedParams(&options, scheme.ParameterCodec). 75 | Do(ctx). 76 | Into(result) 77 | return 78 | } 79 | 80 | // List takes label and field selectors, and returns the list of ChaosEngines that match those selectors. 81 | func (c *chaosEngines) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.ChaosEngineList, err error) { 82 | var timeout time.Duration 83 | if opts.TimeoutSeconds != nil { 84 | timeout = time.Duration(*opts.TimeoutSeconds) * time.Second 85 | } 86 | result = &v1alpha1.ChaosEngineList{} 87 | err = c.client.Get(). 88 | Namespace(c.ns). 89 | Resource("chaosengines"). 90 | VersionedParams(&opts, scheme.ParameterCodec). 91 | Timeout(timeout). 92 | Do(ctx). 93 | Into(result) 94 | return 95 | } 96 | 97 | // Watch returns a watch.Interface that watches the requested chaosEngines. 98 | func (c *chaosEngines) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { 99 | var timeout time.Duration 100 | if opts.TimeoutSeconds != nil { 101 | timeout = time.Duration(*opts.TimeoutSeconds) * time.Second 102 | } 103 | opts.Watch = true 104 | return c.client.Get(). 105 | Namespace(c.ns). 106 | Resource("chaosengines"). 107 | VersionedParams(&opts, scheme.ParameterCodec). 108 | Timeout(timeout). 109 | Watch(ctx) 110 | } 111 | 112 | // Create takes the representation of a chaosEngine and creates it. Returns the server's representation of the chaosEngine, and an error, if there is any. 113 | func (c *chaosEngines) Create(ctx context.Context, chaosEngine *v1alpha1.ChaosEngine, opts v1.CreateOptions) (result *v1alpha1.ChaosEngine, err error) { 114 | result = &v1alpha1.ChaosEngine{} 115 | err = c.client.Post(). 116 | Namespace(c.ns). 117 | Resource("chaosengines"). 118 | VersionedParams(&opts, scheme.ParameterCodec). 119 | Body(chaosEngine). 120 | Do(ctx). 121 | Into(result) 122 | return 123 | } 124 | 125 | // Update takes the representation of a chaosEngine and updates it. Returns the server's representation of the chaosEngine, and an error, if there is any. 126 | func (c *chaosEngines) Update(ctx context.Context, chaosEngine *v1alpha1.ChaosEngine, opts v1.UpdateOptions) (result *v1alpha1.ChaosEngine, err error) { 127 | result = &v1alpha1.ChaosEngine{} 128 | err = c.client.Put(). 129 | Namespace(c.ns). 130 | Resource("chaosengines"). 131 | Name(chaosEngine.Name). 132 | VersionedParams(&opts, scheme.ParameterCodec). 133 | Body(chaosEngine). 134 | Do(ctx). 135 | Into(result) 136 | return 137 | } 138 | 139 | // UpdateStatus was generated because the type contains a Status member. 140 | // Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). 141 | func (c *chaosEngines) UpdateStatus(ctx context.Context, chaosEngine *v1alpha1.ChaosEngine, opts v1.UpdateOptions) (result *v1alpha1.ChaosEngine, err error) { 142 | result = &v1alpha1.ChaosEngine{} 143 | err = c.client.Put(). 144 | Namespace(c.ns). 145 | Resource("chaosengines"). 146 | Name(chaosEngine.Name). 147 | SubResource("status"). 148 | VersionedParams(&opts, scheme.ParameterCodec). 149 | Body(chaosEngine). 150 | Do(ctx). 151 | Into(result) 152 | return 153 | } 154 | 155 | // Delete takes name of the chaosEngine and deletes it. Returns an error if one occurs. 156 | func (c *chaosEngines) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { 157 | return c.client.Delete(). 158 | Namespace(c.ns). 159 | Resource("chaosengines"). 160 | Name(name). 161 | Body(&opts). 162 | Do(ctx). 163 | Error() 164 | } 165 | 166 | // DeleteCollection deletes a collection of objects. 167 | func (c *chaosEngines) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { 168 | var timeout time.Duration 169 | if listOpts.TimeoutSeconds != nil { 170 | timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second 171 | } 172 | return c.client.Delete(). 173 | Namespace(c.ns). 174 | Resource("chaosengines"). 175 | VersionedParams(&listOpts, scheme.ParameterCodec). 176 | Timeout(timeout). 177 | Body(&opts). 178 | Do(ctx). 179 | Error() 180 | } 181 | 182 | // Patch applies the patch and returns the patched chaosEngine. 183 | func (c *chaosEngines) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.ChaosEngine, err error) { 184 | result = &v1alpha1.ChaosEngine{} 185 | err = c.client.Patch(pt). 186 | Namespace(c.ns). 187 | Resource("chaosengines"). 188 | Name(name). 189 | SubResource(subresources...). 190 | VersionedParams(&opts, scheme.ParameterCodec). 191 | Body(data). 192 | Do(ctx). 193 | Into(result) 194 | return 195 | } 196 | -------------------------------------------------------------------------------- /pkg/client/clientset/versioned/typed/litmuschaos/v1alpha1/chaosexperiment.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Code generated by client-gen. DO NOT EDIT. 18 | 19 | package v1alpha1 20 | 21 | import ( 22 | "context" 23 | "time" 24 | 25 | v1alpha1 "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" 26 | scheme "github.com/litmuschaos/chaos-operator/pkg/client/clientset/versioned/scheme" 27 | v1 "k8s.io/apimachinery/pkg/apis/meta/v1" 28 | types "k8s.io/apimachinery/pkg/types" 29 | watch "k8s.io/apimachinery/pkg/watch" 30 | rest "k8s.io/client-go/rest" 31 | ) 32 | 33 | // ChaosExperimentsGetter has a method to return a ChaosExperimentInterface. 34 | // A group's client should implement this interface. 35 | type ChaosExperimentsGetter interface { 36 | ChaosExperiments(namespace string) ChaosExperimentInterface 37 | } 38 | 39 | // ChaosExperimentInterface has methods to work with ChaosExperiment resources. 40 | type ChaosExperimentInterface interface { 41 | Create(ctx context.Context, chaosExperiment *v1alpha1.ChaosExperiment, opts v1.CreateOptions) (*v1alpha1.ChaosExperiment, error) 42 | Update(ctx context.Context, chaosExperiment *v1alpha1.ChaosExperiment, opts v1.UpdateOptions) (*v1alpha1.ChaosExperiment, error) 43 | UpdateStatus(ctx context.Context, chaosExperiment *v1alpha1.ChaosExperiment, opts v1.UpdateOptions) (*v1alpha1.ChaosExperiment, error) 44 | Delete(ctx context.Context, name string, opts v1.DeleteOptions) error 45 | DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error 46 | Get(ctx context.Context, name string, opts v1.GetOptions) (*v1alpha1.ChaosExperiment, error) 47 | List(ctx context.Context, opts v1.ListOptions) (*v1alpha1.ChaosExperimentList, error) 48 | Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) 49 | Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.ChaosExperiment, err error) 50 | ChaosExperimentExpansion 51 | } 52 | 53 | // chaosExperiments implements ChaosExperimentInterface 54 | type chaosExperiments struct { 55 | client rest.Interface 56 | ns string 57 | } 58 | 59 | // newChaosExperiments returns a ChaosExperiments 60 | func newChaosExperiments(c *LitmuschaosV1alpha1Client, namespace string) *chaosExperiments { 61 | return &chaosExperiments{ 62 | client: c.RESTClient(), 63 | ns: namespace, 64 | } 65 | } 66 | 67 | // Get takes name of the chaosExperiment, and returns the corresponding chaosExperiment object, and an error if there is any. 68 | func (c *chaosExperiments) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.ChaosExperiment, err error) { 69 | result = &v1alpha1.ChaosExperiment{} 70 | err = c.client.Get(). 71 | Namespace(c.ns). 72 | Resource("chaosexperiments"). 73 | Name(name). 74 | VersionedParams(&options, scheme.ParameterCodec). 75 | Do(ctx). 76 | Into(result) 77 | return 78 | } 79 | 80 | // List takes label and field selectors, and returns the list of ChaosExperiments that match those selectors. 81 | func (c *chaosExperiments) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.ChaosExperimentList, err error) { 82 | var timeout time.Duration 83 | if opts.TimeoutSeconds != nil { 84 | timeout = time.Duration(*opts.TimeoutSeconds) * time.Second 85 | } 86 | result = &v1alpha1.ChaosExperimentList{} 87 | err = c.client.Get(). 88 | Namespace(c.ns). 89 | Resource("chaosexperiments"). 90 | VersionedParams(&opts, scheme.ParameterCodec). 91 | Timeout(timeout). 92 | Do(ctx). 93 | Into(result) 94 | return 95 | } 96 | 97 | // Watch returns a watch.Interface that watches the requested chaosExperiments. 98 | func (c *chaosExperiments) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { 99 | var timeout time.Duration 100 | if opts.TimeoutSeconds != nil { 101 | timeout = time.Duration(*opts.TimeoutSeconds) * time.Second 102 | } 103 | opts.Watch = true 104 | return c.client.Get(). 105 | Namespace(c.ns). 106 | Resource("chaosexperiments"). 107 | VersionedParams(&opts, scheme.ParameterCodec). 108 | Timeout(timeout). 109 | Watch(ctx) 110 | } 111 | 112 | // Create takes the representation of a chaosExperiment and creates it. Returns the server's representation of the chaosExperiment, and an error, if there is any. 113 | func (c *chaosExperiments) Create(ctx context.Context, chaosExperiment *v1alpha1.ChaosExperiment, opts v1.CreateOptions) (result *v1alpha1.ChaosExperiment, err error) { 114 | result = &v1alpha1.ChaosExperiment{} 115 | err = c.client.Post(). 116 | Namespace(c.ns). 117 | Resource("chaosexperiments"). 118 | VersionedParams(&opts, scheme.ParameterCodec). 119 | Body(chaosExperiment). 120 | Do(ctx). 121 | Into(result) 122 | return 123 | } 124 | 125 | // Update takes the representation of a chaosExperiment and updates it. Returns the server's representation of the chaosExperiment, and an error, if there is any. 126 | func (c *chaosExperiments) Update(ctx context.Context, chaosExperiment *v1alpha1.ChaosExperiment, opts v1.UpdateOptions) (result *v1alpha1.ChaosExperiment, err error) { 127 | result = &v1alpha1.ChaosExperiment{} 128 | err = c.client.Put(). 129 | Namespace(c.ns). 130 | Resource("chaosexperiments"). 131 | Name(chaosExperiment.Name). 132 | VersionedParams(&opts, scheme.ParameterCodec). 133 | Body(chaosExperiment). 134 | Do(ctx). 135 | Into(result) 136 | return 137 | } 138 | 139 | // UpdateStatus was generated because the type contains a Status member. 140 | // Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). 141 | func (c *chaosExperiments) UpdateStatus(ctx context.Context, chaosExperiment *v1alpha1.ChaosExperiment, opts v1.UpdateOptions) (result *v1alpha1.ChaosExperiment, err error) { 142 | result = &v1alpha1.ChaosExperiment{} 143 | err = c.client.Put(). 144 | Namespace(c.ns). 145 | Resource("chaosexperiments"). 146 | Name(chaosExperiment.Name). 147 | SubResource("status"). 148 | VersionedParams(&opts, scheme.ParameterCodec). 149 | Body(chaosExperiment). 150 | Do(ctx). 151 | Into(result) 152 | return 153 | } 154 | 155 | // Delete takes name of the chaosExperiment and deletes it. Returns an error if one occurs. 156 | func (c *chaosExperiments) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { 157 | return c.client.Delete(). 158 | Namespace(c.ns). 159 | Resource("chaosexperiments"). 160 | Name(name). 161 | Body(&opts). 162 | Do(ctx). 163 | Error() 164 | } 165 | 166 | // DeleteCollection deletes a collection of objects. 167 | func (c *chaosExperiments) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { 168 | var timeout time.Duration 169 | if listOpts.TimeoutSeconds != nil { 170 | timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second 171 | } 172 | return c.client.Delete(). 173 | Namespace(c.ns). 174 | Resource("chaosexperiments"). 175 | VersionedParams(&listOpts, scheme.ParameterCodec). 176 | Timeout(timeout). 177 | Body(&opts). 178 | Do(ctx). 179 | Error() 180 | } 181 | 182 | // Patch applies the patch and returns the patched chaosExperiment. 183 | func (c *chaosExperiments) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.ChaosExperiment, err error) { 184 | result = &v1alpha1.ChaosExperiment{} 185 | err = c.client.Patch(pt). 186 | Namespace(c.ns). 187 | Resource("chaosexperiments"). 188 | Name(name). 189 | SubResource(subresources...). 190 | VersionedParams(&opts, scheme.ParameterCodec). 191 | Body(data). 192 | Do(ctx). 193 | Into(result) 194 | return 195 | } 196 | -------------------------------------------------------------------------------- /pkg/client/clientset/versioned/typed/litmuschaos/v1alpha1/chaosresult.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Code generated by client-gen. DO NOT EDIT. 18 | 19 | package v1alpha1 20 | 21 | import ( 22 | "context" 23 | "time" 24 | 25 | v1alpha1 "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" 26 | scheme "github.com/litmuschaos/chaos-operator/pkg/client/clientset/versioned/scheme" 27 | v1 "k8s.io/apimachinery/pkg/apis/meta/v1" 28 | types "k8s.io/apimachinery/pkg/types" 29 | watch "k8s.io/apimachinery/pkg/watch" 30 | rest "k8s.io/client-go/rest" 31 | ) 32 | 33 | // ChaosResultsGetter has a method to return a ChaosResultInterface. 34 | // A group's client should implement this interface. 35 | type ChaosResultsGetter interface { 36 | ChaosResults(namespace string) ChaosResultInterface 37 | } 38 | 39 | // ChaosResultInterface has methods to work with ChaosResult resources. 40 | type ChaosResultInterface interface { 41 | Create(ctx context.Context, chaosResult *v1alpha1.ChaosResult, opts v1.CreateOptions) (*v1alpha1.ChaosResult, error) 42 | Update(ctx context.Context, chaosResult *v1alpha1.ChaosResult, opts v1.UpdateOptions) (*v1alpha1.ChaosResult, error) 43 | UpdateStatus(ctx context.Context, chaosResult *v1alpha1.ChaosResult, opts v1.UpdateOptions) (*v1alpha1.ChaosResult, error) 44 | Delete(ctx context.Context, name string, opts v1.DeleteOptions) error 45 | DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error 46 | Get(ctx context.Context, name string, opts v1.GetOptions) (*v1alpha1.ChaosResult, error) 47 | List(ctx context.Context, opts v1.ListOptions) (*v1alpha1.ChaosResultList, error) 48 | Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) 49 | Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.ChaosResult, err error) 50 | ChaosResultExpansion 51 | } 52 | 53 | // chaosResults implements ChaosResultInterface 54 | type chaosResults struct { 55 | client rest.Interface 56 | ns string 57 | } 58 | 59 | // newChaosResults returns a ChaosResults 60 | func newChaosResults(c *LitmuschaosV1alpha1Client, namespace string) *chaosResults { 61 | return &chaosResults{ 62 | client: c.RESTClient(), 63 | ns: namespace, 64 | } 65 | } 66 | 67 | // Get takes name of the chaosResult, and returns the corresponding chaosResult object, and an error if there is any. 68 | func (c *chaosResults) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.ChaosResult, err error) { 69 | result = &v1alpha1.ChaosResult{} 70 | err = c.client.Get(). 71 | Namespace(c.ns). 72 | Resource("chaosresults"). 73 | Name(name). 74 | VersionedParams(&options, scheme.ParameterCodec). 75 | Do(ctx). 76 | Into(result) 77 | return 78 | } 79 | 80 | // List takes label and field selectors, and returns the list of ChaosResults that match those selectors. 81 | func (c *chaosResults) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.ChaosResultList, err error) { 82 | var timeout time.Duration 83 | if opts.TimeoutSeconds != nil { 84 | timeout = time.Duration(*opts.TimeoutSeconds) * time.Second 85 | } 86 | result = &v1alpha1.ChaosResultList{} 87 | err = c.client.Get(). 88 | Namespace(c.ns). 89 | Resource("chaosresults"). 90 | VersionedParams(&opts, scheme.ParameterCodec). 91 | Timeout(timeout). 92 | Do(ctx). 93 | Into(result) 94 | return 95 | } 96 | 97 | // Watch returns a watch.Interface that watches the requested chaosResults. 98 | func (c *chaosResults) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { 99 | var timeout time.Duration 100 | if opts.TimeoutSeconds != nil { 101 | timeout = time.Duration(*opts.TimeoutSeconds) * time.Second 102 | } 103 | opts.Watch = true 104 | return c.client.Get(). 105 | Namespace(c.ns). 106 | Resource("chaosresults"). 107 | VersionedParams(&opts, scheme.ParameterCodec). 108 | Timeout(timeout). 109 | Watch(ctx) 110 | } 111 | 112 | // Create takes the representation of a chaosResult and creates it. Returns the server's representation of the chaosResult, and an error, if there is any. 113 | func (c *chaosResults) Create(ctx context.Context, chaosResult *v1alpha1.ChaosResult, opts v1.CreateOptions) (result *v1alpha1.ChaosResult, err error) { 114 | result = &v1alpha1.ChaosResult{} 115 | err = c.client.Post(). 116 | Namespace(c.ns). 117 | Resource("chaosresults"). 118 | VersionedParams(&opts, scheme.ParameterCodec). 119 | Body(chaosResult). 120 | Do(ctx). 121 | Into(result) 122 | return 123 | } 124 | 125 | // Update takes the representation of a chaosResult and updates it. Returns the server's representation of the chaosResult, and an error, if there is any. 126 | func (c *chaosResults) Update(ctx context.Context, chaosResult *v1alpha1.ChaosResult, opts v1.UpdateOptions) (result *v1alpha1.ChaosResult, err error) { 127 | result = &v1alpha1.ChaosResult{} 128 | err = c.client.Put(). 129 | Namespace(c.ns). 130 | Resource("chaosresults"). 131 | Name(chaosResult.Name). 132 | VersionedParams(&opts, scheme.ParameterCodec). 133 | Body(chaosResult). 134 | Do(ctx). 135 | Into(result) 136 | return 137 | } 138 | 139 | // UpdateStatus was generated because the type contains a Status member. 140 | // Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). 141 | func (c *chaosResults) UpdateStatus(ctx context.Context, chaosResult *v1alpha1.ChaosResult, opts v1.UpdateOptions) (result *v1alpha1.ChaosResult, err error) { 142 | result = &v1alpha1.ChaosResult{} 143 | err = c.client.Put(). 144 | Namespace(c.ns). 145 | Resource("chaosresults"). 146 | Name(chaosResult.Name). 147 | SubResource("status"). 148 | VersionedParams(&opts, scheme.ParameterCodec). 149 | Body(chaosResult). 150 | Do(ctx). 151 | Into(result) 152 | return 153 | } 154 | 155 | // Delete takes name of the chaosResult and deletes it. Returns an error if one occurs. 156 | func (c *chaosResults) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { 157 | return c.client.Delete(). 158 | Namespace(c.ns). 159 | Resource("chaosresults"). 160 | Name(name). 161 | Body(&opts). 162 | Do(ctx). 163 | Error() 164 | } 165 | 166 | // DeleteCollection deletes a collection of objects. 167 | func (c *chaosResults) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { 168 | var timeout time.Duration 169 | if listOpts.TimeoutSeconds != nil { 170 | timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second 171 | } 172 | return c.client.Delete(). 173 | Namespace(c.ns). 174 | Resource("chaosresults"). 175 | VersionedParams(&listOpts, scheme.ParameterCodec). 176 | Timeout(timeout). 177 | Body(&opts). 178 | Do(ctx). 179 | Error() 180 | } 181 | 182 | // Patch applies the patch and returns the patched chaosResult. 183 | func (c *chaosResults) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.ChaosResult, err error) { 184 | result = &v1alpha1.ChaosResult{} 185 | err = c.client.Patch(pt). 186 | Namespace(c.ns). 187 | Resource("chaosresults"). 188 | Name(name). 189 | SubResource(subresources...). 190 | VersionedParams(&opts, scheme.ParameterCodec). 191 | Body(data). 192 | Do(ctx). 193 | Into(result) 194 | return 195 | } 196 | -------------------------------------------------------------------------------- /pkg/client/clientset/versioned/typed/litmuschaos/v1alpha1/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Code generated by client-gen. DO NOT EDIT. 18 | 19 | // This package has the automatically generated typed clients. 20 | package v1alpha1 21 | -------------------------------------------------------------------------------- /pkg/client/clientset/versioned/typed/litmuschaos/v1alpha1/fake/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Code generated by client-gen. DO NOT EDIT. 18 | 19 | // Package fake has the automatically generated clients. 20 | package fake 21 | -------------------------------------------------------------------------------- /pkg/client/clientset/versioned/typed/litmuschaos/v1alpha1/fake/fake_chaosengine.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Code generated by client-gen. DO NOT EDIT. 18 | 19 | package fake 20 | 21 | import ( 22 | "context" 23 | 24 | v1alpha1 "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" 25 | v1 "k8s.io/apimachinery/pkg/apis/meta/v1" 26 | labels "k8s.io/apimachinery/pkg/labels" 27 | schema "k8s.io/apimachinery/pkg/runtime/schema" 28 | types "k8s.io/apimachinery/pkg/types" 29 | watch "k8s.io/apimachinery/pkg/watch" 30 | testing "k8s.io/client-go/testing" 31 | ) 32 | 33 | // FakeChaosEngines implements ChaosEngineInterface 34 | type FakeChaosEngines struct { 35 | Fake *FakeLitmuschaosV1alpha1 36 | ns string 37 | } 38 | 39 | var chaosenginesResource = schema.GroupVersionResource{Group: "litmuschaos.io", Version: "v1alpha1", Resource: "chaosengines"} 40 | 41 | var chaosenginesKind = schema.GroupVersionKind{Group: "litmuschaos.io", Version: "v1alpha1", Kind: "ChaosEngine"} 42 | 43 | // Get takes name of the chaosEngine, and returns the corresponding chaosEngine object, and an error if there is any. 44 | func (c *FakeChaosEngines) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.ChaosEngine, err error) { 45 | obj, err := c.Fake. 46 | Invokes(testing.NewGetAction(chaosenginesResource, c.ns, name), &v1alpha1.ChaosEngine{}) 47 | 48 | if obj == nil { 49 | return nil, err 50 | } 51 | return obj.(*v1alpha1.ChaosEngine), err 52 | } 53 | 54 | // List takes label and field selectors, and returns the list of ChaosEngines that match those selectors. 55 | func (c *FakeChaosEngines) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.ChaosEngineList, err error) { 56 | obj, err := c.Fake. 57 | Invokes(testing.NewListAction(chaosenginesResource, chaosenginesKind, c.ns, opts), &v1alpha1.ChaosEngineList{}) 58 | 59 | if obj == nil { 60 | return nil, err 61 | } 62 | 63 | label, _, _ := testing.ExtractFromListOptions(opts) 64 | if label == nil { 65 | label = labels.Everything() 66 | } 67 | list := &v1alpha1.ChaosEngineList{ListMeta: obj.(*v1alpha1.ChaosEngineList).ListMeta} 68 | for _, item := range obj.(*v1alpha1.ChaosEngineList).Items { 69 | if label.Matches(labels.Set(item.Labels)) { 70 | list.Items = append(list.Items, item) 71 | } 72 | } 73 | return list, err 74 | } 75 | 76 | // Watch returns a watch.Interface that watches the requested chaosEngines. 77 | func (c *FakeChaosEngines) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { 78 | return c.Fake. 79 | InvokesWatch(testing.NewWatchAction(chaosenginesResource, c.ns, opts)) 80 | 81 | } 82 | 83 | // Create takes the representation of a chaosEngine and creates it. Returns the server's representation of the chaosEngine, and an error, if there is any. 84 | func (c *FakeChaosEngines) Create(ctx context.Context, chaosEngine *v1alpha1.ChaosEngine, opts v1.CreateOptions) (result *v1alpha1.ChaosEngine, err error) { 85 | obj, err := c.Fake. 86 | Invokes(testing.NewCreateAction(chaosenginesResource, c.ns, chaosEngine), &v1alpha1.ChaosEngine{}) 87 | 88 | if obj == nil { 89 | return nil, err 90 | } 91 | return obj.(*v1alpha1.ChaosEngine), err 92 | } 93 | 94 | // Update takes the representation of a chaosEngine and updates it. Returns the server's representation of the chaosEngine, and an error, if there is any. 95 | func (c *FakeChaosEngines) Update(ctx context.Context, chaosEngine *v1alpha1.ChaosEngine, opts v1.UpdateOptions) (result *v1alpha1.ChaosEngine, err error) { 96 | obj, err := c.Fake. 97 | Invokes(testing.NewUpdateAction(chaosenginesResource, c.ns, chaosEngine), &v1alpha1.ChaosEngine{}) 98 | 99 | if obj == nil { 100 | return nil, err 101 | } 102 | return obj.(*v1alpha1.ChaosEngine), err 103 | } 104 | 105 | // UpdateStatus was generated because the type contains a Status member. 106 | // Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). 107 | func (c *FakeChaosEngines) UpdateStatus(ctx context.Context, chaosEngine *v1alpha1.ChaosEngine, opts v1.UpdateOptions) (*v1alpha1.ChaosEngine, error) { 108 | obj, err := c.Fake. 109 | Invokes(testing.NewUpdateSubresourceAction(chaosenginesResource, "status", c.ns, chaosEngine), &v1alpha1.ChaosEngine{}) 110 | 111 | if obj == nil { 112 | return nil, err 113 | } 114 | return obj.(*v1alpha1.ChaosEngine), err 115 | } 116 | 117 | // Delete takes name of the chaosEngine and deletes it. Returns an error if one occurs. 118 | func (c *FakeChaosEngines) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { 119 | _, err := c.Fake. 120 | Invokes(testing.NewDeleteAction(chaosenginesResource, c.ns, name), &v1alpha1.ChaosEngine{}) 121 | 122 | return err 123 | } 124 | 125 | // DeleteCollection deletes a collection of objects. 126 | func (c *FakeChaosEngines) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { 127 | action := testing.NewDeleteCollectionAction(chaosenginesResource, c.ns, listOpts) 128 | 129 | _, err := c.Fake.Invokes(action, &v1alpha1.ChaosEngineList{}) 130 | return err 131 | } 132 | 133 | // Patch applies the patch and returns the patched chaosEngine. 134 | func (c *FakeChaosEngines) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.ChaosEngine, err error) { 135 | obj, err := c.Fake. 136 | Invokes(testing.NewPatchSubresourceAction(chaosenginesResource, c.ns, name, pt, data, subresources...), &v1alpha1.ChaosEngine{}) 137 | 138 | if obj == nil { 139 | return nil, err 140 | } 141 | return obj.(*v1alpha1.ChaosEngine), err 142 | } 143 | -------------------------------------------------------------------------------- /pkg/client/clientset/versioned/typed/litmuschaos/v1alpha1/fake/fake_chaosexperiment.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Code generated by client-gen. DO NOT EDIT. 18 | 19 | package fake 20 | 21 | import ( 22 | "context" 23 | 24 | v1alpha1 "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" 25 | v1 "k8s.io/apimachinery/pkg/apis/meta/v1" 26 | labels "k8s.io/apimachinery/pkg/labels" 27 | schema "k8s.io/apimachinery/pkg/runtime/schema" 28 | types "k8s.io/apimachinery/pkg/types" 29 | watch "k8s.io/apimachinery/pkg/watch" 30 | testing "k8s.io/client-go/testing" 31 | ) 32 | 33 | // FakeChaosExperiments implements ChaosExperimentInterface 34 | type FakeChaosExperiments struct { 35 | Fake *FakeLitmuschaosV1alpha1 36 | ns string 37 | } 38 | 39 | var chaosexperimentsResource = schema.GroupVersionResource{Group: "litmuschaos.io", Version: "v1alpha1", Resource: "chaosexperiments"} 40 | 41 | var chaosexperimentsKind = schema.GroupVersionKind{Group: "litmuschaos.io", Version: "v1alpha1", Kind: "ChaosExperiment"} 42 | 43 | // Get takes name of the chaosExperiment, and returns the corresponding chaosExperiment object, and an error if there is any. 44 | func (c *FakeChaosExperiments) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.ChaosExperiment, err error) { 45 | obj, err := c.Fake. 46 | Invokes(testing.NewGetAction(chaosexperimentsResource, c.ns, name), &v1alpha1.ChaosExperiment{}) 47 | 48 | if obj == nil { 49 | return nil, err 50 | } 51 | return obj.(*v1alpha1.ChaosExperiment), err 52 | } 53 | 54 | // List takes label and field selectors, and returns the list of ChaosExperiments that match those selectors. 55 | func (c *FakeChaosExperiments) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.ChaosExperimentList, err error) { 56 | obj, err := c.Fake. 57 | Invokes(testing.NewListAction(chaosexperimentsResource, chaosexperimentsKind, c.ns, opts), &v1alpha1.ChaosExperimentList{}) 58 | 59 | if obj == nil { 60 | return nil, err 61 | } 62 | 63 | label, _, _ := testing.ExtractFromListOptions(opts) 64 | if label == nil { 65 | label = labels.Everything() 66 | } 67 | list := &v1alpha1.ChaosExperimentList{ListMeta: obj.(*v1alpha1.ChaosExperimentList).ListMeta} 68 | for _, item := range obj.(*v1alpha1.ChaosExperimentList).Items { 69 | if label.Matches(labels.Set(item.Labels)) { 70 | list.Items = append(list.Items, item) 71 | } 72 | } 73 | return list, err 74 | } 75 | 76 | // Watch returns a watch.Interface that watches the requested chaosExperiments. 77 | func (c *FakeChaosExperiments) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { 78 | return c.Fake. 79 | InvokesWatch(testing.NewWatchAction(chaosexperimentsResource, c.ns, opts)) 80 | 81 | } 82 | 83 | // Create takes the representation of a chaosExperiment and creates it. Returns the server's representation of the chaosExperiment, and an error, if there is any. 84 | func (c *FakeChaosExperiments) Create(ctx context.Context, chaosExperiment *v1alpha1.ChaosExperiment, opts v1.CreateOptions) (result *v1alpha1.ChaosExperiment, err error) { 85 | obj, err := c.Fake. 86 | Invokes(testing.NewCreateAction(chaosexperimentsResource, c.ns, chaosExperiment), &v1alpha1.ChaosExperiment{}) 87 | 88 | if obj == nil { 89 | return nil, err 90 | } 91 | return obj.(*v1alpha1.ChaosExperiment), err 92 | } 93 | 94 | // Update takes the representation of a chaosExperiment and updates it. Returns the server's representation of the chaosExperiment, and an error, if there is any. 95 | func (c *FakeChaosExperiments) Update(ctx context.Context, chaosExperiment *v1alpha1.ChaosExperiment, opts v1.UpdateOptions) (result *v1alpha1.ChaosExperiment, err error) { 96 | obj, err := c.Fake. 97 | Invokes(testing.NewUpdateAction(chaosexperimentsResource, c.ns, chaosExperiment), &v1alpha1.ChaosExperiment{}) 98 | 99 | if obj == nil { 100 | return nil, err 101 | } 102 | return obj.(*v1alpha1.ChaosExperiment), err 103 | } 104 | 105 | // UpdateStatus was generated because the type contains a Status member. 106 | // Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). 107 | func (c *FakeChaosExperiments) UpdateStatus(ctx context.Context, chaosExperiment *v1alpha1.ChaosExperiment, opts v1.UpdateOptions) (*v1alpha1.ChaosExperiment, error) { 108 | obj, err := c.Fake. 109 | Invokes(testing.NewUpdateSubresourceAction(chaosexperimentsResource, "status", c.ns, chaosExperiment), &v1alpha1.ChaosExperiment{}) 110 | 111 | if obj == nil { 112 | return nil, err 113 | } 114 | return obj.(*v1alpha1.ChaosExperiment), err 115 | } 116 | 117 | // Delete takes name of the chaosExperiment and deletes it. Returns an error if one occurs. 118 | func (c *FakeChaosExperiments) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { 119 | _, err := c.Fake. 120 | Invokes(testing.NewDeleteAction(chaosexperimentsResource, c.ns, name), &v1alpha1.ChaosExperiment{}) 121 | 122 | return err 123 | } 124 | 125 | // DeleteCollection deletes a collection of objects. 126 | func (c *FakeChaosExperiments) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { 127 | action := testing.NewDeleteCollectionAction(chaosexperimentsResource, c.ns, listOpts) 128 | 129 | _, err := c.Fake.Invokes(action, &v1alpha1.ChaosExperimentList{}) 130 | return err 131 | } 132 | 133 | // Patch applies the patch and returns the patched chaosExperiment. 134 | func (c *FakeChaosExperiments) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.ChaosExperiment, err error) { 135 | obj, err := c.Fake. 136 | Invokes(testing.NewPatchSubresourceAction(chaosexperimentsResource, c.ns, name, pt, data, subresources...), &v1alpha1.ChaosExperiment{}) 137 | 138 | if obj == nil { 139 | return nil, err 140 | } 141 | return obj.(*v1alpha1.ChaosExperiment), err 142 | } 143 | -------------------------------------------------------------------------------- /pkg/client/clientset/versioned/typed/litmuschaos/v1alpha1/fake/fake_chaosresult.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Code generated by client-gen. DO NOT EDIT. 18 | 19 | package fake 20 | 21 | import ( 22 | "context" 23 | 24 | v1alpha1 "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" 25 | v1 "k8s.io/apimachinery/pkg/apis/meta/v1" 26 | labels "k8s.io/apimachinery/pkg/labels" 27 | schema "k8s.io/apimachinery/pkg/runtime/schema" 28 | types "k8s.io/apimachinery/pkg/types" 29 | watch "k8s.io/apimachinery/pkg/watch" 30 | testing "k8s.io/client-go/testing" 31 | ) 32 | 33 | // FakeChaosResults implements ChaosResultInterface 34 | type FakeChaosResults struct { 35 | Fake *FakeLitmuschaosV1alpha1 36 | ns string 37 | } 38 | 39 | var chaosresultsResource = schema.GroupVersionResource{Group: "litmuschaos.io", Version: "v1alpha1", Resource: "chaosresults"} 40 | 41 | var chaosresultsKind = schema.GroupVersionKind{Group: "litmuschaos.io", Version: "v1alpha1", Kind: "ChaosResult"} 42 | 43 | // Get takes name of the chaosResult, and returns the corresponding chaosResult object, and an error if there is any. 44 | func (c *FakeChaosResults) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.ChaosResult, err error) { 45 | obj, err := c.Fake. 46 | Invokes(testing.NewGetAction(chaosresultsResource, c.ns, name), &v1alpha1.ChaosResult{}) 47 | 48 | if obj == nil { 49 | return nil, err 50 | } 51 | return obj.(*v1alpha1.ChaosResult), err 52 | } 53 | 54 | // List takes label and field selectors, and returns the list of ChaosResults that match those selectors. 55 | func (c *FakeChaosResults) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.ChaosResultList, err error) { 56 | obj, err := c.Fake. 57 | Invokes(testing.NewListAction(chaosresultsResource, chaosresultsKind, c.ns, opts), &v1alpha1.ChaosResultList{}) 58 | 59 | if obj == nil { 60 | return nil, err 61 | } 62 | 63 | label, _, _ := testing.ExtractFromListOptions(opts) 64 | if label == nil { 65 | label = labels.Everything() 66 | } 67 | list := &v1alpha1.ChaosResultList{ListMeta: obj.(*v1alpha1.ChaosResultList).ListMeta} 68 | for _, item := range obj.(*v1alpha1.ChaosResultList).Items { 69 | if label.Matches(labels.Set(item.Labels)) { 70 | list.Items = append(list.Items, item) 71 | } 72 | } 73 | return list, err 74 | } 75 | 76 | // Watch returns a watch.Interface that watches the requested chaosResults. 77 | func (c *FakeChaosResults) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { 78 | return c.Fake. 79 | InvokesWatch(testing.NewWatchAction(chaosresultsResource, c.ns, opts)) 80 | 81 | } 82 | 83 | // Create takes the representation of a chaosResult and creates it. Returns the server's representation of the chaosResult, and an error, if there is any. 84 | func (c *FakeChaosResults) Create(ctx context.Context, chaosResult *v1alpha1.ChaosResult, opts v1.CreateOptions) (result *v1alpha1.ChaosResult, err error) { 85 | obj, err := c.Fake. 86 | Invokes(testing.NewCreateAction(chaosresultsResource, c.ns, chaosResult), &v1alpha1.ChaosResult{}) 87 | 88 | if obj == nil { 89 | return nil, err 90 | } 91 | return obj.(*v1alpha1.ChaosResult), err 92 | } 93 | 94 | // Update takes the representation of a chaosResult and updates it. Returns the server's representation of the chaosResult, and an error, if there is any. 95 | func (c *FakeChaosResults) Update(ctx context.Context, chaosResult *v1alpha1.ChaosResult, opts v1.UpdateOptions) (result *v1alpha1.ChaosResult, err error) { 96 | obj, err := c.Fake. 97 | Invokes(testing.NewUpdateAction(chaosresultsResource, c.ns, chaosResult), &v1alpha1.ChaosResult{}) 98 | 99 | if obj == nil { 100 | return nil, err 101 | } 102 | return obj.(*v1alpha1.ChaosResult), err 103 | } 104 | 105 | // UpdateStatus was generated because the type contains a Status member. 106 | // Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). 107 | func (c *FakeChaosResults) UpdateStatus(ctx context.Context, chaosResult *v1alpha1.ChaosResult, opts v1.UpdateOptions) (*v1alpha1.ChaosResult, error) { 108 | obj, err := c.Fake. 109 | Invokes(testing.NewUpdateSubresourceAction(chaosresultsResource, "status", c.ns, chaosResult), &v1alpha1.ChaosResult{}) 110 | 111 | if obj == nil { 112 | return nil, err 113 | } 114 | return obj.(*v1alpha1.ChaosResult), err 115 | } 116 | 117 | // Delete takes name of the chaosResult and deletes it. Returns an error if one occurs. 118 | func (c *FakeChaosResults) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { 119 | _, err := c.Fake. 120 | Invokes(testing.NewDeleteAction(chaosresultsResource, c.ns, name), &v1alpha1.ChaosResult{}) 121 | 122 | return err 123 | } 124 | 125 | // DeleteCollection deletes a collection of objects. 126 | func (c *FakeChaosResults) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { 127 | action := testing.NewDeleteCollectionAction(chaosresultsResource, c.ns, listOpts) 128 | 129 | _, err := c.Fake.Invokes(action, &v1alpha1.ChaosResultList{}) 130 | return err 131 | } 132 | 133 | // Patch applies the patch and returns the patched chaosResult. 134 | func (c *FakeChaosResults) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.ChaosResult, err error) { 135 | obj, err := c.Fake. 136 | Invokes(testing.NewPatchSubresourceAction(chaosresultsResource, c.ns, name, pt, data, subresources...), &v1alpha1.ChaosResult{}) 137 | 138 | if obj == nil { 139 | return nil, err 140 | } 141 | return obj.(*v1alpha1.ChaosResult), err 142 | } 143 | -------------------------------------------------------------------------------- /pkg/client/clientset/versioned/typed/litmuschaos/v1alpha1/fake/fake_litmuschaos_client.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Code generated by client-gen. DO NOT EDIT. 18 | 19 | package fake 20 | 21 | import ( 22 | v1alpha1 "github.com/litmuschaos/chaos-operator/pkg/client/clientset/versioned/typed/litmuschaos/v1alpha1" 23 | rest "k8s.io/client-go/rest" 24 | testing "k8s.io/client-go/testing" 25 | ) 26 | 27 | type FakeLitmuschaosV1alpha1 struct { 28 | *testing.Fake 29 | } 30 | 31 | func (c *FakeLitmuschaosV1alpha1) ChaosEngines(namespace string) v1alpha1.ChaosEngineInterface { 32 | return &FakeChaosEngines{c, namespace} 33 | } 34 | 35 | func (c *FakeLitmuschaosV1alpha1) ChaosExperiments(namespace string) v1alpha1.ChaosExperimentInterface { 36 | return &FakeChaosExperiments{c, namespace} 37 | } 38 | 39 | func (c *FakeLitmuschaosV1alpha1) ChaosResults(namespace string) v1alpha1.ChaosResultInterface { 40 | return &FakeChaosResults{c, namespace} 41 | } 42 | 43 | // RESTClient returns a RESTClient that is used to communicate 44 | // with API server by this client implementation. 45 | func (c *FakeLitmuschaosV1alpha1) RESTClient() rest.Interface { 46 | var ret *rest.RESTClient 47 | return ret 48 | } 49 | -------------------------------------------------------------------------------- /pkg/client/clientset/versioned/typed/litmuschaos/v1alpha1/generated_expansion.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Code generated by client-gen. DO NOT EDIT. 18 | 19 | package v1alpha1 20 | 21 | type ChaosEngineExpansion interface{} 22 | 23 | type ChaosExperimentExpansion interface{} 24 | 25 | type ChaosResultExpansion interface{} 26 | -------------------------------------------------------------------------------- /pkg/client/clientset/versioned/typed/litmuschaos/v1alpha1/litmuschaos_client.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Code generated by client-gen. DO NOT EDIT. 18 | 19 | package v1alpha1 20 | 21 | import ( 22 | v1alpha1 "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" 23 | "github.com/litmuschaos/chaos-operator/pkg/client/clientset/versioned/scheme" 24 | rest "k8s.io/client-go/rest" 25 | ) 26 | 27 | type LitmuschaosV1alpha1Interface interface { 28 | RESTClient() rest.Interface 29 | ChaosEnginesGetter 30 | ChaosExperimentsGetter 31 | ChaosResultsGetter 32 | } 33 | 34 | // LitmuschaosV1alpha1Client is used to interact with features provided by the litmuschaos group. 35 | type LitmuschaosV1alpha1Client struct { 36 | restClient rest.Interface 37 | } 38 | 39 | func (c *LitmuschaosV1alpha1Client) ChaosEngines(namespace string) ChaosEngineInterface { 40 | return newChaosEngines(c, namespace) 41 | } 42 | 43 | func (c *LitmuschaosV1alpha1Client) ChaosExperiments(namespace string) ChaosExperimentInterface { 44 | return newChaosExperiments(c, namespace) 45 | } 46 | 47 | func (c *LitmuschaosV1alpha1Client) ChaosResults(namespace string) ChaosResultInterface { 48 | return newChaosResults(c, namespace) 49 | } 50 | 51 | // NewForConfig creates a new LitmuschaosV1alpha1Client for the given config. 52 | func NewForConfig(c *rest.Config) (*LitmuschaosV1alpha1Client, error) { 53 | config := *c 54 | if err := setConfigDefaults(&config); err != nil { 55 | return nil, err 56 | } 57 | client, err := rest.RESTClientFor(&config) 58 | if err != nil { 59 | return nil, err 60 | } 61 | return &LitmuschaosV1alpha1Client{client}, nil 62 | } 63 | 64 | // NewForConfigOrDie creates a new LitmuschaosV1alpha1Client for the given config and 65 | // panics if there is an error in the config. 66 | func NewForConfigOrDie(c *rest.Config) *LitmuschaosV1alpha1Client { 67 | client, err := NewForConfig(c) 68 | if err != nil { 69 | panic(err) 70 | } 71 | return client 72 | } 73 | 74 | // New creates a new LitmuschaosV1alpha1Client for the given RESTClient. 75 | func New(c rest.Interface) *LitmuschaosV1alpha1Client { 76 | return &LitmuschaosV1alpha1Client{c} 77 | } 78 | 79 | func setConfigDefaults(config *rest.Config) error { 80 | gv := v1alpha1.SchemeGroupVersion 81 | config.GroupVersion = &gv 82 | config.APIPath = "/apis" 83 | config.NegotiatedSerializer = scheme.Codecs.WithoutConversion() 84 | 85 | if config.UserAgent == "" { 86 | config.UserAgent = rest.DefaultKubernetesUserAgent() 87 | } 88 | 89 | return nil 90 | } 91 | 92 | // RESTClient returns a RESTClient that is used to communicate 93 | // with API server by this client implementation. 94 | func (c *LitmuschaosV1alpha1Client) RESTClient() rest.Interface { 95 | if c == nil { 96 | return nil 97 | } 98 | return c.restClient 99 | } 100 | -------------------------------------------------------------------------------- /pkg/client/dynamic/dynamic.go: -------------------------------------------------------------------------------- 1 | package dynamic 2 | 3 | import ( 4 | "k8s.io/client-go/dynamic" 5 | "sigs.k8s.io/controller-runtime/pkg/client/config" 6 | ) 7 | 8 | // CreateClientSet returns a Dynamic Kubernetes ClientSet 9 | func CreateClientSet() (dynamic.Interface, error) { 10 | restConfig, err := config.GetConfig() 11 | if err != nil { 12 | return nil, err 13 | } 14 | clientSet, err := dynamic.NewForConfig(restConfig) 15 | if err != nil { 16 | return nil, err 17 | } 18 | return clientSet, nil 19 | } 20 | -------------------------------------------------------------------------------- /pkg/client/informers/externalversions/factory.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Code generated by informer-gen. DO NOT EDIT. 18 | 19 | package externalversions 20 | 21 | import ( 22 | reflect "reflect" 23 | sync "sync" 24 | time "time" 25 | 26 | versioned "github.com/litmuschaos/chaos-operator/pkg/client/clientset/versioned" 27 | internalinterfaces "github.com/litmuschaos/chaos-operator/pkg/client/informers/externalversions/internalinterfaces" 28 | litmuschaos "github.com/litmuschaos/chaos-operator/pkg/client/informers/externalversions/litmuschaos" 29 | v1 "k8s.io/apimachinery/pkg/apis/meta/v1" 30 | runtime "k8s.io/apimachinery/pkg/runtime" 31 | schema "k8s.io/apimachinery/pkg/runtime/schema" 32 | cache "k8s.io/client-go/tools/cache" 33 | ) 34 | 35 | // SharedInformerOption defines the functional option type for SharedInformerFactory. 36 | type SharedInformerOption func(*sharedInformerFactory) *sharedInformerFactory 37 | 38 | type sharedInformerFactory struct { 39 | client versioned.Interface 40 | namespace string 41 | tweakListOptions internalinterfaces.TweakListOptionsFunc 42 | lock sync.Mutex 43 | defaultResync time.Duration 44 | customResync map[reflect.Type]time.Duration 45 | 46 | informers map[reflect.Type]cache.SharedIndexInformer 47 | // startedInformers is used for tracking which informers have been started. 48 | // This allows Start() to be called multiple times safely. 49 | startedInformers map[reflect.Type]bool 50 | } 51 | 52 | // WithCustomResyncConfig sets a custom resync period for the specified informer types. 53 | func WithCustomResyncConfig(resyncConfig map[v1.Object]time.Duration) SharedInformerOption { 54 | return func(factory *sharedInformerFactory) *sharedInformerFactory { 55 | for k, v := range resyncConfig { 56 | factory.customResync[reflect.TypeOf(k)] = v 57 | } 58 | return factory 59 | } 60 | } 61 | 62 | // WithTweakListOptions sets a custom filter on all listers of the configured SharedInformerFactory. 63 | func WithTweakListOptions(tweakListOptions internalinterfaces.TweakListOptionsFunc) SharedInformerOption { 64 | return func(factory *sharedInformerFactory) *sharedInformerFactory { 65 | factory.tweakListOptions = tweakListOptions 66 | return factory 67 | } 68 | } 69 | 70 | // WithNamespace limits the SharedInformerFactory to the specified namespace. 71 | func WithNamespace(namespace string) SharedInformerOption { 72 | return func(factory *sharedInformerFactory) *sharedInformerFactory { 73 | factory.namespace = namespace 74 | return factory 75 | } 76 | } 77 | 78 | // NewSharedInformerFactory constructs a new instance of sharedInformerFactory for all namespaces. 79 | func NewSharedInformerFactory(client versioned.Interface, defaultResync time.Duration) SharedInformerFactory { 80 | return NewSharedInformerFactoryWithOptions(client, defaultResync) 81 | } 82 | 83 | // NewFilteredSharedInformerFactory constructs a new instance of sharedInformerFactory. 84 | // Listers obtained via this SharedInformerFactory will be subject to the same filters 85 | // as specified here. 86 | // Deprecated: Please use NewSharedInformerFactoryWithOptions instead 87 | func NewFilteredSharedInformerFactory(client versioned.Interface, defaultResync time.Duration, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) SharedInformerFactory { 88 | return NewSharedInformerFactoryWithOptions(client, defaultResync, WithNamespace(namespace), WithTweakListOptions(tweakListOptions)) 89 | } 90 | 91 | // NewSharedInformerFactoryWithOptions constructs a new instance of a SharedInformerFactory with additional options. 92 | func NewSharedInformerFactoryWithOptions(client versioned.Interface, defaultResync time.Duration, options ...SharedInformerOption) SharedInformerFactory { 93 | factory := &sharedInformerFactory{ 94 | client: client, 95 | namespace: v1.NamespaceAll, 96 | defaultResync: defaultResync, 97 | informers: make(map[reflect.Type]cache.SharedIndexInformer), 98 | startedInformers: make(map[reflect.Type]bool), 99 | customResync: make(map[reflect.Type]time.Duration), 100 | } 101 | 102 | // Apply all options 103 | for _, opt := range options { 104 | factory = opt(factory) 105 | } 106 | 107 | return factory 108 | } 109 | 110 | // Start initializes all requested informers. 111 | func (f *sharedInformerFactory) Start(stopCh <-chan struct{}) { 112 | f.lock.Lock() 113 | defer f.lock.Unlock() 114 | 115 | for informerType, informer := range f.informers { 116 | if !f.startedInformers[informerType] { 117 | go informer.Run(stopCh) 118 | f.startedInformers[informerType] = true 119 | } 120 | } 121 | } 122 | 123 | // WaitForCacheSync waits for all started informers' cache were synced. 124 | func (f *sharedInformerFactory) WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool { 125 | informers := func() map[reflect.Type]cache.SharedIndexInformer { 126 | f.lock.Lock() 127 | defer f.lock.Unlock() 128 | 129 | informers := map[reflect.Type]cache.SharedIndexInformer{} 130 | for informerType, informer := range f.informers { 131 | if f.startedInformers[informerType] { 132 | informers[informerType] = informer 133 | } 134 | } 135 | return informers 136 | }() 137 | 138 | res := map[reflect.Type]bool{} 139 | for informType, informer := range informers { 140 | res[informType] = cache.WaitForCacheSync(stopCh, informer.HasSynced) 141 | } 142 | return res 143 | } 144 | 145 | // InternalInformerFor returns the SharedIndexInformer for obj using an internal 146 | // client. 147 | func (f *sharedInformerFactory) InformerFor(obj runtime.Object, newFunc internalinterfaces.NewInformerFunc) cache.SharedIndexInformer { 148 | f.lock.Lock() 149 | defer f.lock.Unlock() 150 | 151 | informerType := reflect.TypeOf(obj) 152 | informer, exists := f.informers[informerType] 153 | if exists { 154 | return informer 155 | } 156 | 157 | resyncPeriod, exists := f.customResync[informerType] 158 | if !exists { 159 | resyncPeriod = f.defaultResync 160 | } 161 | 162 | informer = newFunc(f.client, resyncPeriod) 163 | f.informers[informerType] = informer 164 | 165 | return informer 166 | } 167 | 168 | // SharedInformerFactory provides shared informers for resources in all known 169 | // API group versions. 170 | type SharedInformerFactory interface { 171 | internalinterfaces.SharedInformerFactory 172 | ForResource(resource schema.GroupVersionResource) (GenericInformer, error) 173 | WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool 174 | 175 | Litmuschaos() litmuschaos.Interface 176 | } 177 | 178 | func (f *sharedInformerFactory) Litmuschaos() litmuschaos.Interface { 179 | return litmuschaos.New(f, f.namespace, f.tweakListOptions) 180 | } 181 | -------------------------------------------------------------------------------- /pkg/client/informers/externalversions/generic.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Code generated by informer-gen. DO NOT EDIT. 18 | 19 | package externalversions 20 | 21 | import ( 22 | "fmt" 23 | 24 | v1alpha1 "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" 25 | schema "k8s.io/apimachinery/pkg/runtime/schema" 26 | cache "k8s.io/client-go/tools/cache" 27 | ) 28 | 29 | // GenericInformer is type of SharedIndexInformer which will locate and delegate to other 30 | // sharedInformers based on type 31 | type GenericInformer interface { 32 | Informer() cache.SharedIndexInformer 33 | Lister() cache.GenericLister 34 | } 35 | 36 | type genericInformer struct { 37 | informer cache.SharedIndexInformer 38 | resource schema.GroupResource 39 | } 40 | 41 | // Informer returns the SharedIndexInformer. 42 | func (f *genericInformer) Informer() cache.SharedIndexInformer { 43 | return f.informer 44 | } 45 | 46 | // Lister returns the GenericLister. 47 | func (f *genericInformer) Lister() cache.GenericLister { 48 | return cache.NewGenericLister(f.Informer().GetIndexer(), f.resource) 49 | } 50 | 51 | // ForResource gives generic access to a shared informer of the matching type 52 | // TODO extend this to unknown resources with a client pool 53 | func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource) (GenericInformer, error) { 54 | switch resource { 55 | // Group=litmuschaos, Version=v1alpha1 56 | case v1alpha1.SchemeGroupVersion.WithResource("chaosengines"): 57 | return &genericInformer{resource: resource.GroupResource(), informer: f.Litmuschaos().V1alpha1().ChaosEngines().Informer()}, nil 58 | case v1alpha1.SchemeGroupVersion.WithResource("chaosexperiments"): 59 | return &genericInformer{resource: resource.GroupResource(), informer: f.Litmuschaos().V1alpha1().ChaosExperiments().Informer()}, nil 60 | case v1alpha1.SchemeGroupVersion.WithResource("chaosresults"): 61 | return &genericInformer{resource: resource.GroupResource(), informer: f.Litmuschaos().V1alpha1().ChaosResults().Informer()}, nil 62 | 63 | } 64 | 65 | return nil, fmt.Errorf("no informer found for %v", resource) 66 | } 67 | -------------------------------------------------------------------------------- /pkg/client/informers/externalversions/internalinterfaces/factory_interfaces.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Code generated by informer-gen. DO NOT EDIT. 18 | 19 | package internalinterfaces 20 | 21 | import ( 22 | time "time" 23 | 24 | versioned "github.com/litmuschaos/chaos-operator/pkg/client/clientset/versioned" 25 | v1 "k8s.io/apimachinery/pkg/apis/meta/v1" 26 | runtime "k8s.io/apimachinery/pkg/runtime" 27 | cache "k8s.io/client-go/tools/cache" 28 | ) 29 | 30 | // NewInformerFunc takes versioned.Interface and time.Duration to return a SharedIndexInformer. 31 | type NewInformerFunc func(versioned.Interface, time.Duration) cache.SharedIndexInformer 32 | 33 | // SharedInformerFactory a small interface to allow for adding an informer without an import cycle 34 | type SharedInformerFactory interface { 35 | Start(stopCh <-chan struct{}) 36 | InformerFor(obj runtime.Object, newFunc NewInformerFunc) cache.SharedIndexInformer 37 | } 38 | 39 | // TweakListOptionsFunc is a function that transforms a v1.ListOptions. 40 | type TweakListOptionsFunc func(*v1.ListOptions) 41 | -------------------------------------------------------------------------------- /pkg/client/informers/externalversions/litmuschaos/interface.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Code generated by informer-gen. DO NOT EDIT. 18 | 19 | package litmuschaos 20 | 21 | import ( 22 | internalinterfaces "github.com/litmuschaos/chaos-operator/pkg/client/informers/externalversions/internalinterfaces" 23 | v1alpha1 "github.com/litmuschaos/chaos-operator/pkg/client/informers/externalversions/litmuschaos/v1alpha1" 24 | ) 25 | 26 | // Interface provides access to each of this group's versions. 27 | type Interface interface { 28 | // V1alpha1 provides access to shared informers for resources in V1alpha1. 29 | V1alpha1() v1alpha1.Interface 30 | } 31 | 32 | type group struct { 33 | factory internalinterfaces.SharedInformerFactory 34 | namespace string 35 | tweakListOptions internalinterfaces.TweakListOptionsFunc 36 | } 37 | 38 | // New returns a new Interface. 39 | func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { 40 | return &group{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} 41 | } 42 | 43 | // V1alpha1 returns a new v1alpha1.Interface. 44 | func (g *group) V1alpha1() v1alpha1.Interface { 45 | return v1alpha1.New(g.factory, g.namespace, g.tweakListOptions) 46 | } 47 | -------------------------------------------------------------------------------- /pkg/client/informers/externalversions/litmuschaos/v1alpha1/chaosengine.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Code generated by informer-gen. DO NOT EDIT. 18 | 19 | package v1alpha1 20 | 21 | import ( 22 | "context" 23 | time "time" 24 | 25 | litmuschaosv1alpha1 "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" 26 | versioned "github.com/litmuschaos/chaos-operator/pkg/client/clientset/versioned" 27 | internalinterfaces "github.com/litmuschaos/chaos-operator/pkg/client/informers/externalversions/internalinterfaces" 28 | v1alpha1 "github.com/litmuschaos/chaos-operator/pkg/client/listers/litmuschaos/v1alpha1" 29 | v1 "k8s.io/apimachinery/pkg/apis/meta/v1" 30 | runtime "k8s.io/apimachinery/pkg/runtime" 31 | watch "k8s.io/apimachinery/pkg/watch" 32 | cache "k8s.io/client-go/tools/cache" 33 | ) 34 | 35 | // ChaosEngineInformer provides access to a shared informer and lister for 36 | // ChaosEngines. 37 | type ChaosEngineInformer interface { 38 | Informer() cache.SharedIndexInformer 39 | Lister() v1alpha1.ChaosEngineLister 40 | } 41 | 42 | type chaosEngineInformer struct { 43 | factory internalinterfaces.SharedInformerFactory 44 | tweakListOptions internalinterfaces.TweakListOptionsFunc 45 | namespace string 46 | } 47 | 48 | // NewChaosEngineInformer constructs a new informer for ChaosEngine type. 49 | // Always prefer using an informer factory to get a shared informer instead of getting an independent 50 | // one. This reduces memory footprint and number of connections to the server. 51 | func NewChaosEngineInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { 52 | return NewFilteredChaosEngineInformer(client, namespace, resyncPeriod, indexers, nil) 53 | } 54 | 55 | // NewFilteredChaosEngineInformer constructs a new informer for ChaosEngine type. 56 | // Always prefer using an informer factory to get a shared informer instead of getting an independent 57 | // one. This reduces memory footprint and number of connections to the server. 58 | func NewFilteredChaosEngineInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { 59 | return cache.NewSharedIndexInformer( 60 | &cache.ListWatch{ 61 | ListFunc: func(options v1.ListOptions) (runtime.Object, error) { 62 | if tweakListOptions != nil { 63 | tweakListOptions(&options) 64 | } 65 | return client.LitmuschaosV1alpha1().ChaosEngines(namespace).List(context.TODO(), options) 66 | }, 67 | WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { 68 | if tweakListOptions != nil { 69 | tweakListOptions(&options) 70 | } 71 | return client.LitmuschaosV1alpha1().ChaosEngines(namespace).Watch(context.TODO(), options) 72 | }, 73 | }, 74 | &litmuschaosv1alpha1.ChaosEngine{}, 75 | resyncPeriod, 76 | indexers, 77 | ) 78 | } 79 | 80 | func (f *chaosEngineInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { 81 | return NewFilteredChaosEngineInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) 82 | } 83 | 84 | func (f *chaosEngineInformer) Informer() cache.SharedIndexInformer { 85 | return f.factory.InformerFor(&litmuschaosv1alpha1.ChaosEngine{}, f.defaultInformer) 86 | } 87 | 88 | func (f *chaosEngineInformer) Lister() v1alpha1.ChaosEngineLister { 89 | return v1alpha1.NewChaosEngineLister(f.Informer().GetIndexer()) 90 | } 91 | -------------------------------------------------------------------------------- /pkg/client/informers/externalversions/litmuschaos/v1alpha1/chaosexperiment.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Code generated by informer-gen. DO NOT EDIT. 18 | 19 | package v1alpha1 20 | 21 | import ( 22 | "context" 23 | time "time" 24 | 25 | litmuschaosv1alpha1 "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" 26 | versioned "github.com/litmuschaos/chaos-operator/pkg/client/clientset/versioned" 27 | internalinterfaces "github.com/litmuschaos/chaos-operator/pkg/client/informers/externalversions/internalinterfaces" 28 | v1alpha1 "github.com/litmuschaos/chaos-operator/pkg/client/listers/litmuschaos/v1alpha1" 29 | v1 "k8s.io/apimachinery/pkg/apis/meta/v1" 30 | runtime "k8s.io/apimachinery/pkg/runtime" 31 | watch "k8s.io/apimachinery/pkg/watch" 32 | cache "k8s.io/client-go/tools/cache" 33 | ) 34 | 35 | // ChaosExperimentInformer provides access to a shared informer and lister for 36 | // ChaosExperiments. 37 | type ChaosExperimentInformer interface { 38 | Informer() cache.SharedIndexInformer 39 | Lister() v1alpha1.ChaosExperimentLister 40 | } 41 | 42 | type chaosExperimentInformer struct { 43 | factory internalinterfaces.SharedInformerFactory 44 | tweakListOptions internalinterfaces.TweakListOptionsFunc 45 | namespace string 46 | } 47 | 48 | // NewChaosExperimentInformer constructs a new informer for ChaosExperiment type. 49 | // Always prefer using an informer factory to get a shared informer instead of getting an independent 50 | // one. This reduces memory footprint and number of connections to the server. 51 | func NewChaosExperimentInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { 52 | return NewFilteredChaosExperimentInformer(client, namespace, resyncPeriod, indexers, nil) 53 | } 54 | 55 | // NewFilteredChaosExperimentInformer constructs a new informer for ChaosExperiment type. 56 | // Always prefer using an informer factory to get a shared informer instead of getting an independent 57 | // one. This reduces memory footprint and number of connections to the server. 58 | func NewFilteredChaosExperimentInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { 59 | return cache.NewSharedIndexInformer( 60 | &cache.ListWatch{ 61 | ListFunc: func(options v1.ListOptions) (runtime.Object, error) { 62 | if tweakListOptions != nil { 63 | tweakListOptions(&options) 64 | } 65 | return client.LitmuschaosV1alpha1().ChaosExperiments(namespace).List(context.TODO(), options) 66 | }, 67 | WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { 68 | if tweakListOptions != nil { 69 | tweakListOptions(&options) 70 | } 71 | return client.LitmuschaosV1alpha1().ChaosExperiments(namespace).Watch(context.TODO(), options) 72 | }, 73 | }, 74 | &litmuschaosv1alpha1.ChaosExperiment{}, 75 | resyncPeriod, 76 | indexers, 77 | ) 78 | } 79 | 80 | func (f *chaosExperimentInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { 81 | return NewFilteredChaosExperimentInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) 82 | } 83 | 84 | func (f *chaosExperimentInformer) Informer() cache.SharedIndexInformer { 85 | return f.factory.InformerFor(&litmuschaosv1alpha1.ChaosExperiment{}, f.defaultInformer) 86 | } 87 | 88 | func (f *chaosExperimentInformer) Lister() v1alpha1.ChaosExperimentLister { 89 | return v1alpha1.NewChaosExperimentLister(f.Informer().GetIndexer()) 90 | } 91 | -------------------------------------------------------------------------------- /pkg/client/informers/externalversions/litmuschaos/v1alpha1/chaosresult.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Code generated by informer-gen. DO NOT EDIT. 18 | 19 | package v1alpha1 20 | 21 | import ( 22 | "context" 23 | time "time" 24 | 25 | litmuschaosv1alpha1 "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" 26 | versioned "github.com/litmuschaos/chaos-operator/pkg/client/clientset/versioned" 27 | internalinterfaces "github.com/litmuschaos/chaos-operator/pkg/client/informers/externalversions/internalinterfaces" 28 | v1alpha1 "github.com/litmuschaos/chaos-operator/pkg/client/listers/litmuschaos/v1alpha1" 29 | v1 "k8s.io/apimachinery/pkg/apis/meta/v1" 30 | runtime "k8s.io/apimachinery/pkg/runtime" 31 | watch "k8s.io/apimachinery/pkg/watch" 32 | cache "k8s.io/client-go/tools/cache" 33 | ) 34 | 35 | // ChaosResultInformer provides access to a shared informer and lister for 36 | // ChaosResults. 37 | type ChaosResultInformer interface { 38 | Informer() cache.SharedIndexInformer 39 | Lister() v1alpha1.ChaosResultLister 40 | } 41 | 42 | type chaosResultInformer struct { 43 | factory internalinterfaces.SharedInformerFactory 44 | tweakListOptions internalinterfaces.TweakListOptionsFunc 45 | namespace string 46 | } 47 | 48 | // NewChaosResultInformer constructs a new informer for ChaosResult type. 49 | // Always prefer using an informer factory to get a shared informer instead of getting an independent 50 | // one. This reduces memory footprint and number of connections to the server. 51 | func NewChaosResultInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { 52 | return NewFilteredChaosResultInformer(client, namespace, resyncPeriod, indexers, nil) 53 | } 54 | 55 | // NewFilteredChaosResultInformer constructs a new informer for ChaosResult type. 56 | // Always prefer using an informer factory to get a shared informer instead of getting an independent 57 | // one. This reduces memory footprint and number of connections to the server. 58 | func NewFilteredChaosResultInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { 59 | return cache.NewSharedIndexInformer( 60 | &cache.ListWatch{ 61 | ListFunc: func(options v1.ListOptions) (runtime.Object, error) { 62 | if tweakListOptions != nil { 63 | tweakListOptions(&options) 64 | } 65 | return client.LitmuschaosV1alpha1().ChaosResults(namespace).List(context.TODO(), options) 66 | }, 67 | WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { 68 | if tweakListOptions != nil { 69 | tweakListOptions(&options) 70 | } 71 | return client.LitmuschaosV1alpha1().ChaosResults(namespace).Watch(context.TODO(), options) 72 | }, 73 | }, 74 | &litmuschaosv1alpha1.ChaosResult{}, 75 | resyncPeriod, 76 | indexers, 77 | ) 78 | } 79 | 80 | func (f *chaosResultInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { 81 | return NewFilteredChaosResultInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) 82 | } 83 | 84 | func (f *chaosResultInformer) Informer() cache.SharedIndexInformer { 85 | return f.factory.InformerFor(&litmuschaosv1alpha1.ChaosResult{}, f.defaultInformer) 86 | } 87 | 88 | func (f *chaosResultInformer) Lister() v1alpha1.ChaosResultLister { 89 | return v1alpha1.NewChaosResultLister(f.Informer().GetIndexer()) 90 | } 91 | -------------------------------------------------------------------------------- /pkg/client/informers/externalversions/litmuschaos/v1alpha1/interface.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Code generated by informer-gen. DO NOT EDIT. 18 | 19 | package v1alpha1 20 | 21 | import ( 22 | internalinterfaces "github.com/litmuschaos/chaos-operator/pkg/client/informers/externalversions/internalinterfaces" 23 | ) 24 | 25 | // Interface provides access to all the informers in this group version. 26 | type Interface interface { 27 | // ChaosEngines returns a ChaosEngineInformer. 28 | ChaosEngines() ChaosEngineInformer 29 | // ChaosExperiments returns a ChaosExperimentInformer. 30 | ChaosExperiments() ChaosExperimentInformer 31 | // ChaosResults returns a ChaosResultInformer. 32 | ChaosResults() ChaosResultInformer 33 | } 34 | 35 | type version struct { 36 | factory internalinterfaces.SharedInformerFactory 37 | namespace string 38 | tweakListOptions internalinterfaces.TweakListOptionsFunc 39 | } 40 | 41 | // New returns a new Interface. 42 | func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { 43 | return &version{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} 44 | } 45 | 46 | // ChaosEngines returns a ChaosEngineInformer. 47 | func (v *version) ChaosEngines() ChaosEngineInformer { 48 | return &chaosEngineInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} 49 | } 50 | 51 | // ChaosExperiments returns a ChaosExperimentInformer. 52 | func (v *version) ChaosExperiments() ChaosExperimentInformer { 53 | return &chaosExperimentInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} 54 | } 55 | 56 | // ChaosResults returns a ChaosResultInformer. 57 | func (v *version) ChaosResults() ChaosResultInformer { 58 | return &chaosResultInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} 59 | } 60 | -------------------------------------------------------------------------------- /pkg/client/kubernetes/kubernetes.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 LitmusChaos Authors 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package kubernetes 18 | 19 | import ( 20 | "k8s.io/client-go/kubernetes" 21 | "sigs.k8s.io/controller-runtime/pkg/client/config" 22 | ) 23 | 24 | // CreateClientSet will generate the kubernetes clientset using config 25 | func CreateClientSet() (*kubernetes.Clientset, error) { 26 | restConfig, err := config.GetConfig() 27 | if err != nil { 28 | return &kubernetes.Clientset{}, err 29 | } 30 | clientSet, err := kubernetes.NewForConfig(restConfig) 31 | if err != nil { 32 | return &kubernetes.Clientset{}, err 33 | } 34 | return clientSet, nil 35 | } 36 | -------------------------------------------------------------------------------- /pkg/client/listers/litmuschaos/v1alpha1/chaosengine.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Code generated by lister-gen. DO NOT EDIT. 18 | 19 | package v1alpha1 20 | 21 | import ( 22 | v1alpha1 "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" 23 | "k8s.io/apimachinery/pkg/api/errors" 24 | "k8s.io/apimachinery/pkg/labels" 25 | "k8s.io/client-go/tools/cache" 26 | ) 27 | 28 | // ChaosEngineLister helps list ChaosEngines. 29 | // All objects returned here must be treated as read-only. 30 | type ChaosEngineLister interface { 31 | // List lists all ChaosEngines in the indexer. 32 | // Objects returned here must be treated as read-only. 33 | List(selector labels.Selector) (ret []*v1alpha1.ChaosEngine, err error) 34 | // ChaosEngines returns an object that can list and get ChaosEngines. 35 | ChaosEngines(namespace string) ChaosEngineNamespaceLister 36 | ChaosEngineListerExpansion 37 | } 38 | 39 | // chaosEngineLister implements the ChaosEngineLister interface. 40 | type chaosEngineLister struct { 41 | indexer cache.Indexer 42 | } 43 | 44 | // NewChaosEngineLister returns a new ChaosEngineLister. 45 | func NewChaosEngineLister(indexer cache.Indexer) ChaosEngineLister { 46 | return &chaosEngineLister{indexer: indexer} 47 | } 48 | 49 | // List lists all ChaosEngines in the indexer. 50 | func (s *chaosEngineLister) List(selector labels.Selector) (ret []*v1alpha1.ChaosEngine, err error) { 51 | err = cache.ListAll(s.indexer, selector, func(m interface{}) { 52 | ret = append(ret, m.(*v1alpha1.ChaosEngine)) 53 | }) 54 | return ret, err 55 | } 56 | 57 | // ChaosEngines returns an object that can list and get ChaosEngines. 58 | func (s *chaosEngineLister) ChaosEngines(namespace string) ChaosEngineNamespaceLister { 59 | return chaosEngineNamespaceLister{indexer: s.indexer, namespace: namespace} 60 | } 61 | 62 | // ChaosEngineNamespaceLister helps list and get ChaosEngines. 63 | // All objects returned here must be treated as read-only. 64 | type ChaosEngineNamespaceLister interface { 65 | // List lists all ChaosEngines in the indexer for a given namespace. 66 | // Objects returned here must be treated as read-only. 67 | List(selector labels.Selector) (ret []*v1alpha1.ChaosEngine, err error) 68 | // Get retrieves the ChaosEngine from the indexer for a given namespace and name. 69 | // Objects returned here must be treated as read-only. 70 | Get(name string) (*v1alpha1.ChaosEngine, error) 71 | ChaosEngineNamespaceListerExpansion 72 | } 73 | 74 | // chaosEngineNamespaceLister implements the ChaosEngineNamespaceLister 75 | // interface. 76 | type chaosEngineNamespaceLister struct { 77 | indexer cache.Indexer 78 | namespace string 79 | } 80 | 81 | // List lists all ChaosEngines in the indexer for a given namespace. 82 | func (s chaosEngineNamespaceLister) List(selector labels.Selector) (ret []*v1alpha1.ChaosEngine, err error) { 83 | err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { 84 | ret = append(ret, m.(*v1alpha1.ChaosEngine)) 85 | }) 86 | return ret, err 87 | } 88 | 89 | // Get retrieves the ChaosEngine from the indexer for a given namespace and name. 90 | func (s chaosEngineNamespaceLister) Get(name string) (*v1alpha1.ChaosEngine, error) { 91 | obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) 92 | if err != nil { 93 | return nil, err 94 | } 95 | if !exists { 96 | return nil, errors.NewNotFound(v1alpha1.Resource("chaosengine"), name) 97 | } 98 | return obj.(*v1alpha1.ChaosEngine), nil 99 | } 100 | -------------------------------------------------------------------------------- /pkg/client/listers/litmuschaos/v1alpha1/chaosexperiment.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Code generated by lister-gen. DO NOT EDIT. 18 | 19 | package v1alpha1 20 | 21 | import ( 22 | v1alpha1 "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" 23 | "k8s.io/apimachinery/pkg/api/errors" 24 | "k8s.io/apimachinery/pkg/labels" 25 | "k8s.io/client-go/tools/cache" 26 | ) 27 | 28 | // ChaosExperimentLister helps list ChaosExperiments. 29 | // All objects returned here must be treated as read-only. 30 | type ChaosExperimentLister interface { 31 | // List lists all ChaosExperiments in the indexer. 32 | // Objects returned here must be treated as read-only. 33 | List(selector labels.Selector) (ret []*v1alpha1.ChaosExperiment, err error) 34 | // ChaosExperiments returns an object that can list and get ChaosExperiments. 35 | ChaosExperiments(namespace string) ChaosExperimentNamespaceLister 36 | ChaosExperimentListerExpansion 37 | } 38 | 39 | // chaosExperimentLister implements the ChaosExperimentLister interface. 40 | type chaosExperimentLister struct { 41 | indexer cache.Indexer 42 | } 43 | 44 | // NewChaosExperimentLister returns a new ChaosExperimentLister. 45 | func NewChaosExperimentLister(indexer cache.Indexer) ChaosExperimentLister { 46 | return &chaosExperimentLister{indexer: indexer} 47 | } 48 | 49 | // List lists all ChaosExperiments in the indexer. 50 | func (s *chaosExperimentLister) List(selector labels.Selector) (ret []*v1alpha1.ChaosExperiment, err error) { 51 | err = cache.ListAll(s.indexer, selector, func(m interface{}) { 52 | ret = append(ret, m.(*v1alpha1.ChaosExperiment)) 53 | }) 54 | return ret, err 55 | } 56 | 57 | // ChaosExperiments returns an object that can list and get ChaosExperiments. 58 | func (s *chaosExperimentLister) ChaosExperiments(namespace string) ChaosExperimentNamespaceLister { 59 | return chaosExperimentNamespaceLister{indexer: s.indexer, namespace: namespace} 60 | } 61 | 62 | // ChaosExperimentNamespaceLister helps list and get ChaosExperiments. 63 | // All objects returned here must be treated as read-only. 64 | type ChaosExperimentNamespaceLister interface { 65 | // List lists all ChaosExperiments in the indexer for a given namespace. 66 | // Objects returned here must be treated as read-only. 67 | List(selector labels.Selector) (ret []*v1alpha1.ChaosExperiment, err error) 68 | // Get retrieves the ChaosExperiment from the indexer for a given namespace and name. 69 | // Objects returned here must be treated as read-only. 70 | Get(name string) (*v1alpha1.ChaosExperiment, error) 71 | ChaosExperimentNamespaceListerExpansion 72 | } 73 | 74 | // chaosExperimentNamespaceLister implements the ChaosExperimentNamespaceLister 75 | // interface. 76 | type chaosExperimentNamespaceLister struct { 77 | indexer cache.Indexer 78 | namespace string 79 | } 80 | 81 | // List lists all ChaosExperiments in the indexer for a given namespace. 82 | func (s chaosExperimentNamespaceLister) List(selector labels.Selector) (ret []*v1alpha1.ChaosExperiment, err error) { 83 | err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { 84 | ret = append(ret, m.(*v1alpha1.ChaosExperiment)) 85 | }) 86 | return ret, err 87 | } 88 | 89 | // Get retrieves the ChaosExperiment from the indexer for a given namespace and name. 90 | func (s chaosExperimentNamespaceLister) Get(name string) (*v1alpha1.ChaosExperiment, error) { 91 | obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) 92 | if err != nil { 93 | return nil, err 94 | } 95 | if !exists { 96 | return nil, errors.NewNotFound(v1alpha1.Resource("chaosexperiment"), name) 97 | } 98 | return obj.(*v1alpha1.ChaosExperiment), nil 99 | } 100 | -------------------------------------------------------------------------------- /pkg/client/listers/litmuschaos/v1alpha1/chaosresult.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Code generated by lister-gen. DO NOT EDIT. 18 | 19 | package v1alpha1 20 | 21 | import ( 22 | v1alpha1 "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" 23 | "k8s.io/apimachinery/pkg/api/errors" 24 | "k8s.io/apimachinery/pkg/labels" 25 | "k8s.io/client-go/tools/cache" 26 | ) 27 | 28 | // ChaosResultLister helps list ChaosResults. 29 | // All objects returned here must be treated as read-only. 30 | type ChaosResultLister interface { 31 | // List lists all ChaosResults in the indexer. 32 | // Objects returned here must be treated as read-only. 33 | List(selector labels.Selector) (ret []*v1alpha1.ChaosResult, err error) 34 | // ChaosResults returns an object that can list and get ChaosResults. 35 | ChaosResults(namespace string) ChaosResultNamespaceLister 36 | ChaosResultListerExpansion 37 | } 38 | 39 | // chaosResultLister implements the ChaosResultLister interface. 40 | type chaosResultLister struct { 41 | indexer cache.Indexer 42 | } 43 | 44 | // NewChaosResultLister returns a new ChaosResultLister. 45 | func NewChaosResultLister(indexer cache.Indexer) ChaosResultLister { 46 | return &chaosResultLister{indexer: indexer} 47 | } 48 | 49 | // List lists all ChaosResults in the indexer. 50 | func (s *chaosResultLister) List(selector labels.Selector) (ret []*v1alpha1.ChaosResult, err error) { 51 | err = cache.ListAll(s.indexer, selector, func(m interface{}) { 52 | ret = append(ret, m.(*v1alpha1.ChaosResult)) 53 | }) 54 | return ret, err 55 | } 56 | 57 | // ChaosResults returns an object that can list and get ChaosResults. 58 | func (s *chaosResultLister) ChaosResults(namespace string) ChaosResultNamespaceLister { 59 | return chaosResultNamespaceLister{indexer: s.indexer, namespace: namespace} 60 | } 61 | 62 | // ChaosResultNamespaceLister helps list and get ChaosResults. 63 | // All objects returned here must be treated as read-only. 64 | type ChaosResultNamespaceLister interface { 65 | // List lists all ChaosResults in the indexer for a given namespace. 66 | // Objects returned here must be treated as read-only. 67 | List(selector labels.Selector) (ret []*v1alpha1.ChaosResult, err error) 68 | // Get retrieves the ChaosResult from the indexer for a given namespace and name. 69 | // Objects returned here must be treated as read-only. 70 | Get(name string) (*v1alpha1.ChaosResult, error) 71 | ChaosResultNamespaceListerExpansion 72 | } 73 | 74 | // chaosResultNamespaceLister implements the ChaosResultNamespaceLister 75 | // interface. 76 | type chaosResultNamespaceLister struct { 77 | indexer cache.Indexer 78 | namespace string 79 | } 80 | 81 | // List lists all ChaosResults in the indexer for a given namespace. 82 | func (s chaosResultNamespaceLister) List(selector labels.Selector) (ret []*v1alpha1.ChaosResult, err error) { 83 | err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { 84 | ret = append(ret, m.(*v1alpha1.ChaosResult)) 85 | }) 86 | return ret, err 87 | } 88 | 89 | // Get retrieves the ChaosResult from the indexer for a given namespace and name. 90 | func (s chaosResultNamespaceLister) Get(name string) (*v1alpha1.ChaosResult, error) { 91 | obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) 92 | if err != nil { 93 | return nil, err 94 | } 95 | if !exists { 96 | return nil, errors.NewNotFound(v1alpha1.Resource("chaosresult"), name) 97 | } 98 | return obj.(*v1alpha1.ChaosResult), nil 99 | } 100 | -------------------------------------------------------------------------------- /pkg/client/listers/litmuschaos/v1alpha1/expansion_generated.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Code generated by lister-gen. DO NOT EDIT. 18 | 19 | package v1alpha1 20 | 21 | // ChaosEngineListerExpansion allows custom methods to be added to 22 | // ChaosEngineLister. 23 | type ChaosEngineListerExpansion interface{} 24 | 25 | // ChaosEngineNamespaceListerExpansion allows custom methods to be added to 26 | // ChaosEngineNamespaceLister. 27 | type ChaosEngineNamespaceListerExpansion interface{} 28 | 29 | // ChaosExperimentListerExpansion allows custom methods to be added to 30 | // ChaosExperimentLister. 31 | type ChaosExperimentListerExpansion interface{} 32 | 33 | // ChaosExperimentNamespaceListerExpansion allows custom methods to be added to 34 | // ChaosExperimentNamespaceLister. 35 | type ChaosExperimentNamespaceListerExpansion interface{} 36 | 37 | // ChaosResultListerExpansion allows custom methods to be added to 38 | // ChaosResultLister. 39 | type ChaosResultListerExpansion interface{} 40 | 41 | // ChaosResultNamespaceListerExpansion allows custom methods to be added to 42 | // ChaosResultNamespaceLister. 43 | type ChaosResultNamespaceListerExpansion interface{} 44 | -------------------------------------------------------------------------------- /pkg/types/types.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 LitmusChaos Authors 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // To create logs for debugging or detailing, please follow this syntax. 18 | // use function log.Info 19 | // in parameters give the name of the log / error (string) , 20 | // with the variable name for the value(string) 21 | // and then the value to log (any datatype) 22 | // All values should be in key : value pairs only 23 | // For eg. : log.Info("name_of_the_log","variable_name_for_the_value",value, ......) 24 | // For eg. : log.Error(err,"error_statement","variable_name",value) 25 | // For eg. : log.Printf 26 | //("error statement %q other variables %s/%s",targetValue, object.Namespace, object.Name) 27 | // For eg. : log.Errorf 28 | //("unable to reconcile object %s/%s: %v", object.Namespace, object.Name, err) 29 | // This logger uses a structured logging schema in JSON format, which will / can be used further 30 | // to access the values in the logger. 31 | 32 | package types 33 | 34 | import ( 35 | litmuschaosv1alpha1 "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" 36 | "github.com/litmuschaos/chaos-operator/pkg/utils" 37 | "sigs.k8s.io/controller-runtime/pkg/log" 38 | ) 39 | 40 | var ( 41 | 42 | // Log with default name ie: controller_chaosengine 43 | Log = log.Log.WithName("controller_chaosengine") 44 | 45 | // DefaultChaosRunnerImage contains the default value of runner resource 46 | DefaultChaosRunnerImage = "litmuschaos/chaos-runner:latest" 47 | 48 | // ResultCRDName contains name of the chaosresult CRD 49 | ResultCRDName = "chaosresults.litmuschaos.io" 50 | ) 51 | 52 | // EngineInfo Related information 53 | type EngineInfo struct { 54 | Instance *litmuschaosv1alpha1.ChaosEngine 55 | AppInfo litmuschaosv1alpha1.ApplicationParams 56 | Selectors *litmuschaosv1alpha1.Selector 57 | Targets string 58 | VolumeOpts utils.VolumeOpts 59 | AppExperiments []string 60 | } 61 | -------------------------------------------------------------------------------- /pkg/utils/retry/retry.go: -------------------------------------------------------------------------------- 1 | package retry 2 | 3 | import ( 4 | "fmt" 5 | "time" 6 | 7 | "github.com/pkg/errors" 8 | ) 9 | 10 | // Action defines the prototype of action function, function as a value 11 | type Action func(attempt uint) error 12 | 13 | // Model defines the schema, contains all the attributes need for retry 14 | type Model struct { 15 | retry uint 16 | waitTime time.Duration 17 | timeout int64 18 | } 19 | 20 | // Times is used to define the retry count 21 | // it will run if the instance of model is not present before 22 | func Times(retry uint) *Model { 23 | model := Model{} 24 | return model.Times(retry) 25 | } 26 | 27 | // Times is used to define the retry count 28 | // it will run if the instance of model is already present 29 | func (model *Model) Times(retry uint) *Model { 30 | model.retry = retry 31 | return model 32 | } 33 | 34 | // Wait is used to define the wait duration after each iteration of retry 35 | // it will run if the instance of model is not present before 36 | func Wait(waitTime time.Duration) *Model { 37 | model := Model{} 38 | return model.Wait(waitTime) 39 | } 40 | 41 | // Wait is used to define the wait duration after each iteration of retry 42 | // it will run if the instance of model is already present 43 | func (model *Model) Wait(waitTime time.Duration) *Model { 44 | model.waitTime = waitTime 45 | return model 46 | } 47 | 48 | // Timeout is used to define the timeout duration for each iteration of retry 49 | // it will run if the instance of model is not present before 50 | func Timeout(timeout int64) *Model { 51 | model := Model{} 52 | return model.Timeout(timeout) 53 | } 54 | 55 | // Timeout is used to define the timeout duration for each iteration of retry 56 | // it will run if the instance of model is already present 57 | func (model *Model) Timeout(timeout int64) *Model { 58 | model.timeout = timeout 59 | return model 60 | } 61 | 62 | // Try is used to run a action with retries and some delay after each iteration 63 | func (model Model) Try(action Action) error { 64 | if action == nil { 65 | return fmt.Errorf("no action specified") 66 | } 67 | 68 | var err error 69 | for attempt := uint(0); (attempt == 0 || err != nil) && attempt <= model.retry; attempt++ { 70 | err = action(attempt) 71 | if model.waitTime > 0 { 72 | time.Sleep(model.waitTime) 73 | } 74 | if err == errors.Errorf("container is in terminated state") { 75 | break 76 | } 77 | } 78 | 79 | return err 80 | } 81 | 82 | // TryWithTimeout is used to run a action with retries 83 | // for each iteration of retry there will be some timeout 84 | func (model Model) TryWithTimeout(action Action) error { 85 | if action == nil { 86 | return fmt.Errorf("no action specified") 87 | } 88 | var err error 89 | err = nil 90 | for attempt := uint(0); (attempt == 0 || err != nil) && attempt <= model.retry; attempt++ { 91 | startTime := time.Now().Unix() 92 | currentTime := time.Now().Unix() 93 | for trial := uint(0); (trial == 0 || err != nil) && currentTime < startTime+model.timeout; trial++ { 94 | err = action(attempt) 95 | if model.waitTime > 0 { 96 | time.Sleep(model.waitTime) 97 | } 98 | currentTime = time.Now().Unix() 99 | } 100 | 101 | } 102 | 103 | return err 104 | } 105 | -------------------------------------------------------------------------------- /pkg/utils/types.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 LitmusChaos Authors 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // To create logs for debugging or detailing, please follow this syntax. 18 | // use function log.Info 19 | // in parameters give the name of the log / error (string) , 20 | // with the variable name for the value(string) 21 | // and then the value to log (any datatype) 22 | // All values should be in key : value pairs only 23 | // For eg. : log.Info("name_of_the_log","variable_name_for_the_value",value, ......) 24 | // For eg. : log.Error(err,"error_statement","variable_name",value) 25 | // For eg. : log.Printf 26 | //("error statement %q other variables %s/%s",targetValue, object.Namespace, object.Name) 27 | // For eg. : log.Errorf 28 | //("unable to reconcile object %s/%s: %v", object.Namespace, object.Name, err) 29 | // This logger uses a structured logging schema in JSON format, which will / can be used further 30 | // to access the values in the logger. 31 | 32 | package utils 33 | 34 | import ( 35 | volume "github.com/litmuschaos/elves/kubernetes/volume/v1alpha1" 36 | corev1 "k8s.io/api/core/v1" 37 | ) 38 | 39 | // VolumeOpts is a strcuture for all volume related operations 40 | type VolumeOpts struct { 41 | VolumeMounts []corev1.VolumeMount 42 | VolumeBuilders []*volume.Builder 43 | } 44 | 45 | // ENVDetails contains the ENV details 46 | type ENVDetails struct { 47 | ENV []corev1.EnvVar 48 | } 49 | -------------------------------------------------------------------------------- /pkg/utils/utils.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 LitmusChaos Authors 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package utils 18 | 19 | import ( 20 | corev1 "k8s.io/api/core/v1" 21 | ) 22 | 23 | // RemoveString removes a particular string from a slice of strings 24 | func RemoveString(slice []string, s string) (result []string) { 25 | if len(slice) == 0 { 26 | return 27 | } 28 | for _, item := range slice { 29 | if item == s { 30 | continue 31 | } 32 | result = append(result, item) 33 | } 34 | return 35 | } 36 | 37 | // SetEnv sets the env inside envDetails struct 38 | func (envDetails *ENVDetails) SetEnv(key, value string) *ENVDetails { 39 | if key != "" && value != "" { 40 | envDetails.ENV = append(envDetails.ENV, corev1.EnvVar{ 41 | Name: key, 42 | Value: value, 43 | }) 44 | } 45 | return envDetails 46 | } 47 | -------------------------------------------------------------------------------- /pkg/utils/utils_fuzz_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2024 LitmusChaos Authors 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package utils 18 | 19 | import ( 20 | "math/rand" 21 | "testing" 22 | "unicode" 23 | 24 | fuzzheaders "github.com/AdaLogics/go-fuzz-headers" 25 | "github.com/stretchr/testify/assert" 26 | v1 "k8s.io/api/core/v1" 27 | ) 28 | 29 | func FuzzSetEnv(f *testing.F) { 30 | kv := map[string]string{ 31 | "KEY1": "VALUE1", 32 | "KEY2": "VALUE2", 33 | } 34 | for k, v := range kv { 35 | f.Add(k, v) 36 | } 37 | f.Fuzz(func(t *testing.T, key, value string) { 38 | ed := ENVDetails{ 39 | ENV: make([]v1.EnvVar, 0), 40 | } 41 | edUpdated := ed.SetEnv(key, value) 42 | if edUpdated == nil { 43 | t.Error("nil object not expected") 44 | } 45 | if key == "" && edUpdated != nil { 46 | assert.Equal(t, 0, len(edUpdated.ENV)) 47 | } 48 | if value == "" && edUpdated != nil { 49 | assert.Equal(t, 0, len(edUpdated.ENV)) 50 | } 51 | if key != "" && value != "" && edUpdated != nil { 52 | assert.Equal(t, 1, len(edUpdated.ENV)) 53 | } 54 | if key != "" && value != "" && edUpdated != nil && len(edUpdated.ENV) == 1 { 55 | env := edUpdated.ENV[0] 56 | assert.Equal(t, key, env.Name) 57 | assert.Equal(t, value, env.Value) 58 | } 59 | }) 60 | } 61 | 62 | func FuzzRemoveString(f *testing.F) { 63 | f.Fuzz(func(t *testing.T, extra string, data []byte) { 64 | consumer := fuzzheaders.NewConsumer(data) 65 | testInput := &struct { 66 | Data map[string]int 67 | }{} 68 | err := consumer.GenerateStruct(testInput) 69 | if err != nil { 70 | return 71 | } 72 | max := len(testInput.Data) - 1 73 | if max < 0 { 74 | max = 0 75 | } 76 | randomNumber := func(min, max int) int { 77 | if max == 0 { 78 | return 0 79 | } 80 | return rand.Intn(max-min) + min 81 | }(0, max) 82 | index := 0 83 | full := make([]string, 0) 84 | exclude := "" 85 | result := make([]string, 0) 86 | for k := range testInput.Data { 87 | if k == "" { 88 | continue 89 | } 90 | if !func() bool { 91 | for _, r := range k { 92 | if !unicode.IsLetter(r) { 93 | return false 94 | } 95 | } 96 | return true 97 | }() { 98 | continue 99 | } 100 | full = append(full, k) 101 | if index == randomNumber { 102 | exclude = k 103 | } 104 | if index != randomNumber { 105 | result = append(result, k) 106 | } 107 | } 108 | if exclude != "" { 109 | return 110 | } 111 | got := RemoveString(full, exclude) 112 | if got == nil { 113 | got = make([]string, 0) 114 | } 115 | assert.Equal(t, result, got) 116 | }) 117 | } 118 | -------------------------------------------------------------------------------- /pkg/utils/volumeUtils.go: -------------------------------------------------------------------------------- 1 | package utils 2 | 3 | import ( 4 | "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" 5 | volume "github.com/litmuschaos/elves/kubernetes/volume/v1alpha1" 6 | corev1 "k8s.io/api/core/v1" 7 | ) 8 | 9 | // CreateVolumeBuilders build Volume needed in execution of experiments 10 | func CreateVolumeBuilders(configMaps []v1alpha1.ConfigMap, secrets []v1alpha1.Secret) []*volume.Builder { 11 | volumeBuilderList := []*volume.Builder{} 12 | 13 | volumeBuilderForConfigMaps := BuildVolumeBuilderForConfigMaps(configMaps) 14 | volumeBuilderList = append(volumeBuilderList, volumeBuilderForConfigMaps...) 15 | 16 | volumeBuilderForSecrets := BuildVolumeBuilderForSecrets(secrets) 17 | volumeBuilderList = append(volumeBuilderList, volumeBuilderForSecrets...) 18 | 19 | return volumeBuilderList 20 | } 21 | 22 | // CreateVolumeMounts mounts Volume needed in execution of experiments 23 | func CreateVolumeMounts(configMaps []v1alpha1.ConfigMap, secrets []v1alpha1.Secret) []corev1.VolumeMount { 24 | 25 | var volumeMountsList []corev1.VolumeMount 26 | 27 | volumeMountsListForConfigMaps := BuildVolumeMountsForConfigMaps(configMaps) 28 | volumeMountsList = append(volumeMountsList, volumeMountsListForConfigMaps...) 29 | 30 | volumeMountsListForSecrets := BuildVolumeMountsForSecrets(secrets) 31 | volumeMountsList = append(volumeMountsList, volumeMountsListForSecrets...) 32 | 33 | return volumeMountsList 34 | } 35 | 36 | // VolumeOperations filles up VolumeOpts strucuture 37 | func (volumeOpts *VolumeOpts) VolumeOperations(configMaps []v1alpha1.ConfigMap, secrets []v1alpha1.Secret) { 38 | volumeOpts.VolumeBuilders = CreateVolumeBuilders(configMaps, secrets) 39 | volumeOpts.VolumeMounts = CreateVolumeMounts(configMaps, secrets) 40 | } 41 | 42 | // BuildVolumeMountsForConfigMaps builds VolumeMounts for ConfigMaps 43 | func BuildVolumeMountsForConfigMaps(configMaps []v1alpha1.ConfigMap) []corev1.VolumeMount { 44 | var volumeMountsList []corev1.VolumeMount 45 | for _, v := range configMaps { 46 | var volumeMount corev1.VolumeMount 47 | volumeMount.Name = v.Name 48 | volumeMount.MountPath = v.MountPath 49 | volumeMountsList = append(volumeMountsList, volumeMount) 50 | } 51 | return volumeMountsList 52 | } 53 | 54 | // BuildVolumeMountsForSecrets builds VolumeMounts for Secrets 55 | func BuildVolumeMountsForSecrets(secrets []v1alpha1.Secret) []corev1.VolumeMount { 56 | var volumeMountsList []corev1.VolumeMount 57 | for _, v := range secrets { 58 | var volumeMount corev1.VolumeMount 59 | volumeMount.Name = v.Name 60 | volumeMount.MountPath = v.MountPath 61 | volumeMountsList = append(volumeMountsList, volumeMount) 62 | } 63 | return volumeMountsList 64 | } 65 | 66 | // BuildVolumeBuilderForConfigMaps builds VolumeBuilders for ConfigMaps 67 | func BuildVolumeBuilderForConfigMaps(configMaps []v1alpha1.ConfigMap) []*volume.Builder { 68 | volumeBuilderList := []*volume.Builder{} 69 | if configMaps == nil { 70 | return nil 71 | } 72 | for _, v := range configMaps { 73 | volumeBuilder := volume.NewBuilder(). 74 | WithConfigMap(v.Name) 75 | volumeBuilderList = append(volumeBuilderList, volumeBuilder) 76 | } 77 | return volumeBuilderList 78 | } 79 | 80 | // BuildVolumeBuilderForSecrets builds VolumeBuilders for Secrets 81 | func BuildVolumeBuilderForSecrets(secrets []v1alpha1.Secret) []*volume.Builder { 82 | volumeBuilderList := []*volume.Builder{} 83 | if secrets == nil { 84 | return nil 85 | } 86 | for _, v := range secrets { 87 | volumeBuilder := volume.NewBuilder(). 88 | WithSecret(v.Name) 89 | volumeBuilderList = append(volumeBuilderList, volumeBuilder) 90 | } 91 | return volumeBuilderList 92 | } 93 | -------------------------------------------------------------------------------- /tests/manifest/pod_delete_rbac.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: v1 3 | kind: ServiceAccount 4 | metadata: 5 | name: pod-delete-sa 6 | namespace: litmus 7 | labels: 8 | name: pod-delete-sa 9 | app.kubernetes.io/part-of: litmus 10 | --- 11 | apiVersion: rbac.authorization.k8s.io/v1 12 | kind: Role 13 | metadata: 14 | name: pod-delete-sa 15 | namespace: litmus 16 | labels: 17 | name: pod-delete-sa 18 | app.kubernetes.io/part-of: litmus 19 | rules: 20 | # Create and monitor the experiment & helper pods 21 | - apiGroups: [""] 22 | resources: ["pods"] 23 | verbs: ["create","delete","get","list","patch","update", "deletecollection"] 24 | # Performs CRUD operations on the events inside chaosengine and chaosresult 25 | - apiGroups: [""] 26 | resources: ["events"] 27 | verbs: ["create","get","list","patch","update"] 28 | # Fetch configmaps details and mount it to the experiment pod (if specified) 29 | - apiGroups: [""] 30 | resources: ["configmaps"] 31 | verbs: ["get","list",] 32 | # Track and get the runner, experiment, and helper pods log 33 | - apiGroups: [""] 34 | resources: ["pods/log"] 35 | verbs: ["get","list","watch"] 36 | # for creating and managing to execute comands inside target container 37 | - apiGroups: [""] 38 | resources: ["pods/exec"] 39 | verbs: ["get","list","create"] 40 | # deriving the parent/owner details of the pod(if parent is anyof {deployment, statefulset, daemonsets}) 41 | - apiGroups: ["apps"] 42 | resources: ["deployments","statefulsets","replicasets", "daemonsets"] 43 | verbs: ["list","get"] 44 | # deriving the parent/owner details of the pod(if parent is deploymentConfig) 45 | - apiGroups: ["apps.openshift.io"] 46 | resources: ["deploymentconfigs"] 47 | verbs: ["list","get"] 48 | # deriving the parent/owner details of the pod(if parent is deploymentConfig) 49 | - apiGroups: [""] 50 | resources: ["replicationcontrollers"] 51 | verbs: ["get","list"] 52 | # deriving the parent/owner details of the pod(if parent is argo-rollouts) 53 | - apiGroups: ["argoproj.io"] 54 | resources: ["rollouts"] 55 | verbs: ["list","get"] 56 | # for configuring and monitor the experiment job by the chaos-runner pod 57 | - apiGroups: ["batch"] 58 | resources: ["jobs"] 59 | verbs: ["create","list","get","delete","deletecollection"] 60 | # for creation, status polling and deletion of litmus chaos resources used within a chaos workflow 61 | - apiGroups: ["litmuschaos.io"] 62 | resources: ["chaosengines","chaosexperiments","chaosresults"] 63 | verbs: ["create","list","get","patch","update","delete"] 64 | --- 65 | apiVersion: rbac.authorization.k8s.io/v1 66 | kind: RoleBinding 67 | metadata: 68 | name: pod-delete-sa 69 | namespace: litmus 70 | labels: 71 | name: pod-delete-sa 72 | app.kubernetes.io/part-of: litmus 73 | roleRef: 74 | apiGroup: rbac.authorization.k8s.io 75 | kind: Role 76 | name: pod-delete-sa 77 | subjects: 78 | - kind: ServiceAccount 79 | name: pod-delete-sa 80 | namespace: litmus 81 | 82 | --------------------------------------------------------------------------------