Compare commits
20 Commits
Author | SHA1 | Date |
---|---|---|
|
af8244e53a | |
|
0e85028f68 | |
|
63281440c1 | |
|
7e4ac4cc45 | |
|
9fb5e5a384 | |
|
0b10874e04 | |
|
77a6191735 | |
|
bb7ea39bcd | |
|
3a8ff7b8fa | |
|
e96a7ee7f1 | |
|
31aa78b0cf | |
|
9d6dfb2d65 | |
|
a4c31076d4 | |
|
2b2646ea7e | |
|
dc17ee1399 | |
|
fe0bf63328 | |
|
361a7649cb | |
|
f1afe838dd | |
|
ba4d2f704c | |
|
2d84728732 |
|
@ -1,10 +0,0 @@
|
|||
component_depth: 2
|
||||
languages:
|
||||
- go
|
||||
exclude:
|
||||
- /vendor/.*
|
||||
- /pkg/client/.*
|
||||
- /pkg/apis/litmuschaos/v1alpha1/zz_generated.*\.go
|
||||
test:
|
||||
include:
|
||||
- .*/test/.*\.go
|
|
@ -2,4 +2,4 @@
|
|||
# Each line is a file pattern followed by one or more owners.
|
||||
|
||||
# These owners will be the default owners for everything in the repo.
|
||||
* @rahulchheda @ksatchit @chandankumar4 @rajdas98
|
||||
* @ksatchit @ispeakc0de @imrajdas
|
|
@ -11,7 +11,7 @@ jobs:
|
|||
# Install golang
|
||||
- uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: 1.20.0
|
||||
go-version: 1.22
|
||||
|
||||
# Checkout to the latest commit
|
||||
# On specific directory/path
|
||||
|
@ -22,11 +22,13 @@ jobs:
|
|||
run: make gofmt-check
|
||||
|
||||
- name: golangci-lint
|
||||
uses: reviewdog/action-golangci-lint@v1
|
||||
uses: reviewdog/action-golangci-lint@v2
|
||||
with:
|
||||
golangci_lint_flags: "--timeout=10m"
|
||||
|
||||
- name: unused-package check
|
||||
run: make unused-package-check
|
||||
|
||||
|
||||
trivy:
|
||||
needs: pre-checks
|
||||
runs-on: ubuntu-latest
|
||||
|
@ -38,7 +40,7 @@ jobs:
|
|||
- name: Build an image from Dockerfile
|
||||
run: |
|
||||
docker build -f build/Dockerfile -t docker.io/litmuschaos/chaos-operator:${{ github.sha }} . --build-arg TARGETPLATFORM=linux/amd64
|
||||
|
||||
|
||||
- name: Run Trivy vulnerability scanner
|
||||
uses: aquasecurity/trivy-action@master
|
||||
with:
|
||||
|
@ -47,7 +49,19 @@ jobs:
|
|||
exit-code: '1'
|
||||
ignore-unfixed: true
|
||||
vuln-type: 'os,library'
|
||||
severity: 'CRITICAL,HIGH'
|
||||
severity: 'CRITICAL,HIGH'
|
||||
|
||||
gitleaks-scan:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Run GitLeaks
|
||||
run: |
|
||||
wget https://github.com/gitleaks/gitleaks/releases/download/v8.18.2/gitleaks_8.18.2_linux_x64.tar.gz && \
|
||||
tar -zxvf gitleaks_8.18.2_linux_x64.tar.gz && \
|
||||
sudo mv gitleaks /usr/local/bin && gitleaks detect --source . -v
|
||||
|
||||
image-build:
|
||||
runs-on: ubuntu-latest
|
||||
|
@ -67,9 +81,9 @@ jobs:
|
|||
make build-amd64
|
||||
docker save -o ${{ github.workspace }}/image.tar litmuschaos/chaos-operator:ci
|
||||
chmod +x ${{ github.workspace }}/image.tar
|
||||
|
||||
|
||||
- name: Upload artifact
|
||||
uses: actions/upload-artifact@v2
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: myimage
|
||||
path: |
|
||||
|
@ -82,7 +96,7 @@ jobs:
|
|||
# Install golang
|
||||
- uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: 1.20.0
|
||||
go-version: 1.22
|
||||
|
||||
# Checkout to the latest commit
|
||||
# On specific directory/path
|
||||
|
@ -91,7 +105,7 @@ jobs:
|
|||
|
||||
#Install and configure a kind cluster
|
||||
- name: Installing Prerequisites (K3S Cluster)
|
||||
env:
|
||||
env:
|
||||
KUBECONFIG: /etc/rancher/k3s/k3s.yaml
|
||||
run: |
|
||||
curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION=v1.20.14-rc1+k3s1 sh -s - --docker --write-kubeconfig-mode 664
|
||||
|
@ -105,15 +119,15 @@ jobs:
|
|||
make deps
|
||||
|
||||
- name: Download artifact
|
||||
uses: actions/download-artifact@v2
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: myimage
|
||||
path: ${{ github.workspace }}
|
||||
|
||||
|
||||
- name: Load Docker image
|
||||
run: |
|
||||
docker load --input ${{ github.workspace }}/image.tar
|
||||
shell: bash
|
||||
shell: bash
|
||||
|
||||
- name: Running Go BDD Test
|
||||
run: |
|
||||
|
|
|
@ -2,13 +2,13 @@ name: ChaosOperator-E2E-pipeline
|
|||
on:
|
||||
issue_comment:
|
||||
types: [created]
|
||||
|
||||
|
||||
jobs:
|
||||
Tests:
|
||||
if: contains(github.event.comment.html_url, '/pull/') && startsWith(github.event.comment.body, '/run-e2e')
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
|
||||
|
||||
- name: Notification for e2e Start
|
||||
uses: peter-evans/create-or-update-comment@v1
|
||||
with:
|
||||
|
@ -19,13 +19,13 @@ jobs:
|
|||
|
||||
- uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: 1.20.0
|
||||
|
||||
- name: Setting up GOPATH
|
||||
go-version: 1.22
|
||||
|
||||
- name: Setting up GOPATH
|
||||
run: |
|
||||
echo ::set-env name=GOPATH::${GITHUB_WORKSPACE}/go
|
||||
env:
|
||||
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
|
||||
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
|
||||
|
||||
#Using the last commit id of pull request
|
||||
- uses: octokit/request-action@v2.x
|
||||
|
@ -36,20 +36,20 @@ jobs:
|
|||
pull_number: ${{ github.event.issue.number }}
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
|
||||
- name: set commit to output
|
||||
id: getcommit
|
||||
run: |
|
||||
prsha=$(echo $response | jq '.[-1].sha' | tr -d '"')
|
||||
echo "::set-output name=sha::$prsha"
|
||||
env:
|
||||
echo "::set-output name=sha::$prsha"
|
||||
env:
|
||||
response: ${{ steps.get_PR_commits.outputs.data }}
|
||||
|
||||
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
ref: ${{steps.getcommit.outputs.sha}}
|
||||
path: go/src/github.com/litmuschaos/chaos-operator
|
||||
|
||||
|
||||
- name: Build docker image
|
||||
run: |
|
||||
export PATH=$PATH:$(go env GOPATH)/bin
|
||||
|
@ -61,12 +61,14 @@ jobs:
|
|||
- name: Installing Prerequisites (KinD Cluster)
|
||||
uses: engineerd/setup-kind@v0.5.0
|
||||
with:
|
||||
version: "v0.7.0"
|
||||
|
||||
version: "v0.22.0"
|
||||
|
||||
- name: Configuring and testing kind Installation
|
||||
run: |
|
||||
kubectl cluster-info --context kind-kind
|
||||
kind get kubeconfig --internal >$HOME/.kube/config
|
||||
kubectl cluster-info
|
||||
kubectl get pods -n kube-system
|
||||
echo "current-context:" $(kubectl config current-context)
|
||||
echo "environment-kubeconfig:" ${KUBECONFIG}
|
||||
kubectl get nodes
|
||||
|
||||
- name: Load image on the nodes of the cluster
|
||||
|
@ -76,7 +78,7 @@ jobs:
|
|||
- name: Getting litmus-e2e repository
|
||||
run: |
|
||||
cd ${GOPATH}/src/github.com/litmuschaos/
|
||||
git clone https://github.com/litmuschaos/litmus-e2e.git -b generic
|
||||
git clone https://github.com/litmuschaos/litmus-e2e.git -b master
|
||||
|
||||
- name: Install LitmusChaos
|
||||
run: |
|
||||
|
@ -86,25 +88,25 @@ jobs:
|
|||
env:
|
||||
OPERATOR_IMAGE: litmuschaos/chaos-operator:ci
|
||||
IMAGE_PULL_POLICY: IfNotPresent
|
||||
KUBECONFIG: /home/runner/.kube/config
|
||||
|
||||
KUBECONFIG: /home/runner/.kube/config
|
||||
|
||||
- name: Run Admin mode test
|
||||
if: startsWith(github.event.comment.body, '/run-e2e-admin-mode') || startsWith(github.event.comment.body, '/run-e2e-all')
|
||||
run: |
|
||||
export PATH=$PATH:$(go env GOPATH)/bin
|
||||
cd ${GOPATH}/src/github.com/litmuschaos/litmus-e2e
|
||||
go test operator/admin-mode_test.go -v -count=1
|
||||
go test components/operator/admin-mode_test.go -v -count=1
|
||||
env:
|
||||
KUBECONFIG: /home/runner/.kube/config
|
||||
KUBECONFIG: /home/runner/.kube/config
|
||||
|
||||
- name: Run Reconcile Resiliency test
|
||||
if: startsWith(github.event.comment.body, '/run-e2e-reconcile-resiliency') || startsWith(github.event.comment.body, '/run-e2e-all')
|
||||
run: |
|
||||
export PATH=$PATH:$(go env GOPATH)/bin
|
||||
cd ${GOPATH}/src/github.com/litmuschaos/litmus-e2e
|
||||
go test operator/reconcile-resiliency_test.go -v -count=1
|
||||
go test components/operator/reconcile-resiliency_test.go -v -count=1
|
||||
env:
|
||||
KUBECONFIG: /home/runner/.kube/config
|
||||
KUBECONFIG: /home/runner/.kube/config
|
||||
|
||||
- name: Check the test run
|
||||
if: |
|
||||
|
@ -113,7 +115,7 @@ jobs:
|
|||
run: |
|
||||
echo ::set-env name=TEST_RUN::true
|
||||
env:
|
||||
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
|
||||
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
|
||||
|
||||
- name: Check for all the jobs are succeeded
|
||||
if: ${{ success() && env.TEST_RUN == 'true' }}
|
||||
|
@ -123,11 +125,11 @@ jobs:
|
|||
body: |
|
||||
**Test Result:** All tests are passed
|
||||
**Logs:** [${{ env.RUN_ID }}](https://github.com/litmuschaos/chaos-operator/actions/runs/${{ env.RUN_ID }})
|
||||
|
||||
reactions: hooray
|
||||
env:
|
||||
|
||||
reactions: hooray
|
||||
env:
|
||||
RUN_ID: ${{ github.run_id }}
|
||||
|
||||
|
||||
- name: Check for any job failed
|
||||
if: ${{ failure() }}
|
||||
uses: peter-evans/create-or-update-comment@v1
|
||||
|
@ -135,23 +137,23 @@ jobs:
|
|||
comment-id: "${{ github.event.comment.id }}"
|
||||
body: |
|
||||
**Test Failed:** Some tests are failed please check
|
||||
**Logs:** [${{ env.RUN_ID }}](https://github.com/litmuschaos/chaos-operator/actions/runs/${{ env.RUN_ID }})
|
||||
**Logs:** [${{ env.RUN_ID }}](https://github.com/litmuschaos/chaos-operator/actions/runs/${{ env.RUN_ID }})
|
||||
reactions: confused
|
||||
env:
|
||||
env:
|
||||
RUN_ID: ${{ github.run_id }}
|
||||
|
||||
|
||||
- name: Deleting KinD cluster
|
||||
if: ${{ always() }}
|
||||
run: kind delete cluster
|
||||
|
||||
|
||||
- name: Check if any test ran or not
|
||||
if: env.TEST_RUN != 'true'
|
||||
uses: peter-evans/create-or-update-comment@v1
|
||||
with:
|
||||
comment-id: "${{ github.event.comment.id }}"
|
||||
body: |
|
||||
**Test Result:** No test found
|
||||
**Test Result:** No test found try /run-e2e-all
|
||||
**Logs:** [${{ env.RUN_ID }}](https://github.com/litmuschaos/chaos-operator/actions/runs/${{ env.RUN_ID }})
|
||||
reactions: eyes
|
||||
env:
|
||||
env:
|
||||
RUN_ID: ${{ github.run_id }}
|
||||
|
|
|
@ -13,7 +13,7 @@ jobs:
|
|||
# Install golang
|
||||
- uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: 1.20.0
|
||||
go-version: 1.22
|
||||
|
||||
# Checkout to the latest commit
|
||||
# On specific directory/path
|
||||
|
@ -24,14 +24,13 @@ jobs:
|
|||
run: make gofmt-check
|
||||
|
||||
- name: golangci-lint
|
||||
uses: reviewdog/action-golangci-lint@v1
|
||||
uses: reviewdog/action-golangci-lint@v2
|
||||
|
||||
- name: unused-package check
|
||||
run: make unused-package-check
|
||||
|
||||
image-build:
|
||||
runs-on: ubuntu-latest
|
||||
needs: tests
|
||||
steps:
|
||||
# Checkout to the latest commit
|
||||
# On specific directory/path
|
||||
|
@ -59,45 +58,4 @@ jobs:
|
|||
DOCKER_TAG: ci
|
||||
DNAME: ${{ secrets.DNAME }}
|
||||
DPASS: ${{ secrets.DPASS }}
|
||||
run: make push-chaos-operator
|
||||
|
||||
tests:
|
||||
needs: pre-checks
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
# Checkout to the latest commit
|
||||
# On specific directory/path
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
|
||||
# Install golang
|
||||
- uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: 1.20.0
|
||||
|
||||
#Install and configure a kind cluster
|
||||
- name: Installing Prerequisites (K3S Cluster)
|
||||
env:
|
||||
KUBECONFIG: /etc/rancher/k3s/k3s.yaml
|
||||
run: |
|
||||
curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION=v1.20.14-rc1+k3s1 sh -s - --docker --write-kubeconfig-mode 664
|
||||
kubectl wait node --all --for condition=ready --timeout=90s
|
||||
mkdir -p $HOME/.kube
|
||||
cp /etc/rancher/k3s/k3s.yaml $HOME/.kube/config
|
||||
kubectl get nodes
|
||||
|
||||
- name: Dependency checks
|
||||
run: |
|
||||
make deps
|
||||
|
||||
- name: Build Docker Image
|
||||
env:
|
||||
DOCKER_REPO: litmuschaos
|
||||
DOCKER_IMAGE: chaos-operator
|
||||
DOCKER_TAG: ci
|
||||
run: |
|
||||
make build-amd64
|
||||
|
||||
- name: Running Go BDD Test
|
||||
run: |
|
||||
make test
|
||||
run: make push-chaos-operator
|
|
@ -11,25 +11,15 @@ jobs:
|
|||
# Install golang
|
||||
- uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: 1.20.0
|
||||
go-version: 1.22
|
||||
|
||||
# Checkout to the latest commit
|
||||
# On specific directory/path
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: gofmt check
|
||||
run: make gofmt-check
|
||||
|
||||
- name: golangci-lint
|
||||
uses: reviewdog/action-golangci-lint@v1
|
||||
|
||||
- name: unused-package check
|
||||
run: make unused-package-check
|
||||
|
||||
image-build:
|
||||
runs-on: ubuntu-latest
|
||||
needs: tests
|
||||
steps:
|
||||
# Checkout to the latest commit
|
||||
# On specific directory/path
|
||||
|
@ -73,44 +63,3 @@ jobs:
|
|||
DNAME: ${{ secrets.DNAME }}
|
||||
DPASS: ${{ secrets.DPASS }}
|
||||
run: make push-chaos-operator
|
||||
|
||||
tests:
|
||||
needs: pre-checks
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
# Checkout to the latest commit
|
||||
# On specific directory/path
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
|
||||
# Install golang
|
||||
- uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: 1.20.0
|
||||
|
||||
#Install and configure a kind cluster
|
||||
- name: Installing Prerequisites (K3S Cluster)
|
||||
env:
|
||||
KUBECONFIG: /etc/rancher/k3s/k3s.yaml
|
||||
run: |
|
||||
curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION=v1.20.14-rc1+k3s1 sh -s - --docker --write-kubeconfig-mode 664
|
||||
kubectl wait node --all --for condition=ready --timeout=90s
|
||||
mkdir -p $HOME/.kube
|
||||
cp /etc/rancher/k3s/k3s.yaml $HOME/.kube/config
|
||||
kubectl get nodes
|
||||
|
||||
- name: Dependency checks
|
||||
run: |
|
||||
make deps
|
||||
|
||||
- name: Build Docker Image
|
||||
env:
|
||||
DOCKER_REPO: litmuschaos
|
||||
DOCKER_IMAGE: chaos-operator
|
||||
DOCKER_TAG: ci
|
||||
run: |
|
||||
make build-amd64
|
||||
|
||||
- name: Running Go BDD Test
|
||||
run: |
|
||||
make test
|
||||
|
|
|
@ -4,15 +4,6 @@ on:
|
|||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
snyk:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@master
|
||||
- name: Run Snyk to check for vulnerabilities
|
||||
uses: snyk/actions/golang@master
|
||||
env:
|
||||
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
|
||||
|
||||
trivy:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
[](https://www.codacy.com/manual/litmuschaos/chaos-operator?utm_source=github.com&utm_medium=referral&utm_content=litmuschaos/chaos-operator&utm_campaign=Badge_Grade)
|
||||
[](https://goreportcard.com/report/github.com/litmuschaos/chaos-operator)
|
||||
[](https://bestpractices.coreinfrastructure.org/projects/5290)
|
||||
[](https://bettercodehub.com/)
|
||||
[](https://app.fossa.io/projects/git%2Bgithub.com%2Flitmuschaos%2Fchaos-operator?ref=badge_shield)
|
||||
[](https://codecov.io/gh/litmuschaos/chaos-operator)
|
||||
[](https://www.youtube.com/channel/UCa57PMqmz_j0wnteRa9nCaw)
|
||||
|
|
|
@ -208,8 +208,6 @@ type ExperimentList struct {
|
|||
|
||||
// ExperimentAttributes defines attributes of experiments
|
||||
type ExperimentAttributes struct {
|
||||
//Execution priority of the chaos experiment
|
||||
Rank uint32 `json:"rank"`
|
||||
// It contains env, configmaps, secrets, experimentImage, node selector, custom experiment annotation
|
||||
// which can be provided or overridden from the chaos engine
|
||||
Components ExperimentComponents `json:"components,omitempty"`
|
||||
|
@ -302,6 +300,8 @@ type SourceDetails struct {
|
|||
Privileged bool `json:"privileged,omitempty"`
|
||||
// NodeSelector for the source pod
|
||||
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
|
||||
// Tolerations for the source pod
|
||||
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
|
||||
// Volumes for the source pod
|
||||
Volumes []corev1.Volume `json:"volumes,omitempty"`
|
||||
// VolumesMount for the source pod
|
||||
|
@ -436,6 +436,8 @@ type RunProperty struct {
|
|||
// EvaluationTimeout is the timeout window in which the SLO metrics
|
||||
// will be fetched and will be evaluated
|
||||
EvaluationTimeout string `json:"evaluationTimeout,omitempty"`
|
||||
// Verbosity contains flags for type of logging while running the Continuous and onChaos Probes
|
||||
Verbosity string `json:"verbosity,omitempty"`
|
||||
// StopOnFailure contains flag to stop/continue experiment execution, if probe fails
|
||||
// it will stop the experiment execution, if provided true
|
||||
// it will continue the experiment execution, if provided false or not provided(default case)
|
||||
|
|
|
@ -1136,6 +1136,13 @@ func (in *SourceDetails) DeepCopyInto(out *SourceDetails) {
|
|||
(*out)[key] = val
|
||||
}
|
||||
}
|
||||
if in.Tolerations != nil {
|
||||
in, out := &in.Tolerations, &out.Tolerations
|
||||
*out = make([]v1.Toleration, len(*in))
|
||||
for i := range *in {
|
||||
(*in)[i].DeepCopyInto(&(*out)[i])
|
||||
}
|
||||
}
|
||||
if in.Volumes != nil {
|
||||
in, out := &in.Volumes, &out.Volumes
|
||||
*out = make([]v1.Volume, len(*in))
|
||||
|
|
|
@ -17,13 +17,15 @@ RUN go env
|
|||
RUN CGO_ENABLED=0 go build -buildvcs=false -o /output/chaos-operator -v ./main.go
|
||||
|
||||
# Packaging stage
|
||||
# Image source: https://github.com/litmuschaos/test-tools/blob/master/custom/hardened-alpine/infra/Dockerfile
|
||||
# The base image is non-root (have litmus user) with default litmus directory.
|
||||
FROM litmuschaos/infra-alpine
|
||||
FROM registry.access.redhat.com/ubi9/ubi-minimal:9.5
|
||||
|
||||
LABEL maintainer="LitmusChaos"
|
||||
|
||||
ENV OPERATOR=/usr/local/bin/chaos-operator
|
||||
|
||||
COPY --from=builder /output/chaos-operator ${OPERATOR}
|
||||
RUN chown 65534:0 ${OPERATOR} && chmod 755 ${OPERATOR}
|
||||
|
||||
USER 65534
|
||||
|
||||
ENTRYPOINT ["/usr/local/bin/chaos-operator"]
|
||||
|
|
|
@ -19,6 +19,11 @@ package controllers
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"reflect"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/go-logr/logr"
|
||||
litmuschaosv1alpha1 "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1"
|
||||
"github.com/litmuschaos/chaos-operator/pkg/analytics"
|
||||
|
@ -37,14 +42,10 @@ import (
|
|||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/client-go/tools/record"
|
||||
"os"
|
||||
"reflect"
|
||||
ctrl "sigs.k8s.io/controller-runtime"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
|
||||
"sigs.k8s.io/controller-runtime/pkg/reconcile"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
const finalizer = "chaosengine.litmuschaos.io/finalizer"
|
||||
|
@ -111,7 +112,7 @@ func (r *ChaosEngineReconciler) Reconcile(ctx context.Context, request ctrl.Requ
|
|||
|
||||
// Handling of normal execution of ChaosEngine
|
||||
if engine.Instance.Spec.EngineState == litmuschaosv1alpha1.EngineStateActive && engine.Instance.Status.EngineStatus == litmuschaosv1alpha1.EngineStatusInitialized {
|
||||
return r.reconcileForCreationAndRunning(engine, reqLogger)
|
||||
return r.reconcileForCreationAndRunning(engine, *reqLogger)
|
||||
}
|
||||
|
||||
// Handling Graceful completion of ChaosEngine
|
||||
|
@ -679,11 +680,11 @@ func updateExperimentStatusesForStop(engine *chaosTypes.EngineInfo) {
|
|||
}
|
||||
}
|
||||
|
||||
func startReqLogger(request reconcile.Request) logr.Logger {
|
||||
func startReqLogger(request reconcile.Request) *logr.Logger {
|
||||
reqLogger := chaosTypes.Log.WithValues("Request.Namespace", request.Namespace, "Request.Name", request.Name)
|
||||
reqLogger.Info("Reconciling ChaosEngine")
|
||||
|
||||
return reqLogger
|
||||
return &reqLogger
|
||||
}
|
||||
|
||||
func (r *ChaosEngineReconciler) updateEngineForComplete(engine *chaosTypes.EngineInfo, isCompleted bool) (bool, error) {
|
||||
|
@ -826,7 +827,7 @@ func isResultCRDAvailable() (bool, error) {
|
|||
Resource: "customresourcedefinitions",
|
||||
}
|
||||
|
||||
resultList, err := (*dynamicClient).Resource(gvr).List(context.Background(), v1.ListOptions{})
|
||||
resultList, err := dynamicClient.Resource(gvr).List(context.Background(), v1.ListOptions{})
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
|
|
@ -1621,7 +1621,7 @@ func TestReconcileForCreationAndRunning(t *testing.T) {
|
|||
|
||||
func CreateFakeClient(t *testing.T) *ChaosEngineReconciler {
|
||||
|
||||
fakeClient := litmusFakeClientset.NewFakeClient()
|
||||
fakeClient := litmusFakeClientset.NewClientBuilder().WithRuntimeObjects().Build()
|
||||
if fakeClient == nil {
|
||||
fmt.Println("litmusClient is not created")
|
||||
}
|
||||
|
|
|
@ -576,6 +576,29 @@ spec:
|
|||
type: string
|
||||
description: NodeSelector for the source pod
|
||||
type: object
|
||||
tolerations:
|
||||
description: Tolerations for the source pod
|
||||
items:
|
||||
description: The pod with this Toleration tolerates any taint matches the <key,value,effect> using the matching operator <operator>.
|
||||
properties:
|
||||
effect:
|
||||
description: Effect to match. Empty means all effects.
|
||||
type: string
|
||||
key:
|
||||
description: Taint key the toleration applies to. Empty means match all taint keys. If the key is empty, operator must be Exists.
|
||||
type: string
|
||||
operator:
|
||||
description: Operators are Exists or Equal. Defaults to Equal.
|
||||
type: string
|
||||
tolerationSeconds:
|
||||
description: Period of time the toleration tolerates the taint.
|
||||
format: int64
|
||||
type: integer
|
||||
value:
|
||||
description: If the operator is Exists, the value should be empty, otherwise just a regular string.
|
||||
type: string
|
||||
type: object
|
||||
type: array
|
||||
privileged:
|
||||
description: Privileged for the source pod
|
||||
type: boolean
|
||||
|
@ -2271,6 +2294,8 @@ spec:
|
|||
type: string
|
||||
initialDelay:
|
||||
type: string
|
||||
verbosity:
|
||||
type: string
|
||||
stopOnFailure:
|
||||
type: boolean
|
||||
sloProbe/inputs:
|
||||
|
|
|
@ -575,6 +575,29 @@ spec:
|
|||
type: string
|
||||
description: NodeSelector for the source pod
|
||||
type: object
|
||||
tolerations:
|
||||
description: Tolerations for the source pod
|
||||
items:
|
||||
description: The pod with this Toleration tolerates any taint matches the <key,value,effect> using the matching operator <operator>.
|
||||
properties:
|
||||
effect:
|
||||
description: Effect to match. Empty means all effects.
|
||||
type: string
|
||||
key:
|
||||
description: Taint key the toleration applies to. Empty means match all taint keys. If the key is empty, operator must be Exists.
|
||||
type: string
|
||||
operator:
|
||||
description: Operators are Exists or Equal. Defaults to Equal.
|
||||
type: string
|
||||
tolerationSeconds:
|
||||
description: Period of time the toleration tolerates the taint.
|
||||
format: int64
|
||||
type: integer
|
||||
value:
|
||||
description: If the operator is Exists, the value should be empty, otherwise just a regular string.
|
||||
type: string
|
||||
type: object
|
||||
type: array
|
||||
privileged:
|
||||
description: Privileged for the source pod
|
||||
type: boolean
|
||||
|
@ -2272,6 +2295,8 @@ spec:
|
|||
type: integer
|
||||
initialDelay:
|
||||
type: string
|
||||
verbosity:
|
||||
type: string
|
||||
stopOnFailure:
|
||||
type: boolean
|
||||
sloProbe/inputs:
|
||||
|
|
136
go.mod
136
go.mod
|
@ -1,120 +1,110 @@
|
|||
module github.com/litmuschaos/chaos-operator
|
||||
|
||||
go 1.20
|
||||
go 1.22
|
||||
|
||||
require (
|
||||
cloud.google.com/go v0.81.0 // indirect
|
||||
github.com/go-logr/logr v1.2.3
|
||||
github.com/google/go-cmp v0.5.6 // indirect
|
||||
github.com/go-logr/logr v1.4.2
|
||||
github.com/google/go-cmp v0.5.9 // indirect
|
||||
github.com/jpillora/go-ogle-analytics v0.0.0-20161213085824-14b04e0594ef
|
||||
github.com/litmuschaos/elves v0.0.0-20230607095010-c7119636b529
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/spf13/pflag v1.0.5 // indirect
|
||||
golang.org/x/crypto v0.0.0-20220314234659-1baeb1ce4c0b // indirect
|
||||
golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c // indirect
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
|
||||
k8s.io/api v0.26.0
|
||||
k8s.io/apimachinery v0.26.0
|
||||
golang.org/x/oauth2 v0.7.0 // indirect
|
||||
k8s.io/api v0.26.15
|
||||
k8s.io/apimachinery v0.26.15
|
||||
k8s.io/client-go v12.0.0+incompatible
|
||||
sigs.k8s.io/controller-runtime v0.10.0
|
||||
sigs.k8s.io/controller-runtime v0.14.6
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24
|
||||
github.com/google/martian v2.1.0+incompatible
|
||||
github.com/onsi/ginkgo v1.16.4
|
||||
github.com/onsi/gomega v1.15.0
|
||||
github.com/operator-framework/operator-sdk v0.19.0
|
||||
github.com/stretchr/testify v1.7.0
|
||||
github.com/onsi/ginkgo v1.16.5
|
||||
github.com/onsi/gomega v1.24.2
|
||||
github.com/stretchr/testify v1.8.2
|
||||
k8s.io/klog v1.0.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
|
||||
github.com/Azure/go-autorest/autorest v0.11.18 // indirect
|
||||
github.com/Azure/go-autorest/autorest/adal v0.9.13 // indirect
|
||||
github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect
|
||||
github.com/Azure/go-autorest/logger v0.2.1 // indirect
|
||||
github.com/Azure/go-autorest/tracing v0.6.0 // indirect
|
||||
github.com/beorn7/perks v1.0.1 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.1.2 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.2.0 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/evanphx/json-patch v4.11.0+incompatible // indirect
|
||||
github.com/form3tech-oss/jwt-go v3.2.3+incompatible // indirect
|
||||
github.com/fsnotify/fsnotify v1.4.9 // indirect
|
||||
github.com/go-logr/zapr v0.4.0 // indirect
|
||||
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
|
||||
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
|
||||
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
|
||||
github.com/fsnotify/fsnotify v1.6.0 // indirect
|
||||
github.com/go-logr/zapr v1.2.3 // indirect
|
||||
github.com/go-openapi/jsonpointer v0.19.5 // indirect
|
||||
github.com/go-openapi/jsonreference v0.20.0 // indirect
|
||||
github.com/go-openapi/swag v0.19.14 // indirect
|
||||
github.com/gogo/protobuf v1.3.2 // indirect
|
||||
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
|
||||
github.com/golang/protobuf v1.5.2 // indirect
|
||||
github.com/golang/protobuf v1.5.4 // indirect
|
||||
github.com/google/gnostic v0.5.7-v3refs // indirect
|
||||
github.com/google/gofuzz v1.1.0 // indirect
|
||||
github.com/google/uuid v1.1.2 // indirect
|
||||
github.com/googleapis/gnostic v0.5.5 // indirect
|
||||
github.com/hashicorp/golang-lru v0.5.3 // indirect
|
||||
github.com/google/uuid v1.3.0 // indirect
|
||||
github.com/imdario/mergo v0.3.12 // indirect
|
||||
github.com/josharian/intern v1.0.0 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
|
||||
github.com/mailru/easyjson v0.7.6 // indirect
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.2 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
|
||||
github.com/nxadm/tail v1.4.8 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/prometheus/client_golang v1.12.1 // indirect
|
||||
github.com/prometheus/client_model v0.2.0 // indirect
|
||||
github.com/prometheus/common v0.32.1 // indirect
|
||||
github.com/prometheus/procfs v0.7.3 // indirect
|
||||
github.com/prometheus/client_golang v1.14.0 // indirect
|
||||
github.com/prometheus/client_model v0.3.0 // indirect
|
||||
github.com/prometheus/common v0.37.0 // indirect
|
||||
github.com/prometheus/procfs v0.8.0 // indirect
|
||||
go.uber.org/atomic v1.7.0 // indirect
|
||||
go.uber.org/multierr v1.6.0 // indirect
|
||||
go.uber.org/zap v1.19.0 // indirect
|
||||
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
|
||||
go.uber.org/zap v1.24.0 // indirect
|
||||
golang.org/x/net v0.19.0 // indirect
|
||||
golang.org/x/sys v0.13.0 // indirect
|
||||
golang.org/x/term v0.5.0 // indirect
|
||||
golang.org/x/text v0.7.0 // indirect
|
||||
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
|
||||
golang.org/x/tools v0.16.1 // indirect
|
||||
golang.org/x/sys v0.15.0 // indirect
|
||||
golang.org/x/term v0.15.0 // indirect
|
||||
golang.org/x/text v0.14.0 // indirect
|
||||
golang.org/x/time v0.3.0 // indirect
|
||||
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
|
||||
google.golang.org/appengine v1.6.7 // indirect
|
||||
google.golang.org/protobuf v1.26.0 // indirect
|
||||
google.golang.org/protobuf v1.33.0 // indirect
|
||||
gopkg.in/inf.v0 v0.9.1 // indirect
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
k8s.io/apiextensions-apiserver v0.22.1 // indirect
|
||||
k8s.io/component-base v0.22.2 // indirect
|
||||
k8s.io/apiextensions-apiserver v0.26.1 // indirect
|
||||
k8s.io/component-base v0.26.15 // indirect
|
||||
k8s.io/klog/v2 v2.80.1 // indirect
|
||||
k8s.io/kube-openapi v0.0.0-20210421082810-95288971da7e // indirect
|
||||
k8s.io/utils v0.0.0-20221107191617-1a15be271d1d // indirect
|
||||
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 // indirect
|
||||
k8s.io/utils v0.0.0-20221128185143-99ec85e7a448 // indirect
|
||||
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect
|
||||
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
|
||||
sigs.k8s.io/yaml v1.2.0 // indirect
|
||||
sigs.k8s.io/yaml v1.3.0 // indirect
|
||||
)
|
||||
|
||||
// Pinned to kubernetes-1.21.2
|
||||
// Pinned to kubernetes-1.26
|
||||
replace (
|
||||
github.com/go-logr/logr => github.com/go-logr/logr v0.4.0
|
||||
k8s.io/api => k8s.io/api v0.21.2
|
||||
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.21.2
|
||||
k8s.io/apimachinery => k8s.io/apimachinery v0.21.2
|
||||
k8s.io/apiserver => k8s.io/apiserver v0.21.2
|
||||
k8s.io/cli-runtime => k8s.io/cli-runtime v0.21.2
|
||||
k8s.io/client-go => k8s.io/client-go v0.21.2
|
||||
k8s.io/cloud-provider => k8s.io/cloud-provider v0.21.2
|
||||
k8s.io/cluster-bootstrap => k8s.io/cluster-bootstrap v0.21.2
|
||||
k8s.io/code-generator => k8s.io/code-generator v0.21.2
|
||||
k8s.io/component-base => k8s.io/component-base v0.21.2
|
||||
k8s.io/cri-api => k8s.io/cri-api v0.21.2
|
||||
k8s.io/csi-translation-lib => k8s.io/csi-translation-lib v0.21.2
|
||||
k8s.io/klog/v2 => k8s.io/klog/v2 v2.9.0
|
||||
k8s.io/kube-aggregator => k8s.io/kube-aggregator v0.21.2
|
||||
k8s.io/kube-controller-manager => k8s.io/kube-controller-manager v0.21.2
|
||||
k8s.io/kube-proxy => k8s.io/kube-proxy v0.21.2
|
||||
k8s.io/kube-scheduler => k8s.io/kube-scheduler v0.21.2
|
||||
k8s.io/kubectl => k8s.io/kubectl v0.21.2
|
||||
k8s.io/kubelet => k8s.io/kubelet v0.21.2
|
||||
k8s.io/legacy-cloud-providers => k8s.io/legacy-cloud-providers v0.21.2
|
||||
k8s.io/metrics => k8s.io/metrics v0.21.2
|
||||
k8s.io/sample-apiserver => k8s.io/sample-apiserver v0.21.2
|
||||
sigs.k8s.io/controller-runtime => sigs.k8s.io/controller-runtime v0.14.6
|
||||
github.com/go-logr/logr => github.com/go-logr/logr v1.4.2
|
||||
k8s.io/api => k8s.io/api v0.26.15
|
||||
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.26.15
|
||||
k8s.io/apimachinery => k8s.io/apimachinery v0.26.15
|
||||
k8s.io/client-go => k8s.io/client-go v0.26.15
|
||||
k8s.io/cloud-provider => k8s.io/cloud-provider v0.26.15
|
||||
k8s.io/cluster-bootstrap => k8s.io/cluster-bootstrap v0.26.15
|
||||
k8s.io/component-base => k8s.io/component-base v0.26.15
|
||||
k8s.io/cri-api => k8s.io/cri-api v0.26.15
|
||||
k8s.io/csi-translation-lib => k8s.io/csi-translation-lib v0.26.15
|
||||
k8s.io/klog/v2 => k8s.io/klog/v2 v2.80.1
|
||||
k8s.io/kube-aggregator => k8s.io/kube-aggregator v0.26.15
|
||||
k8s.io/kube-controller-manager => k8s.io/kube-controller-manager v0.26.15
|
||||
k8s.io/kube-proxy => k8s.io/kube-proxy v0.26.15
|
||||
k8s.io/kube-scheduler => k8s.io/kube-scheduler v0.26.15
|
||||
k8s.io/kubelet => k8s.io/kubelet v0.26.15
|
||||
k8s.io/legacy-cloud-providers => k8s.io/legacy-cloud-providers v0.26.15
|
||||
k8s.io/sample-apiserver => k8s.io/sample-apiserver v0.26.15
|
||||
)
|
||||
|
||||
replace github.com/docker/docker => github.com/moby/moby v0.7.3-0.20190826074503-38ab9da00309 // Required by Helm
|
||||
|
||||
replace github.com/Azure/go-autorest => github.com/Azure/go-autorest v14.2.0+incompatible
|
||||
|
||||
replace golang.org/x/net => golang.org/x/net v0.7.0
|
||||
|
|
11
main.go
11
main.go
|
@ -19,12 +19,13 @@ package main
|
|||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/litmuschaos/chaos-operator/pkg/analytics"
|
||||
"github.com/operator-framework/operator-sdk/pkg/k8sutil"
|
||||
"os"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"github.com/litmuschaos/chaos-operator/pkg/analytics"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
|
||||
// to ensure that exec-entrypoint and run can make use of them.
|
||||
_ "k8s.io/client-go/plugin/pkg/client/auth"
|
||||
|
@ -71,9 +72,9 @@ func main() {
|
|||
|
||||
printVersion()
|
||||
|
||||
namespace, err := k8sutil.GetWatchNamespace()
|
||||
if err != nil {
|
||||
setupLog.Error(err, "failed to get watch namespace")
|
||||
namespace, found := os.LookupEnv("WATCH_NAMESPACE")
|
||||
if !found {
|
||||
setupLog.Error(errors.New("WATCH_NAMESPACE env is not set"), "failed to get watch namespace")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
)
|
||||
|
||||
// CreateClientSet returns a Dynamic Kubernetes ClientSet
|
||||
func CreateClientSet() (*dynamic.Interface, error) {
|
||||
func CreateClientSet() (dynamic.Interface, error) {
|
||||
restConfig, err := config.GetConfig()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -15,5 +15,5 @@ func CreateClientSet() (*dynamic.Interface, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &clientSet, nil
|
||||
return clientSet, nil
|
||||
}
|
||||
|
|
|
@ -22,6 +22,9 @@ import (
|
|||
|
||||
// RemoveString removes a particular string from a slice of strings
|
||||
func RemoveString(slice []string, s string) (result []string) {
|
||||
if len(slice) == 0 {
|
||||
return
|
||||
}
|
||||
for _, item := range slice {
|
||||
if item == s {
|
||||
continue
|
||||
|
@ -33,7 +36,7 @@ func RemoveString(slice []string, s string) (result []string) {
|
|||
|
||||
// SetEnv sets the env inside envDetails struct
|
||||
func (envDetails *ENVDetails) SetEnv(key, value string) *ENVDetails {
|
||||
if value != "" {
|
||||
if key != "" && value != "" {
|
||||
envDetails.ENV = append(envDetails.ENV, corev1.EnvVar{
|
||||
Name: key,
|
||||
Value: value,
|
||||
|
|
|
@ -0,0 +1,117 @@
|
|||
/*
|
||||
Copyright 2024 LitmusChaos Authors
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package utils
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"testing"
|
||||
"unicode"
|
||||
|
||||
fuzzheaders "github.com/AdaLogics/go-fuzz-headers"
|
||||
"github.com/stretchr/testify/assert"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
)
|
||||
|
||||
func FuzzSetEnv(f *testing.F) {
|
||||
kv := map[string]string{
|
||||
"KEY1": "VALUE1",
|
||||
"KEY2": "VALUE2",
|
||||
}
|
||||
for k, v := range kv {
|
||||
f.Add(k, v)
|
||||
}
|
||||
f.Fuzz(func(t *testing.T, key, value string) {
|
||||
ed := ENVDetails{
|
||||
ENV: make([]v1.EnvVar, 0),
|
||||
}
|
||||
edUpdated := ed.SetEnv(key, value)
|
||||
if edUpdated == nil {
|
||||
t.Error("nil object not expected")
|
||||
}
|
||||
if key == "" && edUpdated != nil {
|
||||
assert.Equal(t, 0, len(edUpdated.ENV))
|
||||
}
|
||||
if value == "" && edUpdated != nil {
|
||||
assert.Equal(t, 0, len(edUpdated.ENV))
|
||||
}
|
||||
if key != "" && value != "" && edUpdated != nil {
|
||||
assert.Equal(t, 1, len(edUpdated.ENV))
|
||||
}
|
||||
if key != "" && value != "" && edUpdated != nil && len(edUpdated.ENV) == 1 {
|
||||
env := edUpdated.ENV[0]
|
||||
assert.Equal(t, key, env.Name)
|
||||
assert.Equal(t, value, env.Value)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func FuzzRemoveString(f *testing.F) {
|
||||
f.Fuzz(func(t *testing.T, extra string, data []byte) {
|
||||
consumer := fuzzheaders.NewConsumer(data)
|
||||
testInput := &struct {
|
||||
Data map[string]int
|
||||
}{}
|
||||
err := consumer.GenerateStruct(testInput)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
max := len(testInput.Data) - 1
|
||||
if max < 0 {
|
||||
max = 0
|
||||
}
|
||||
randomNumber := func(min, max int) int {
|
||||
if max == 0 {
|
||||
return 0
|
||||
}
|
||||
return rand.Intn(max-min) + min
|
||||
}(0, max)
|
||||
index := 0
|
||||
full := make([]string, 0)
|
||||
exclude := ""
|
||||
result := make([]string, 0)
|
||||
for k := range testInput.Data {
|
||||
if k == "" {
|
||||
continue
|
||||
}
|
||||
if !func() bool {
|
||||
for _, r := range k {
|
||||
if !unicode.IsLetter(r) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}() {
|
||||
continue
|
||||
}
|
||||
full = append(full, k)
|
||||
if index == randomNumber {
|
||||
exclude = k
|
||||
}
|
||||
if index != randomNumber {
|
||||
result = append(result, k)
|
||||
}
|
||||
}
|
||||
if exclude != "" {
|
||||
return
|
||||
}
|
||||
got := RemoveString(full, exclude)
|
||||
if got == nil {
|
||||
got = make([]string, 0)
|
||||
}
|
||||
assert.Equal(t, result, got)
|
||||
})
|
||||
}
|
|
@ -6,11 +6,6 @@ import (
|
|||
corev1 "k8s.io/api/core/v1"
|
||||
)
|
||||
|
||||
var (
|
||||
// hostpathTypeFile represents the hostpath type
|
||||
hostpathTypeFile = corev1.HostPathFile
|
||||
)
|
||||
|
||||
// CreateVolumeBuilders build Volume needed in execution of experiments
|
||||
func CreateVolumeBuilders(configMaps []v1alpha1.ConfigMap, secrets []v1alpha1.Secret) []*volume.Builder {
|
||||
volumeBuilderList := []*volume.Builder{}
|
||||
|
|
Loading…
Reference in New Issue