From 5bffebce1035082c9b072f13a5aecd4d9cfe0699 Mon Sep 17 00:00:00 2001 From: Andreas Thaler Date: Mon, 30 Oct 2023 15:56:52 +0100 Subject: [PATCH] chore: Add github actions for integration tests (#496) --- .github/template/finalize-test/action.yaml | 31 ++++ .github/template/prepare-checks/action.yaml | 13 ++ .github/template/prepare-test/action.yaml | 60 ++++++++ .github/workflows/pull-code-checks.yml | 66 +++++++++ .github/workflows/pull-governance.yml | 24 ++- .github/workflows/pull-integration.yml | 137 ++++++++++++++++++ .github/workflows/push-integration.yml | 33 +++-- .golangci.yaml | 4 + Makefile | 38 +++-- controllers/operator/suite_test.go | 2 +- docs/contributor/governance.md | 6 +- hack/build-image.sh | 7 + ...provision-test-env.sh => provision-k3d.sh} | 5 - 13 files changed, 374 insertions(+), 52 deletions(-) create mode 100644 .github/template/finalize-test/action.yaml create mode 100644 .github/template/prepare-checks/action.yaml create mode 100644 .github/template/prepare-test/action.yaml create mode 100644 .github/workflows/pull-code-checks.yml create mode 100644 .github/workflows/pull-integration.yml create mode 100755 hack/build-image.sh rename hack/{provision-test-env.sh => provision-k3d.sh} (70%) diff --git a/.github/template/finalize-test/action.yaml b/.github/template/finalize-test/action.yaml new file mode 100644 index 000000000..b0fda56ad --- /dev/null +++ b/.github/template/finalize-test/action.yaml @@ -0,0 +1,31 @@ +name: Finalize tests +description: Finalizes integration test execution with cleanup and collecting dumps fors the error scenario + +inputs: + failure: + description: Are we in failure mode? + required: true + +runs: + using: "composite" + + steps: + + - name: Print operator logs + shell: bash + if: ${{ inputs.failure }} + run: | + kubectl -n kyma-system logs -l "app.kubernetes.io/instance=telemetry, app.kubernetes.io/name=operator" + + - name: List Namespaces + shell: bash + if: ${{ inputs.failure }} + run: | + kubectl get namespaces + + - name: List Pods + shell: bash + if: ${{ inputs.failure }} + run: | + kubectl get po --all-namespaces + diff --git a/.github/template/prepare-checks/action.yaml b/.github/template/prepare-checks/action.yaml new file mode 100644 index 000000000..730f0fbd5 --- /dev/null +++ b/.github/template/prepare-checks/action.yaml @@ -0,0 +1,13 @@ +name: Prepare checks +description: Prepares everything for static code check execution + +runs: + using: "composite" + + steps: + # uses an older go version by default, so configure go with newest version + - name: Setup golang + uses: actions/setup-go@v4 + with: + go-version: '1.21' + cache: true diff --git a/.github/template/prepare-test/action.yaml b/.github/template/prepare-test/action.yaml new file mode 100644 index 000000000..1292374e9 --- /dev/null +++ b/.github/template/prepare-test/action.yaml @@ -0,0 +1,60 @@ +name: Prepare test +description: Prepares everything for integration test execution + +inputs: + release: + description: Deploy operator in release mode + required: false + github-token: + description: Github token to use for github access + required: true + +runs: + using: "composite" + + steps: + + # uses an older go version by default, so configure go with newest version + - name: Setup golang + uses: actions/setup-go@v4 + with: + go-version: '1.21' + cache: true + + - name: Provision K3D + shell: bash + run: make provision-k3d + + # wait for the build to succeed so that the manager image is available + - name: Wait for the 'pull-telemetry-manager-build' job to succeed + uses: kyma-project/wait-for-commit-status-action@2b3ffe09af8b6f40e1213d5fb7f91a7bd41ffb20 + with: + context: "pull-telemetry-manager-build" + commit_ref: "${{ github.event.pull_request.head.sha }}" # Note: 'github.event.pull_request.head.sha' is not same as 'github.sha' on pull requests. + timeout: 600000 # 10 minutes in milliseconds + # The check interval is kept long otherwise it will exhaust the GitHub rate limit (More info: https://docs.github.com/en/rest/overview/resources-in-the-rest-api?apiVersion=2022-11-28#rate-limiting) + check_interval: 60000 # 1 minute in milliseconds + env: + GITHUB_TOKEN: "${{ inputs.github-token }}" + GITHUB_OWNER: "${{ github.repository_owner }}" + GITHUB_REPO: "telemetry-manager" + + - name: Deploy module experimental + if: ${{ inputs.release }} + shell: bash + run: make deploy + + - name: Deploy module release + if: ${{ !inputs.release }} + shell: bash + run: make deploy-dev + + - name: Wait for operator readiness + shell: bash + run: kubectl -n kyma-system rollout status deployment telemetry-operator --timeout=90s + + - name: Print cluster info + shell: bash + run: | + kubectl cluster-info + kubectl -n kyma-system get po diff --git a/.github/workflows/pull-code-checks.yml b/.github/workflows/pull-code-checks.yml new file mode 100644 index 000000000..98532debe --- /dev/null +++ b/.github/workflows/pull-code-checks.yml @@ -0,0 +1,66 @@ +name: PR Code checks + +on: + pull_request: + branches: + - "main" + - "release-*" + paths-ignore: + - 'docs/**' + - '**.md' + workflow_dispatch: + +jobs: + unit-tests: + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Prepare test + uses: "./.github/template/prepare-checks" + + - name: Run tests + run: make test + + linting: + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Prepare test + uses: "./.github/template/prepare-checks" + + - name: Run linting + uses: golangci/golangci-lint-action@v3 + with: + install-mode: binary + version: latest + args: --timeout=5m --config=./.golangci.yaml + + verify-manifests: + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Prepare test + uses: "./.github/template/prepare-checks" + + - name: Verify manifests + run: make lint-manifests + + markdown-link-check: + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Validate links + uses: gaurav-nelson/github-action-markdown-link-check@v1 + with: + use-verbose-mode: 'no' + config-file: '.mlc.config.json' + folder-path: '.' + max-depth: -1 diff --git a/.github/workflows/pull-governance.yml b/.github/workflows/pull-governance.yml index 22bbfb8c5..10ecca7b0 100644 --- a/.github/workflows/pull-governance.yml +++ b/.github/workflows/pull-governance.yml @@ -1,18 +1,23 @@ -name: Governance -run-name: ${{github.event.pull_request.title}} +name: PR Governance + on: pull_request_target: + branches: + - "main" + - "release-*" types: - opened - reopened - edited - synchronize + workflow_dispatch: + jobs: pr-title-check: - name: Check PR Title runs-on: ubuntu-latest steps: - - uses: amannn/action-semantic-pull-request@47b15d52c5c30e94a17ec87eb8dd51ff5221fed9 + - name: Validate title + uses: amannn/action-semantic-pull-request@47b15d52c5c30e94a17ec87eb8dd51ff5221fed9 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: @@ -26,14 +31,3 @@ jobs: requireScope: false # https://regex101.com/r/O5OZvC/1 subjectPattern: ^([A-Z].*[^.]|bump .*)$ - markdown-link-check: - name: Check Markdown Links - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: gaurav-nelson/github-action-markdown-link-check@v1 - with: - use-verbose-mode: 'no' - config-file: '.mlc.config.json' - folder-path: '.' - max-depth: -1 diff --git a/.github/workflows/pull-integration.yml b/.github/workflows/pull-integration.yml new file mode 100644 index 000000000..e4bb0dfe5 --- /dev/null +++ b/.github/workflows/pull-integration.yml @@ -0,0 +1,137 @@ +name: PR Integration + +env: + IMG: europe-docker.pkg.dev/kyma-project/dev/telemetry-manager:PR-${{ github.event.number }} + +on: + pull_request: + branches: + - "main" + - "release-*" + paths-ignore: + - 'docs/**' + - '**.md' + workflow_dispatch: + +jobs: + e2e-metrics: + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Prepare test + uses: "./.github/template/prepare-test" + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + + - name: Run tests + run: make run-e2e-test-metrics + + - name: Finalize test + uses: "./.github/template/finalize-test" + if: success() || failure() + with: + failure: failure() + + e2e-traces-release: + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Prepare Test + uses: "./.github/template/prepare-test" + with: + release: true + github-token: ${{ secrets.GITHUB_TOKEN }} + + - name: Run tests + run: make run-e2e-test-tracing + + - name: Finalize Test + uses: "./.github/template/finalize-test" + if: success() || failure() + with: + failure: failure() + + e2e-traces: + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Prepare Test + uses: "./.github/template/prepare-test" + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + + - name: Run tests + run: make run-e2e-test-tracing + + - name: Finalize Test + uses: "./.github/template/finalize-test" + if: success() || failure() + with: + failure: failure() + + e2e-logs-release: + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Prepare Test + uses: "./.github/template/prepare-test" + with: + release: true + github-token: ${{ secrets.GITHUB_TOKEN }} + + - name: Run tests + run: make run-e2e-test-logging + + - name: Finalize Test + uses: "./.github/template/finalize-test" + if: success() || failure() + with: + failure: failure() + + e2e-logs: + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Prepare Test + uses: "./.github/template/prepare-test" + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + + - name: Run tests + run: make run-e2e-test-logging + + - name: Finalize Test + uses: "./.github/template/finalize-test" + if: success() || failure() + with: + failure: failure() + + e2e-integration-istio: + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Prepare Test + uses: "./.github/template/prepare-test" + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + + - name: Run tests + run: make run-integration-test-istio + + - name: Finalize Test + uses: "./.github/template/finalize-test" + if: success() || failure() + with: + failure: failure() diff --git a/.github/workflows/push-integration.yml b/.github/workflows/push-integration.yml index d8892fa2c..f62a0f65c 100644 --- a/.github/workflows/push-integration.yml +++ b/.github/workflows/push-integration.yml @@ -1,21 +1,25 @@ -name: Integration +name: Branch Integration on: push: - branches: [ "main", "release-*" ] - + branches: + - "main" + - "release-*" + paths-ignore: + - 'docs/**' + - '**.md' workflow_dispatch: jobs: gardener-integration-test: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 + - name: Checkout repo + uses: actions/checkout@v4 # uses an older go version by default, so configure go with newest version - - uses: actions/setup-go@v4 + - name: Setup go + uses: actions/setup-go@v4 with: go-version: '1.21' cache: true @@ -35,23 +39,22 @@ jobs: GITHUB_REPO: "telemetry-manager" # save gardener kubeconfig to a temp file in order to pass it to the command - - name: save sa + - name: Save serviceaccount to file shell: bash run: 'echo "$GARDENER_SA" > /tmp/gardener-sa.yaml' env: GARDENER_SA: ${{ secrets.GARDENER_SA }} # provision cluster and run tests - - name: | - run integration tests + - name: Run test run: make gardener-integration-test env: GARDENER_SECRET_NAME: ${{ secrets.GARDENER_SECRET_NAME }} GARDENER_PROJECT: ${{ secrets.GARDENER_PROJECT }} GARDENER_SA_PATH: /tmp/gardener-sa.yaml - - uses: actions/upload-artifact@v3 - if: success() || failure() # run this step even if previous step failed - with: - name: test-results - path: '**/artifacts/*-junit.xml' + - name: Send slack message on failure + uses: slackapi/slack-github-action@e28cf165c92ffef168d23c5c9000cffc8a25e117 + if: failure() + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} diff --git a/.golangci.yaml b/.golangci.yaml index 3aa10bc7b..4e74595d0 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -84,6 +84,10 @@ linters-settings: allow-unused: true require-explanation: true require-specific: true + revive: + rules: + - name: dot-imports + disabled: true issues: exclude: diff --git a/Makefile b/Makefile index a9e983970..b2638f0df 100644 --- a/Makefile +++ b/Makefile @@ -45,17 +45,16 @@ help: ## Display this help. @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) ##@ Development -lint-autofix: ## Autofix all possible linting errors. - golangci-lint run -E goimports --fix +lint-autofix: golangci-lint ## Autofix all possible linting errors. + ${GOLANGCI-LINT} run -E goimports --fix lint-manifests: hack/lint-manifests.sh -lint: lint-manifests +lint: golangci-lint lint-manifests go version - golangci-lint version - GO111MODULE=on golangci-lint run - + ${GOLANGCI-LINT} version + GO111MODULE=on ${GOLANGCI-LINT} run .PHONY: crd-docs-gen crd-docs-gen: tablegen ## Generates CRD spec into docs folder @@ -98,36 +97,40 @@ test-matchers: ginkgo $(GINKGO) run ./test/testkit/matchers/... .PHONY: provision-test-env -provision-test-env: - K8S_VERSION=$(ENVTEST_K8S_VERSION) hack/provision-test-env.sh +provision-test-env: provision-k3d + K8S_VERSION=$(ENVTEST_K8S_VERSION) hack/build-image.sh + +.PHONY: provision-k3d +provision-k3d: k3d + K8S_VERSION=$(ENVTEST_K8S_VERSION) hack/provision-k3d.sh .PHONY: e2e-test -e2e-test: k3d provision-test-env ## Provision k3d cluster and run end-to-end tests. +e2e-test: provision-test-env ## Provision k3d cluster and run end-to-end tests. IMG=k3d-kyma-registry:5000/telemetry-manager:latest make deploy-dev make run-e2e-test .PHONY: e2e-test-logging -e2e-test-logging: k3d provision-test-env ## Provision k3d cluster, deploy development variant and run end-to-end logging tests. +e2e-test-logging: provision-test-env ## Provision k3d cluster, deploy development variant and run end-to-end logging tests. IMG=k3d-kyma-registry:5000/telemetry-manager:latest make deploy-dev make run-e2e-test-logging .PHONY: e2e-test-tracing -e2e-test-tracing: k3d provision-test-env ## Provision k3d cluster, deploy development variant and run end-to-end tracing tests. +e2e-test-tracing: provision-test-env ## Provision k3d cluster, deploy development variant and run end-to-end tracing tests. IMG=k3d-kyma-registry:5000/telemetry-manager:latest make deploy-dev make run-e2e-test-tracing .PHONY: e2e-test-metrics -e2e-test-metrics: k3d provision-test-env ## Provision k3d cluster, deploy development variant and run end-to-end metrics tests. +e2e-test-metrics: provision-test-env ## Provision k3d cluster, deploy development variant and run end-to-end metrics tests. IMG=k3d-kyma-registry:5000/telemetry-manager:latest make deploy-dev make run-e2e-test-metrics .PHONY: e2e-test-logging-release -e2e-test-logging-release: k3d provision-test-env ## Provision k3d cluster, deploy release (default) variant and run end-to-end logging tests. +e2e-test-logging-release: provision-test-env ## Provision k3d cluster, deploy release (default) variant and run end-to-end logging tests. IMG=k3d-kyma-registry:5000/telemetry-manager:latest make deploy make run-e2e-test-logging .PHONY: e2e-test-tracing-release -e2e-test-tracing-release: k3d provision-test-env ## Provision k3d cluster, deploy release (default) variant and run end-to-end tracing tests. +e2e-test-tracing-release: provision-test-env ## Provision k3d cluster, deploy release (default) variant and run end-to-end tracing tests. IMG=k3d-kyma-registry:5000/telemetry-manager:latest make deploy make run-e2e-test-tracing @@ -263,6 +266,7 @@ TABLE_GEN ?= $(LOCALBIN)/table-gen CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen ENVTEST ?= $(LOCALBIN)/setup-envtest GINKGO ?= $(LOCALBIN)/ginkgo +GOLANGCI-LINT ?= $(LOCALBIN)/golangci-lint K3D ?= $(LOCALBIN)/k3d KYMA ?= $(LOCALBIN)/kyma-$(KYMA_STABILITY) @@ -273,6 +277,7 @@ CONTROLLER_TOOLS_VERSION ?= v0.11.3 K3D_VERSION ?= v5.4.7 GINKGO_VERSION ?= v2.13.0 GORELEASER_VERSION ?= v1.17.1 +GOLANGCI-LINT_VERSION ?= latest KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" .PHONY: kustomize @@ -300,6 +305,11 @@ tablegen: $(TABLE_GEN) ## Download table-gen locally if necessary. $(TABLE_GEN): $(LOCALBIN) test -s $(TABLE_GEN) || GOBIN=$(LOCALBIN) go install github.com/kyma-project/kyma/hack/table-gen@$(TABLE_GEN_VERSION) +.PHONY: golangci-lint +golangci-lint: $(GOLANGCI-LINT) ## Download golangci-lint locally if necessary. +$(GOLANGCI-LINT): $(LOCALBIN) + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(LOCALBIN) $(GOLANGCI-LINT_VERSION) + .PHONY: ginkgo ginkgo: $(GINKGO) ## Download ginkgo locally if necessary. $(GINKGO): $(LOCALBIN) diff --git a/controllers/operator/suite_test.go b/controllers/operator/suite_test.go index 89f3598c0..4e883ec48 100644 --- a/controllers/operator/suite_test.go +++ b/controllers/operator/suite_test.go @@ -91,7 +91,7 @@ var _ = BeforeSuite(func() { Port: 19443, Host: "localhost", }), - HealthProbeBindAddress: "localhost:8084", + HealthProbeBindAddress: "localhost:8088", LeaderElection: false, LeaderElectionID: "cdd7ef0a.kyma-project.io", }) diff --git a/docs/contributor/governance.md b/docs/contributor/governance.md index 7673bb2a8..4ed2adbe0 100644 --- a/docs/contributor/governance.md +++ b/docs/contributor/governance.md @@ -11,15 +11,17 @@ To achieve both aspects, call: make manifests ``` -Additionally, a [ProwJob](https://github.com/kyma-project/test-infra/blob/main/prow/jobs/telemetry-manager/telemetry-manager-generic.yaml#L6) verifies this operation. +Additionally, a [Github Action](./../../.github/workflows/pull-code-checks.yml) verifies this operation. ## Sourcecode linting For the source code linting, the development team uses [golangci-lint](https://golangci-lint.run) with fine-grained configuration. +Additionally, a [Github Action](./../../.github/workflows/pull-code-checks.yml) verifies this operation. + ### Linters in action -The following linters are configured and integrated as a CI stage using a [ProwJob](https://github.com/kyma-project/test-infra/blob/main/prow/jobs/kyma/components/kyma-components-static-checks.yaml#L6). +The following linters are configured and integrated as a CI stage using a [Github Action](./../../.github/workflows/pull-code-checks.yml).
List of linters diff --git a/hack/build-image.sh b/hack/build-image.sh new file mode 100755 index 000000000..5ed525588 --- /dev/null +++ b/hack/build-image.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env sh + +IMG=localhost:5001/telemetry-manager:latest +export IMG + +make docker-build +make docker-push diff --git a/hack/provision-test-env.sh b/hack/provision-k3d.sh similarity index 70% rename from hack/provision-test-env.sh rename to hack/provision-k3d.sh index 4bb047126..44ae13309 100755 --- a/hack/provision-test-env.sh +++ b/hack/provision-k3d.sh @@ -3,9 +3,4 @@ bin/k3d registry create kyma-registry --port 5001 bin/k3d cluster create kyma --registry-use kyma-registry:5001 --image rancher/k3s:v$K8S_VERSION-k3s1 --api-port 6550 -IMG=localhost:5001/telemetry-manager:latest -export IMG - -make docker-build -make docker-push kubectl create ns kyma-system