From 8c7f037c7231cfe2d2223d68b7ba8046a0a4fdf5 Mon Sep 17 00:00:00 2001 From: Sambhav Kothari Date: Fri, 18 Feb 2022 01:47:35 +0000 Subject: [PATCH] Improve E2E test CI timings (#3250) Signed-off-by: Sambhav Kothari --- .github/workflows/cli.yaml | 63 +++++++++++++ .github/workflows/e2e.yaml | 42 +-------- .../{build.yaml => image-build.yaml} | 34 +------ .github/workflows/tests.yaml | 93 +++++++++++++++++++ Makefile | 6 +- 5 files changed, 162 insertions(+), 76 deletions(-) create mode 100644 .github/workflows/cli.yaml rename .github/workflows/{build.yaml => image-build.yaml} (84%) create mode 100644 .github/workflows/tests.yaml diff --git a/.github/workflows/cli.yaml b/.github/workflows/cli.yaml new file mode 100644 index 0000000000..7ddbf5edf1 --- /dev/null +++ b/.github/workflows/cli.yaml @@ -0,0 +1,63 @@ +name: cli +on: + push: + branches: + - 'main' + - 'release*' + paths-ignore: + - 'README.md' + - 'docs/**' + - '.github/config.yml' + pull_request: + branches: + - 'main' + - 'release*' + paths-ignore: + - 'README.md' + - 'docs/**' + - '.github/config.yml' + +permissions: read-all + +jobs: + cli-test: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579 # v2.4.0 + + - name: Unshallow + run: git fetch --prune --unshallow + + - name: Set up Go + uses: actions/setup-go@424fc82d43fa5a37540bae62709ddcc23d9520d4 # v2.1.5 + with: + go-version: 1.17 + + - name: Cache Go modules + uses: actions/cache@d9747005de0f7240e5d35a68dca96b3f41b8b340 # v1.2.0 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Test Policy + run: | + if [[ ${{ github.event_name }} == "push" ]] + then + GIT_BRANCH=${GITHUB_REF##*/} + elif [[ ${{ github.event_name }} == "pull_request" ]] + then + GIT_BRANCH=${{ github.event.pull_request.base.ref }} + fi + make cli + CLI_PATH=$PWD/cmd/cli/kubectl-kyverno/kyverno + $CLI_PATH test https://github.com/kyverno/policies/$GIT_BRANCH + $CLI_PATH test https://github.com/kyverno/policies --git-branch $GIT_BRANCH + $CLI_PATH test https://github.com/kyverno/policies/pod-security/restricted -b $GIT_BRANCH + $CLI_PATH test ./test/cli/test-mutate + $CLI_PATH test ./test/cli/test + $CLI_PATH test ./test/cli/test-fail/missing-policy && exit 1 || exit 0 + $CLI_PATH test ./test/cli/test-fail/missing-rule && exit 1 || exit 0 + $CLI_PATH test ./test/cli/test-fail/missing-resource && exit 1 || exit 0 diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index 84b0b14610..beef73c8f5 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -50,47 +50,9 @@ jobs: restore-keys: | ${{ runner.os }}-go- - - name: Test Policy + - name : Create dev images, kind cluster and setup kustomize run: | - if [[ ${{ github.event_name }} == "push" ]] - then - GIT_BRANCH=${GITHUB_REF##*/} - elif [[ ${{ github.event_name }} == "pull_request" ]] - then - GIT_BRANCH=${{ github.event.pull_request.base.ref }} - fi - - CLI_PATH=cmd/cli/kubectl-kyverno - - go run $PWD/$CLI_PATH/main.go test https://github.com/kyverno/policies/$GIT_BRANCH - go run $PWD/$CLI_PATH/main.go test https://github.com/kyverno/policies --git-branch $GIT_BRANCH - go run $PWD/$CLI_PATH/main.go test https://github.com/kyverno/policies/pod-security/restricted -b $GIT_BRANCH - go run $PWD/$CLI_PATH/main.go test ./test/cli/test-mutate - go run $PWD/$CLI_PATH/main.go test ./test/cli/test - go run $PWD/$CLI_PATH/main.go test ./test/cli/test-fail/missing-policy && exit 1 || exit 0 - go run $PWD/$CLI_PATH/main.go test ./test/cli/test-fail/missing-rule && exit 1 || exit 0 - go run $PWD/$CLI_PATH/main.go test ./test/cli/test-fail/missing-resource && exit 1 || exit 0 - - - name: gofmt check - run: | - if [ "$(gofmt -s -l . | wc -l)" -ne 0 ] - then - echo "The following files were found to be not go formatted:" - gofmt -s -l . - echo "Please run 'make fmt' to go format the above files." - exit 1 - fi - - - name: golangci-lint - uses: reviewdog/action-golangci-lint@02bcf8c1a9febe8620f1ca523b18dd64f82296db # v1.25.0 - - - name: docker images build (AMD64) - run: | - make docker-build-all-amd64 - - - name : Create Kind Cluster and setup kustomize - run: | - make create-e2e-infrastruture + make -j4 create-e2e-infrastruture - name: e2e testing run: | diff --git a/.github/workflows/build.yaml b/.github/workflows/image-build.yaml similarity index 84% rename from .github/workflows/build.yaml rename to .github/workflows/image-build.yaml index b8cca30c54..a1a8e98452 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/image-build.yaml @@ -1,13 +1,9 @@ -name: build +name: image-build on: push: branches: - 'main' - 'release*' - pull_request: - branches: - - 'main' - - 'release*' permissions: contents: read @@ -172,31 +168,3 @@ jobs: - name: docker images build run: | make docker-build-cli - - tests: - runs-on: ubuntu-latest - needs: pre-checks - steps: - - name: Checkout - uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579 # v2.4.0 - - - name: Unshallow - run: git fetch --prune --unshallow - - - name: Set up Go - uses: actions/setup-go@424fc82d43fa5a37540bae62709ddcc23d9520d4 # v2.1.5 - with: - go-version: 1.17 - - - name: Cache Go modules - uses: actions/cache@d9747005de0f7240e5d35a68dca96b3f41b8b340 # v1.2.0 - with: - path: ~/go/pkg/mod - key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} - restore-keys: | - ${{ runner.os }}-go- - - - name: Kyverno unit test - run: | - export PROJECT_PATH=$(pwd) - make test-unit diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml new file mode 100644 index 0000000000..c04c070382 --- /dev/null +++ b/.github/workflows/tests.yaml @@ -0,0 +1,93 @@ +name: tests +on: + push: + branches: + - 'main' + - 'release*' + pull_request: + branches: + - 'main' + - 'release*' + +permissions: + contents: read + packages: write + id-token: write + +jobs: + pre-checks: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579 # v2.4.0 + + - name: Unshallow + run: git fetch --prune --unshallow + + - name: Set up Go + uses: actions/setup-go@424fc82d43fa5a37540bae62709ddcc23d9520d4 # v2.1.5 + with: + go-version: 1.17 + + - name: Cache Go modules + uses: actions/cache@d9747005de0f7240e5d35a68dca96b3f41b8b340 # v1.2.0 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: gofmt check + run: | + if [ "$(gofmt -s -l . | wc -l)" -ne 0 ] + then + echo "The following files were found to be not go formatted:" + gofmt -s -l . + echo "Please run 'make fmt' to go format the above files." + exit 1 + fi + + - name: goimports + run: | + if [ "$(goimports -l . | wc -l)" -ne 0 ] + then + echo "The following files were found to have import formatting issues:" + goimports -l -l . + echo "Please run 'make fmt' to go format the above files." + exit 1 + fi + + - name: golangci-lint + uses: reviewdog/action-golangci-lint@02bcf8c1a9febe8620f1ca523b18dd64f82296db # v1.25.0 + + - name: Checking unused pkgs using go mod tidy + run: | + make unused-package-check + + tests: + runs-on: ubuntu-latest + needs: pre-checks + steps: + - name: Checkout + uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579 # v2.4.0 + + - name: Unshallow + run: git fetch --prune --unshallow + + - name: Set up Go + uses: actions/setup-go@424fc82d43fa5a37540bae62709ddcc23d9520d4 # v2.1.5 + with: + go-version: 1.17 + + - name: Cache Go modules + uses: actions/cache@d9747005de0f7240e5d35a68dca96b3f41b8b340 # v1.2.0 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Kyverno unit test + run: | + export PROJECT_PATH=$(pwd) + make test-unit diff --git a/Makefile b/Makefile index df1b8803f5..b230e8ec63 100644 --- a/Makefile +++ b/Makefile @@ -78,8 +78,8 @@ docker-get-initContainer-digest: docker-build-initContainer-local: CGO_ENABLED=0 GOOS=linux go build -o $(PWD)/$(INITC_PATH)/kyvernopre -ldflags=$(LD_FLAGS) $(PWD)/$(INITC_PATH)/main.go - @docker build -f $(PWD)/$(INITC_PATH)/localDockerfile -t $(REPO)/$(INITC_IMAGE):$(IMAGE_TAG) $(PWD)/$(INITC_PATH) - @docker tag $(REPO)/$(INITC_IMAGE):$(IMAGE_TAG) $(REPO)/$(INITC_IMAGE):latest + @docker build -f $(PWD)/$(INITC_PATH)/localDockerfile -t $(REPO)/$(INITC_IMAGE):$(IMAGE_TAG_DEV) $(PWD)/$(INITC_PATH) + @docker tag $(REPO)/$(INITC_IMAGE):$(IMAGE_TAG_DEV) $(REPO)/$(INITC_IMAGE):latest docker-publish-initContainer-dev: docker-buildx-builder docker-push-initContainer-dev @@ -187,7 +187,7 @@ docker-build-all-amd64: docker-buildx-builder docker-build-initContainer-amd64 d # Create e2e Infrastruture ################################## -create-e2e-infrastruture: +create-e2e-infrastruture: docker-build-initContainer-local docker-build-kyverno-local chmod a+x $(PWD)/scripts/create-e2e-infrastruture.sh $(PWD)/scripts/create-e2e-infrastruture.sh