diff --git a/.env b/.env new file mode 100644 index 000000000..7d631b2cb --- /dev/null +++ b/.env @@ -0,0 +1,18 @@ +### Default Environment Variables +## General +ENV_ENVTEST_K8S_VERSION=1.27.1 # ENVTEST_K8S_VERSION refers to the version of Kubebuilder assets to be downloaded by envtest binary. +ENV_IMG=europe-docker.pkg.dev/kyma-project/prod/telemetry-manager:main # Image URL to use all building/pushing image targets + +## Gardener +ENV_GARDENER_K8S_VERSION=1.27 +ENV_GARDENER_OS_VERSION="Not Defined" + +## Dependencies +ENV_CONTROLLER_TOOLS_VERSION=v0.11.3 +ENV_GINKGO_VERSION=v2.15.0 +ENV_GO_TEST_COVERAGE_VERSION=v2.8.2 +ENV_GOLANGCI-LINT_VERSION=latest +ENV_ISTIO_VERSION=1.3.2 +ENV_K3D_VERSION=v5.4.7 +ENV_KUSTOMIZE_VERSION=v5.0.1 +ENV_TABLE_GEN_VERSION=v0.0.0-20230523174756-3dae9f177ffd diff --git a/.github/template/prepare-test/action.yaml b/.github/template/prepare-test/action.yaml index 93e9b4f98..8050137e5 100644 --- a/.github/template/prepare-test/action.yaml +++ b/.github/template/prepare-test/action.yaml @@ -13,10 +13,13 @@ runs: using: "composite" steps: - - name: Setup Golang uses: "./.github/template/setup-golang" + - name: Setup Ginkgo + shell: bash + run: make ginkgo + - name: Provision K3D shell: bash run: make provision-k3d @@ -51,6 +54,6 @@ runs: - name: Print cluster info shell: bash - run: | + run: | kubectl cluster-info kubectl -n kyma-system get po diff --git a/.github/workflows/branch-integration.yml b/.github/workflows/branch-integration.yml index 5a486932c..650258fb5 100644 --- a/.github/workflows/branch-integration.yml +++ b/.github/workflows/branch-integration.yml @@ -47,7 +47,7 @@ jobs: # provision cluster and run tests - name: Run test - run: make gardener-integration-test + run: hack/gardener-integration-test.sh env: GARDENER_SECRET_NAME: ${{ secrets.GARDENER_SECRET_NAME }} GARDENER_PROJECT: ${{ secrets.GARDENER_PROJECT }} diff --git a/.github/workflows/pr-integration.yml b/.github/workflows/pr-integration.yml index d8e9f8c2e..e27382b45 100644 --- a/.github/workflows/pr-integration.yml +++ b/.github/workflows/pr-integration.yml @@ -9,8 +9,8 @@ on: - "main" - "release-*" paths-ignore: - - 'docs/**' - - '**.md' + - "docs/**" + - "**.md" workflow_dispatch: jobs: @@ -27,7 +27,7 @@ jobs: github-token: ${{ secrets.GITHUB_TOKEN }} - name: Run tests - run: make run-e2e-test-metrics + run: bin/ginkgo run --tags e2e --label-filter="metrics" test/e2e - name: Finalize test uses: "./.github/template/finalize-test" @@ -38,104 +38,104 @@ jobs: e2e-metrics: runs-on: ubuntu-latest steps: - - name: Checkout repo - uses: actions/checkout@v4 + - name: Checkout repo + uses: actions/checkout@v4 - - name: Prepare test - uses: "./.github/template/prepare-test" - with: - github-token: ${{ secrets.GITHUB_TOKEN }} + - name: Prepare test + uses: "./.github/template/prepare-test" + with: + github-token: ${{ secrets.GITHUB_TOKEN }} - - name: Run tests - run: make run-e2e-test-metrics + - name: Run tests + run: bin/ginkgo run --tags e2e --label-filter="metrics" test/e2e - - name: Finalize test - uses: "./.github/template/finalize-test" - if: success() || failure() - with: - failure: failure() + - 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: Checkout repo + uses: actions/checkout@v4 - - name: Prepare Test - uses: "./.github/template/prepare-test" - with: - release: true - github-token: ${{ secrets.GITHUB_TOKEN }} + - name: Prepare Test + uses: "./.github/template/prepare-test" + with: + release: true + github-token: ${{ secrets.GITHUB_TOKEN }} - - name: Run tests - run: make run-e2e-test-traces + - name: Run tests + run: bin/ginkgo run --tags e2e --label-filter="traces" test/e2e - - name: Finalize Test - uses: "./.github/template/finalize-test" - if: success() || failure() - with: - failure: failure() + - 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: Checkout repo + uses: actions/checkout@v4 - - name: Prepare Test - uses: "./.github/template/prepare-test" - with: - github-token: ${{ secrets.GITHUB_TOKEN }} + - name: Prepare Test + uses: "./.github/template/prepare-test" + with: + github-token: ${{ secrets.GITHUB_TOKEN }} - - name: Run tests - run: make run-e2e-test-traces + - name: Run tests + run: bin/ginkgo run --tags e2e --label-filter="traces" test/e2e - - name: Finalize Test - uses: "./.github/template/finalize-test" - if: success() || failure() - with: - failure: failure() + - 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: Checkout repo + uses: actions/checkout@v4 - - name: Prepare Test - uses: "./.github/template/prepare-test" - with: - release: true - github-token: ${{ secrets.GITHUB_TOKEN }} + - name: Prepare Test + uses: "./.github/template/prepare-test" + with: + release: true + github-token: ${{ secrets.GITHUB_TOKEN }} - - name: Run tests - run: make run-e2e-test-logs + - name: Run tests + run: bin/ginkgo run --tags e2e --label-filter="logs" test/e2e - - name: Finalize Test - uses: "./.github/template/finalize-test" - if: success() || failure() - with: - failure: failure() + - 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: Checkout repo + uses: actions/checkout@v4 - - name: Prepare Test - uses: "./.github/template/prepare-test" - with: - github-token: ${{ secrets.GITHUB_TOKEN }} + - name: Prepare Test + uses: "./.github/template/prepare-test" + with: + github-token: ${{ secrets.GITHUB_TOKEN }} - - name: Run tests - run: make run-e2e-test-logs + - name: Run tests + run: bin/ginkgo run --tags e2e --label-filter="logs" test/e2e - - name: Finalize Test - uses: "./.github/template/finalize-test" - if: success() || failure() - with: - failure: failure() + - name: Finalize Test + uses: "./.github/template/finalize-test" + if: success() || failure() + with: + failure: failure() e2e-telemetry-release: runs-on: ubuntu-latest @@ -150,7 +150,7 @@ jobs: github-token: ${{ secrets.GITHUB_TOKEN }} - name: Run tests - run: make run-e2e-test-telemetry + run: bin/ginkgo run --tags e2e --label-filter="telemetry" test/e2e - name: Finalize Test uses: "./.github/template/finalize-test" @@ -170,7 +170,7 @@ jobs: github-token: ${{ secrets.GITHUB_TOKEN }} - name: Run tests - run: make run-e2e-test-telemetry + run: bin/ginkgo run --tags e2e --label-filter="telemetry" test/e2e - name: Finalize Test uses: "./.github/template/finalize-test" @@ -181,19 +181,21 @@ jobs: 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() + - 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: | + hack/deploy-istio.sh + bin/ginkgo run --tags istio test/integration/istio + + - name: Finalize Test + uses: "./.github/template/finalize-test" + if: success() || failure() + with: + failure: failure() diff --git a/.github/workflows/pr-lifecycle.yml b/.github/workflows/pr-lifecycle.yml index 28e219cd3..c819528b1 100644 --- a/.github/workflows/pr-lifecycle.yml +++ b/.github/workflows/pr-lifecycle.yml @@ -6,80 +6,84 @@ on: - "main" - "release-*" paths-ignore: - - 'docs/**' - - '**.md' + - "docs/**" + - "**.md" workflow_dispatch: jobs: manager-upgrade: runs-on: ubuntu-latest steps: - - name: Checkout repo - uses: actions/checkout@v4 + - name: Checkout repo + uses: actions/checkout@v4 - - name: Setup Golang - uses: "./.github/template/setup-golang" + - name: Setup Golang + uses: "./.github/template/setup-golang" - - name: Provision K3D - shell: bash - run: make provision-k3d + - name: Provision K3D + shell: bash + run: make provision-k3d - - name: Deploy with latest tag - shell: bash - run: | - git fetch --tags - LATEST_TAG=$(git tag --sort=-creatordate | sed -n 1p) - echo "Using tag ${LATEST_TAG}" - git checkout ${LATEST_TAG} - GIT_COMMIT_SHA=$(git rev-parse --short=8 HEAD) - GIT_COMMIT_DATE=$(git show -s --format=%cd --date=format:'v%Y%m%d' ${GIT_COMMIT_SHA}) - echo "Deploying Manager using image europe-docker.pkg.dev/kyma-project/prod/telemetry-manager:${GIT_COMMIT_DATE}-${GIT_COMMIT_SHA}" - IMG=europe-docker.pkg.dev/kyma-project/prod/telemetry-manager:${GIT_COMMIT_DATE}-${GIT_COMMIT_SHA} make deploy-dev + - name: Deploy with latest tag + shell: bash + run: | + git fetch --tags + LATEST_TAG=$(git tag --sort=-creatordate | sed -n 1p) + echo "Using tag ${LATEST_TAG}" + git checkout ${LATEST_TAG} + GIT_COMMIT_SHA=$(git rev-parse --short=8 HEAD) + GIT_COMMIT_DATE=$(git show -s --format=%cd --date=format:'v%Y%m%d' ${GIT_COMMIT_SHA}) + echo "Deploying Manager using image europe-docker.pkg.dev/kyma-project/prod/telemetry-manager:${GIT_COMMIT_DATE}-${GIT_COMMIT_SHA}" + IMG=europe-docker.pkg.dev/kyma-project/prod/telemetry-manager:${GIT_COMMIT_DATE}-${GIT_COMMIT_SHA} make deploy-dev - - name: Wait for manager readiness - shell: bash - run: kubectl -n kyma-system rollout status deployment telemetry-manager --timeout=90s + - name: Wait for manager readiness + shell: bash + run: kubectl -n kyma-system rollout status deployment telemetry-manager --timeout=90s - - name: Run test on latest tag - shell: bash - run: make run-upgrade-test + - name: Run test on latest tag + shell: bash + run: | + make ginkgo + bin/ginkgo run --tags e2e --flake-attempts=5 --label-filter="operational" -v test/e2e - - name: Wait for cleanup of test run - shell: bash - run: hack/wait-for-namespaces.sh + - name: Wait for cleanup of test run + shell: bash + run: hack/wait-for-namespaces.sh - - name: Switch back to current revision - uses: actions/checkout@v4 + - name: Switch back to current revision + uses: actions/checkout@v4 - # 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: "${{ secrets.GITHUB_TOKEN }}" - GITHUB_OWNER: "${{ github.repository_owner }}" - GITHUB_REPO: "telemetry-manager" + # 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: "${{ secrets.GITHUB_TOKEN }}" + GITHUB_OWNER: "${{ github.repository_owner }}" + GITHUB_REPO: "telemetry-manager" - - name: Deploy with current version - shell: bash - run: | - IMG=europe-docker.pkg.dev/kyma-project/dev/telemetry-manager:PR-${{ github.event.number }} make deploy-dev + - name: Deploy with current version + shell: bash + run: | + IMG=europe-docker.pkg.dev/kyma-project/dev/telemetry-manager:PR-${{ github.event.number }} make deploy-dev - - name: Wait for manager readiness - shell: bash - run: kubectl -n kyma-system rollout status deployment telemetry-manager --timeout=90s + - name: Wait for manager readiness + shell: bash + run: kubectl -n kyma-system rollout status deployment telemetry-manager --timeout=90s - - name: Run test on current version - shell: bash - run: make run-upgrade-test + - name: Run test on current version + shell: bash + run: | + make ginkgo + bin/ginkgo run --tags e2e --flake-attempts=5 --label-filter="operational" -v test/e2e - - name: Finalize test - uses: "./.github/template/finalize-test" - if: success() || failure() - with: - failure: failure() + - name: Finalize test + uses: "./.github/template/finalize-test" + if: success() || failure() + with: + failure: failure() diff --git a/.github/workflows/tag-release.yml b/.github/workflows/tag-release.yml index 019883293..c10e21f99 100644 --- a/.github/workflows/tag-release.yml +++ b/.github/workflows/tag-release.yml @@ -28,7 +28,7 @@ jobs: GITHUB_REPO: "telemetry-manager" - name: Release - run: make release + run: hack/release.sh env: GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" GORELEASER_CURRENT_TAG: "${{ github.ref_name }}" # Explicitly set release tag to do not use -dev tag diff --git a/Makefile b/Makefile index 86ada4aae..6e61048bc 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,8 @@ -# Image URL to use all building/pushing image targets -IMG ?= europe-docker.pkg.dev/kyma-project/prod/telemetry-manager:main -# ENVTEST_K8S_VERSION refers to the version of Kubebuilder assets to be downloaded by envtest binary. +include .env -ENVTEST_K8S_VERSION = 1.27.1 -GARDENER_K8S_VERSION ?= 1.27 -GARDENER_OS_VERSION ?= Not Defined -ISTIO_VERSION ?= 1.3.2 +# Environment Variables +IMG ?= $(ENV_IMG) +ENVTEST_K8S_VERSION ?= $(ENV_ENVTEST_K8S_VERSION) # Operating system architecture OS_ARCH ?= $(shell uname -m) @@ -30,8 +27,13 @@ SHELL = /usr/bin/env bash -o pipefail .PHONY: all all: build -##@ General +# Sub-makefiles +MAKE_DEPS ?= hack/make +include ${MAKE_DEPS}/dependencies.mk +include ${MAKE_DEPS}/provision.mk + +##@ General # The help target prints out all targets with their descriptions organized # beneath their categories. The categories are represented by '##@' and the # target descriptions by '##'. The awk commands is responsible for reading the @@ -47,6 +49,7 @@ all: build 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: golangci-lint ## Autofix all possible linting errors. ${GOLANGCI-LINT} run --fix @@ -90,122 +93,20 @@ tidy: ## Check if there any dirty change for go mod tidy. git diff --exit-code go.mod git diff --exit-code go.sum + +##@ Testing .PHONY: test -test: manifests generate fmt vet tidy envtest ## Run tests. +test: ginkgo manifests generate fmt vet tidy envtest ## Run tests. + $(GINKGO) run test/testkit/matchers/... KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test ./... -coverprofile cover.out -test-matchers: ginkgo - $(GINKGO) run ./test/testkit/matchers/... - -.PHONY: provision-test-env -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-logs -e2e-test-logs: provision-test-env ## Provision k3d cluster, deploy development variant and run end-to-end logs tests. - IMG=k3d-kyma-registry:5000/telemetry-manager:latest make deploy-dev - make run-e2e-test-logs - -.PHONY: e2e-test-traces -e2e-test-traces: provision-test-env ## Provision k3d cluster, deploy development variant and run end-to-end traces tests. - IMG=k3d-kyma-registry:5000/telemetry-manager:latest make deploy-dev - make run-e2e-test-traces - -.PHONY: e2e-test-metrics -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-telemetry -e2e-test-telemetry: provision-test-env ## Provision k3d cluster, deploy development variant and run end-to-end telemetry tests. - IMG=k3d-kyma-registry:5000/telemetry-manager:latest make deploy-dev - make run-e2e-test-telemetry - -.PHONY: e2e-test-logs-release -e2e-test-logs-release: provision-test-env ## Provision k3d cluster, deploy release (default) variant and run end-to-end logs tests. - IMG=k3d-kyma-registry:5000/telemetry-manager:latest make deploy - make run-e2e-test-logs - -.PHONY: e2e-test-traces-release -e2e-test-traces-release: provision-test-env ## Provision k3d cluster, deploy release (default) variant and run end-to-end traces tests. - IMG=k3d-kyma-registry:5000/telemetry-manager:latest make deploy - make run-e2e-test-traces - -.PHONY: e2e-test-metrics-release -e2e-test-metrics-release: provision-test-env ## Provision k3d cluster, deploy release (default) variant and run end-to-end metrics tests. - IMG=k3d-kyma-registry:5000/telemetry-manager:latest make deploy - make run-e2e-test-metrics - -.PHONY: e2e-test-telemetry-release -e2e-test-telemetry-release: provision-test-env ## Provision k3d cluster, deploy release (default) variant and run end-to-end telemetry tests. - IMG=k3d-kyma-registry:5000/telemetry-manager:latest make deploy - make run-e2e-test-telemetry - -.PHONY: run-e2e-test-logs -run-e2e-test-logs: ginkgo test-matchers ## run end-to-end logs tests using an existing cluster - $(GINKGO) run --tags e2e --junit-report=junit.xml --label-filter="logs" ./test/e2e - mkdir -p ${ARTIFACTS} - mv junit.xml ${ARTIFACTS} - -.PHONY: run-e2e-test-traces -run-e2e-test-traces: ginkgo test-matchers ## run end-to-end traces tests using an existing cluster - $(GINKGO) run --tags e2e --junit-report=junit.xml --label-filter="traces" ./test/e2e - mkdir -p ${ARTIFACTS} - mv junit.xml ${ARTIFACTS} - -.PHONY: run-e2e-test-metrics -run-e2e-test-metrics: ginkgo test-matchers ## run end-to-end metrics tests using an existing cluster - $(GINKGO) run --tags e2e --junit-report=junit.xml --label-filter="metrics" ./test/e2e - mkdir -p ${ARTIFACTS} - mv junit.xml ${ARTIFACTS} - -.PHONY: run-e2e-test-telemetry -run-e2e-test-telemetry: ginkgo test-matchers ## run end-to-end telemetry tests using an existing cluster - $(GINKGO) run --tags e2e --junit-report=junit.xml --label-filter="telemetry" ./test/e2e - mkdir -p ${ARTIFACTS} - mv junit.xml ${ARTIFACTS} - -.PHONY: upgrade-test -upgrade-test: provision-k3d ## Provision k3d cluster and run upgrade tests. - hack/upgrade-test.sh - -.PHONY: run-upgrade-test -run-upgrade-test: ginkgo - $(GINKGO) run --tags e2e --junit-report=junit.xml --flake-attempts=5 --label-filter="operational" -v ./test/e2e - mkdir -p ${ARTIFACTS} - mv junit.xml ${ARTIFACTS} - -.PHONY: e2e-deploy-module -e2e-deploy-module: kyma kustomize provision-k3d provision-test-env ## Provision a k3d cluster and deploy module with the lifecycle manager. Manager image and module image are pushed to local k3d registry - make run-e2e-deploy-module - -.PHONY: run-e2e-deploy-module -run-e2e-deploy-module: kyma kustomize ## Deploy module with the lifecycle manager. - KYMA=${KYMA} KUSTOMIZE=${KUSTOMIZE} ./hack/deploy-module.sh - -.PHONY: integration-test-istio -integration-test-istio: ginkgo k3d | test-matchers provision-test-env ## Provision k3d cluster, deploy development variant and run integration tests with istio. - IMG=k3d-kyma-registry:5000/telemetry-manager:latest make deploy-dev - make run-integration-test-istio - -.PHONY: run-integration-test-istio -run-integration-test-istio: ginkgo test-matchers ## run integration tests with istio on an existing cluster - ISTIO_VERSION=$(ISTIO_VERSION) hack/deploy-istio.sh - $(GINKGO) run --tags istio --junit-report=junit.xml ./test/integration/istio - mkdir -p ${ARTIFACTS} - mv junit.xml ${ARTIFACTS} - .PHONY: check-coverage -check-coverage: go-test-coverage +check-coverage: go-test-coverage ## Check tests coverage. go test ./... -short -coverprofile=cover.out -covermode=atomic -coverpkg=./... $(GO_TEST_COVERAGE) --config=./.testcoverage.yml -##@ Build +##@ Build .PHONY: build build: generate fmt vet tidy ## Build manager binary. go build -o bin/manager main.go @@ -232,8 +133,8 @@ docker-build: ## Build docker image with the manager. docker-push: ## Push docker image with the manager. docker push ${IMG} -##@ Deployment +##@ Deployment ifndef ignore-not-found ignore-not-found = false endif @@ -263,142 +164,3 @@ deploy-dev: manifests kustomize ## Deploy resources based on the development var .PHONY: undeploy-dev undeploy-dev: ## Undeploy resources based on the development variant from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion. $(KUSTOMIZE) build config/development | kubectl delete --ignore-not-found=$(ignore-not-found) -f - - -##@ Release Module - -.PHONY: release -release: kustomize ## Prepare release artefacts and create a GitHub release - KUSTOMIZE=${KUSTOMIZE} IMG=${IMG} GORELEASER_VERSION=${GORELEASER_VERSION} ./hack/release.sh - -##@ Build Dependencies - -## Location to install dependencies to -LOCALBIN ?= $(shell pwd)/bin -$(LOCALBIN): - mkdir -p $(LOCALBIN) - -## Tool Binaries -KUSTOMIZE ?= $(LOCALBIN)/kustomize -TABLE_GEN ?= $(LOCALBIN)/table-gen -CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen -ENVTEST ?= $(LOCALBIN)/setup-envtest -GINKGO ?= $(LOCALBIN)/ginkgo -GOLANGCI-LINT ?= $(LOCALBIN)/golangci-lint -GO_TEST_COVERAGE ?= $(LOCALBIN)/go-test-coverage -K3D ?= $(LOCALBIN)/k3d -KYMA ?= $(LOCALBIN)/kyma-$(KYMA_STABILITY) - -## Tool Versions -KUSTOMIZE_VERSION ?= v5.0.1 -TABLE_GEN_VERSION ?= v0.0.0-20230523174756-3dae9f177ffd -CONTROLLER_TOOLS_VERSION ?= v0.11.3 -K3D_VERSION ?= v5.4.7 -GINKGO_VERSION ?= v2.15.0 -GORELEASER_VERSION ?= v1.23.0 -GOLANGCI-LINT_VERSION ?= latest -GO_TEST_COVERAGE_VERSION ?= v2.8.2 - -KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" -.PHONY: kustomize -kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. If wrong version is installed, it will be removed before downloading. -$(KUSTOMIZE): $(LOCALBIN) - @if test -x $(KUSTOMIZE) && ! $(KUSTOMIZE) version | grep -q $(KUSTOMIZE_VERSION); then \ - echo "$(KUSTOMIZE) version is not expected $(KUSTOMIZE_VERSION). Removing it before installing."; \ - rm -rf $(KUSTOMIZE); \ - fi - test -s $(KUSTOMIZE) || { curl -Ss $(KUSTOMIZE_INSTALL_SCRIPT) --output install_kustomize.sh && bash install_kustomize.sh $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN); rm install_kustomize.sh; } - -.PHONY: controller-gen -controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary. -$(CONTROLLER_GEN): $(LOCALBIN) - test -s $(CONTROLLER_GEN) && $(CONTROLLER_GEN) --version | grep -q $(CONTROLLER_TOOLS_VERSION) || \ - GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION) - -.PHONY: envtest -envtest: $(ENVTEST) ## Download envtest-setup locally if necessary. -$(ENVTEST): $(LOCALBIN) - test -s $(ENVTEST) || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest - -.PHONY: tablegen -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) - test -s $(GINKGO) && $(GINKGO) version | grep -q $(GINKGO_VERSION) || \ - GOBIN=$(LOCALBIN) go install github.com/onsi/ginkgo/v2/ginkgo@$(GINKGO_VERSION) - -.PHONY: go-test-coverage -go-test-coverage: $(GO_TEST_COVERAGE) ## Download go-test-coverage locally if necessary. -$(GO_TEST_COVERAGE): $(LOCALBIN) - test -s $(GO_TEST_COVERAGE) && $(GO_TEST_COVERAGE) --version | grep -q $(GO_TEST_COVERAGE_VERSION) || \ - GOBIN=$(LOCALBIN) go install github.com/vladopajic/go-test-coverage/v2@$(GO_TEST_COVERAGE_VERSION) - -K3D_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh" -.PHONY: k3d -k3d: $(K3D) ## Download k3d locally if necessary. If wrong version is installed, it will be removed before downloading. -$(K3D): $(LOCALBIN) - @if test -x $(K3D) && ! $(K3D) version | grep -q $(K3D_VERSION); then \ - echo "$(K3D) version is not as expected '$(K3D_VERSION)'. Removing it before installing."; \ - rm -rf $(K3D); \ - fi - test -s $(K3D) || curl -s $(K3D_INSTALL_SCRIPT) | PATH="$(PATH):$(LOCALBIN)" USE_SUDO=false K3D_INSTALL_DIR=$(LOCALBIN) TAG=$(K3D_VERSION) bash - -define os_error -$(error Error: unsupported platform OS_TYPE:$1, OS_ARCH:$2; to mitigate this problem set variable KYMA with absolute path to kyma-cli binary compatible with your operating system and architecture) -endef - -KYMA_FILENAME ?= $(shell ./hack/get-kyma-filename.sh ${OS_TYPE} ${OS_ARCH}) -KYMA_STABILITY ?= unstable - -.PHONY: kyma -kyma: $(LOCALBIN) $(KYMA) ## Download Kyma cli locally if necessary. -$(KYMA): - $(if $(KYMA_FILENAME),,$(call os_error, ${OS_TYPE}, ${OS_ARCH})) - test -f $@ || curl -s -Lo $(KYMA) https://storage.googleapis.com/kyma-cli-$(KYMA_STABILITY)/$(KYMA_FILENAME) - chmod 0100 $(KYMA) - -##@ Gardener -## injected by the environment -# GARDENER_SA_PATH= -# GARDENER_PROJECT= -# GARDENER_SECRET_NAME= -GIT_COMMIT_SHA=$(shell git rev-parse --short=8 HEAD) -GIT_COMMIT_DATE=$(shell git show -s --format=%cd --date=format:'v%Y%m%d' ${GIT_COMMIT_SHA}) -HIBERNATION_HOUR=$(shell echo $$(( ( $(shell date +%H | sed s/^0//g) + 5 ) % 24 ))) -GARDENER_CLUSTER_NAME=$(shell echo "ci-${GIT_COMMIT_SHA}-${GARDENER_K8S_VERSION}" | sed 's/\.//g') - -ifneq (,$(GARDENER_SA_PATH)) -GARDENER_K8S_VERSION_FULL=$(shell kubectl --kubeconfig=${GARDENER_SA_PATH} get cloudprofiles.core.gardener.cloud gcp -o go-template='{{range .spec.kubernetes.versions}}{{if and (eq .classification "supported") (lt .version "${GARDENER_K8S_VERSION}.a") (gt .version "${GARDENER_K8S_VERSION}")}}{{.version}}{{end}}{{end}}') -GARDENER_OS_VERSION=$(shell kubectl --kubeconfig=${GARDENER_SA_PATH} get cloudprofiles.core.gardener.cloud gcp -o go-template='{{range .spec.machineImages}}{{if eq .name "gardenlinux"}}{{range .versions}}{{if eq .classification "supported"}}{{.version}}{{end}}{{end}}{{end}}{{end}}') -endif - -# log tests are excluded for now as they are too flaky -.PHONY: run-tests-with-git-image -run-tests-with-git-image: ## Run e2e tests on existing cluster using image related to git commit sha - kubectl create namespace kyma-system - IMG=europe-docker.pkg.dev/kyma-project/prod/telemetry-manager:${GIT_COMMIT_DATE}-${GIT_COMMIT_SHA} make deploy-dev - make run-integration-test-istio - -.PHONY: gardener-integration-test -gardener-integration-test: ## Provision gardener cluster and run integration test on it. - make provision-gardener \ - run-tests-with-git-image \ - deprovision-gardener || \ - (make deprovision-gardener && false) - -.PHONY: provision-gardener -provision-gardener: kyma ## Provision gardener cluster with latest k8s version - ${KYMA} provision gardener gcp --credentials ${GARDENER_SA_PATH} --name ${GARDENER_CLUSTER_NAME} --project ${GARDENER_PROJECT} --secret ${GARDENER_SECRET_NAME} --kube-version ${GARDENER_K8S_VERSION_FULL} --gardenlinux-version ${GARDENER_OS_VERSION} --hibernation-start="00 ${HIBERNATION_HOUR} * * ?" - -.PHONY: deprovision-gardener -deprovision-gardener: kyma ## Deprovision gardener cluster - kubectl --kubeconfig=${GARDENER_SA_PATH} annotate shoot ${GARDENER_CLUSTER_NAME} confirmation.gardener.cloud/deletion=true - kubectl --kubeconfig=${GARDENER_SA_PATH} delete shoot ${GARDENER_CLUSTER_NAME} --wait=false diff --git a/docs/contributor/arch/009-makefile-architecture.md b/docs/contributor/arch/009-makefile-architecture.md new file mode 100644 index 000000000..1d4b68196 --- /dev/null +++ b/docs/contributor/arch/009-makefile-architecture.md @@ -0,0 +1,40 @@ +# 9. Makefile: Simplified Architecture + +Date: 2024-28-02 + +## Status + +Proposed + +## Context: Cluttered Makefile Targets + +Makefile targets are currently cluttered, unorganized, and redundant (see the dependency graph below). Targets are not parametrized, thus multiple make targets serve the same scope (for example, running e2e tests). Targets are also used simultaneously by developers and contributors, as well as within GitHub actions and shell scripts, which makes dependencies even more intertwined. These factors result in a complex environment that is becoming hard to manage by the developers. + +![Makefile Dependency Graph (After)](../assets/makefile-graph-before.png) + +## Decision + +After analyzing repositories that have similar configurations as Telemetry Manager (such as Kubebuilder default configuration, Kyma modules repositories, and other Go repositories), the following decisions have been made: + +![Makefile Archtiecture](../assets/makefile-architecture.jpg) + +1. Split general Makefile into sub-makefiles: + - `Makefile`: root makefile, containing targets related to the development, building, deployment, and testing flow of the codebase. Includes `provision.mk` and `dependencies.mk` + - `provision.mk`: contains all targets that (de-)provision a certain environment (such as k3d or Gardener). + - `dependencies.mk`: contains all targets that install build dependencies (such as Kyma or Ginkgo). +2. Implement .env file that stores environment variables accessible from both makefiles and shell scripts: + - This decision was both necessary as well as desired, because it mitigates the use of hardcoded variables (such as dependencies versions), and makes these variables accessible from both makefiles and shell scripts. +3. Remove redundant make targets (for example, e2e, upgrade, integration running targets): + + - Running tests targets (e2e, integration, upgrade): replaced with direct calls of the ginkgo CLI. [The Development Documentation](../development.md) has also been updated accordingly. Junit xml reports have also been dropped in the process. + - Test matchers are now executed only before running the `make test` target for unit tests. Thus, the `test-matchers` target has been removed, and its logic moved directly into the `test` target. The matchers test has also been removed from other test jobs (because it was redundant). + - Gardener integration tests: a separate shell script has been created for it, encapsulating both `gardener-integration-test` and `run-tests-with-git-image` make targets. + - The `release` target logic was moved directly to the `release.sh` script, because that's the only place where this logic is needed. + +4. Update GitHub actions and scripts that are influenced by the changes. + +## Consequences + +These decisions result in a simpler dependency graph (see the following image), as well as further separation of concerns and maintainability of the commands and operational flows. + +![Makefile Dependency Graph (After)](../assets/makefile-graph-after.jpg) diff --git a/docs/contributor/assets/makefile-architecture.jpg b/docs/contributor/assets/makefile-architecture.jpg new file mode 100644 index 000000000..84cc57025 Binary files /dev/null and b/docs/contributor/assets/makefile-architecture.jpg differ diff --git a/docs/contributor/assets/makefile-graph-after.jpg b/docs/contributor/assets/makefile-graph-after.jpg new file mode 100644 index 000000000..c41b73cab Binary files /dev/null and b/docs/contributor/assets/makefile-graph-after.jpg differ diff --git a/docs/contributor/assets/makefile-graph-before.png b/docs/contributor/assets/makefile-graph-before.png new file mode 100644 index 000000000..507c64d86 Binary files /dev/null and b/docs/contributor/assets/makefile-graph-before.png differ diff --git a/docs/contributor/development.md b/docs/contributor/development.md index 9d40c3a01..f88d08019 100644 --- a/docs/contributor/development.md +++ b/docs/contributor/development.md @@ -1,7 +1,6 @@ # Development -Telemetry Manager has been bootstrapped with [Kubebuilder](https://github.com/kubernetes-sigs/kubebuilder) 3.6.0. -Too add more APIs, use [Kubebuilder](https://book.kubebuilder.io/cronjob-tutorial/new-api.html). +Telemetry Manager has been bootstrapped with [Kubebuilder](https://github.com/kubernetes-sigs/kubebuilder) 3.6.0. To add more APIs, use [Kubebuilder](https://book.kubebuilder.io/cronjob-tutorial/new-api.html). ## Prerequisites @@ -9,54 +8,52 @@ Too add more APIs, use [Kubebuilder](https://book.kubebuilder.io/cronjob-tutoria - Install [Golang 1.20](https://golang.org/dl/) or newer (for development and local execution). - Install [Docker](https://www.docker.com/get-started). - Install [golangci-lint](https://golangci-lint.run). +- Install [ginkgo CLI](https://pkg.go.dev/github.com/onsi/ginkgo/ginkgo) to run the E2E test commands straight from your terminal. Other dependencies will be downloaded by the make targets to the `bin` sub-folder. -## Available Commands +## Development Commands For development, use the following commands: -- Run unit tests - ```bash - make test - ``` - -- Create a k3d cluster on Docker, deploy Telemetry Manager, and run integration tests - ```bash - make e2e-test - ``` - - Run `golangci-lint` and lint manifests + ```bash make lint ``` - Autofix all automatically-fixable linter complaints + ```bash make lint-autofix ``` - Regenerate YAML manifests (CRDs and RBAC) + ```bash make manifests ``` - Install CRDs to cluster in current kubeconfig context + ```bash make install ``` - Uninstall CRDs to cluster in current kubeconfig context + ```bash make uninstall ``` - Run Telemetry Manager locally (uses current kubeconfig context) + ```bash make run ``` - Build container image and deploy to cluster in current kubeconfig context + ```bash export IMG= make docker-build @@ -66,11 +63,32 @@ For development, use the following commands: ``` - Clean up everything + ```bash make undeploy ``` +## Testing Commands + +For testing, use the following commands: + +- Run unit tests + + ```bash + make test + ``` + - Deploy module with Lifecycle Manager on a k3d cluster + + ```bash + make provision-k3d-e2e + ``` + +- Run e2e tests + ```bash + ginkgo run --tags e2e --label-filter="" test/e2e + ``` + _Example:_ ```bash - make e2e-deploy-module + ginkgo run --tags e2e --label-filter="logs" test/e2e ``` diff --git a/docs/contributor/releasing.md b/docs/contributor/releasing.md index 2f6dd87bc..e3d30b07b 100644 --- a/docs/contributor/releasing.md +++ b/docs/contributor/releasing.md @@ -21,8 +21,8 @@ This release process covers the steps to release new major and minor versions fo 5. Bump the `telemetry-manager/{RELEASE_BRANCH}` branch with the new versions for the dependent images. Create a PR to `telemetry-manager/{RELEASE_BRANCH}` with the following changes: - - `Makefile`: - - For the `IMG` variable, update the tag of the `telemetry-manager` image with the new module version following the `x.y.z` pattern. For example, `IMG ?= europe-docker.pkg.dev/kyma-project/prod/telemetry-manager:1.0.0`. + - `.env`: + - For the `ENV_IMG` variable, update the tag of the `telemetry-manager` image with the new module version following the `x.y.z` pattern. For example, `ENV_IMG=europe-docker.pkg.dev/kyma-project/prod/telemetry-manager:1.0.0`. - `config/manager/kustomization.yaml`: - Update the `newTag` field for the `telemetry-manager` image with the new module version following the `x.y.z` pattern, such as `1.0.0`. - `sec-scanners-config.yaml`: diff --git a/hack/deploy-istio.sh b/hack/deploy-istio.sh index dc8033004..8fafbfe08 100755 --- a/hack/deploy-istio.sh +++ b/hack/deploy-istio.sh @@ -1,4 +1,7 @@ #!/usr/bin/env bash +source .env + +readonly ISTIO_VERSION=${ISTIO_VERSION:-$ENV_ISTIO_VERSION} function apply_istio_telemetry() { kubectl apply -f - <