Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 48 additions & 7 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,20 @@ permissions: {}
jobs:
build:
name: Build and Test
runs-on: vm-runner
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
checks: write
outputs:
run_e2e: ${{ steps.changes.outputs.src }}
steps:
- name: Checkout code
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
with:
persist-credentials: false

- name: Setup build environment
id: setup
uses: ./.github/actions/setup-build-env
Expand All @@ -74,10 +77,6 @@ jobs:

- name: Lint, Test and Build
if: github.event.pull_request.draft == false
env:
DOCKER_BUILD_ARGS: --cache-from=type=gha --cache-to=type=gha,mode=max
TAG: ${{ steps.setup.outputs.image-tag }}
LICENSE_KEY: ${{ secrets.ENTERPRISE_COMPONENTS_LICENSE_KEY }}
run: |
make lint
make manifests
Expand All @@ -86,8 +85,50 @@ jobs:
# check for uncommited changes to crds, docs or API
git diff --exit-code
make test
git fetch origin ${{ github.base_ref || 'master' }}
BASE_REF=origin/${{ github.base_ref || 'master' }} TAG=${TAG} make test-e2e

- name: Save Go cache
if: ${{ github.ref == 'refs/heads/master' }}
uses: ./.github/actions/save-go-cache

- name: Check changed files
uses: dorny/paths-filter@fbd0ab8f3e69293af611ebaee6363fc25e6d187d # v4.0.1
id: changes
with:
filters: |
src:
- '**'
- '!Makefile'

e2e:
name: E2E / ${{ matrix.name }}
needs: build
if: github.event.pull_request.draft == false && needs.build.outputs.run_e2e == 'true'
runs-on: vm-runner
permissions:
actions: read
contents: read
checks: write
strategy:
fail-fast: false
matrix:
include:
- name: main
e2e_target: ./test/e2e/
- name: upgrade
e2e_target: ./test/e2e/upgrade/...
steps:
- name: Checkout code
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- name: Setup build environment
id: setup
uses: ./.github/actions/setup-build-env
- name: E2E Tests
env:
DOCKER_BUILD_ARGS: --cache-from=type=gha --cache-to=type=gha,mode=max
LICENSE_KEY: ${{ secrets.ENTERPRISE_COMPONENTS_LICENSE_KEY }}
E2E_TARGET: ${{ matrix.e2e_target }}
run: |
TAG=${GITHUB_SHA:0:7} BASE_REF=origin/${{ github.base_ref || 'master' }} make test-e2e
- name: Save Go cache
if: ${{ github.ref == 'refs/heads/master' }}
uses: ./.github/actions/save-go-cache
Expand Down
77 changes: 2 additions & 75 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ VERSION ?= $(if $(findstring $(TAG),$(TAG:v%=%)),0.0.0,$(TAG:v%=%))
DATEINFO_TAG ?= $(shell date -u +'%Y%m%d-%H%M%S')
NAMESPACE ?= vm
OVERLAY ?= config/manager
E2E_TESTS_CONCURRENCY ?= $(shell getconf _NPROCESSORS_ONLN)
E2E_TARGET ?= ./test/e2e/...
FIPS_VERSION=v1.0.0
BASEIMAGE ?=scratch

Expand Down Expand Up @@ -59,6 +57,7 @@ export FLAGS_HEADER

include docs/Makefile
include codespell/Makefile
include test/Makefile

.PHONY: all
all: build
Expand Down Expand Up @@ -162,21 +161,6 @@ test: manifests generate fmt vet envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test $$(go list ./... | grep -v /e2e) -coverprofile cover.out
cd api/ && go test ./operator/...

# Utilize Kind or modify the e2e tests to load the image locally, enabling compatibility with other vendors.
.PHONY: test-e2e # Run the e2e tests against a Kind k8s instance that is spun up.
test-e2e: load-kind ginkgo crust-gather mirrord
env CGO_ENABLED=1 OPERATOR_IMAGE=$(OPERATOR_IMAGE) CONFIG_RELOADER_IMAGE=$(CONFIG_RELOADER_IMAGE) REPORTS_DIR=$(shell pwd) CRUST_GATHER_BIN=$(CRUST_GATHER_BIN) $(MIRRORD_BIN) exec -f ./mirrord.json -- $(GINKGO_BIN) \
-ldflags="-linkmode=external" \
--output-interceptor-mode=none \
-procs=$(E2E_TESTS_CONCURRENCY) \
-randomize-all \
-timeout=60m \
-junit-report=report.xml $(E2E_TARGET)

.PHONY: test-e2e-upgrade # Run only the e2e upgrade tests against a Kind k8s instance that is spun up.
test-e2e-upgrade: E2E_TARGET=./test/e2e/upgrade/...
test-e2e-upgrade: test-e2e

.PHONY: lint
lint: golangci-lint ## Run golangci-lint linter
cd api && $(GOLANGCI_LINT) run operator/... & P1=$$!; \
Expand Down Expand Up @@ -345,30 +329,6 @@ deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in
undeploy: kustomize ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
$(KUSTOMIZE) build $(OVERLAY) | $(KUBECTL) delete $(if $(NAMESPACE),-n $(NAMESPACE),) --ignore-not-found=$(or $(ignore-not-found),false) -f -

# builds image and loads it into kind.
ensure-kind-cluster: kind
if [ "`$(KIND) get clusters`" != "kind" ]; then \
$(KIND) create cluster --config=./kind.yaml; \
else \
$(KUBECTL) cluster-info --context kind-kind; \
fi

load-kind: docker-build docker-build-config-reloader ensure-kind-cluster
if [ "$(CONTAINER_TOOL)" != "podman" ]; then \
$(KIND) load docker-image $(REGISTRY)/$(ORG)/$(REPO):$(TAG); \
$(KIND) load docker-image $(CONFIG_RELOADER_IMAGE); \
fi

deploy-kind: OVERLAY=config/base-with-webhook
deploy-kind: load-kind deploy

# deploy-kind-no-build skips docker-build/load — use when image is already loaded (e.g. from test-e2e's load-kind dep)
deploy-kind-no-build: OVERLAY=config/base-with-webhook
deploy-kind-no-build: ensure-kind-cluster deploy

undeploy-kind: OVERLAY=config/base-with-webhook-no-crd
undeploy-kind: ensure-kind-cluster undeploy

## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
Expand All @@ -383,14 +343,10 @@ GOLANGCI_LINT = $(LOCALBIN)/golangci-lint-$(GOLANGCI_LINT_VERSION)
CLIENT_GEN = $(LOCALBIN)/client-gen-$(CODEGENERATOR_VERSION)
LISTER_GEN = $(LOCALBIN)/lister-gen-$(CODEGENERATOR_VERSION)
INFORMER_GEN = $(LOCALBIN)/informer-gen-$(CODEGENERATOR_VERSION)
KIND = $(LOCALBIN)/kind-$(KIND_VERSION)
OPERATOR_SDK = $(LOCALBIN)/operator-sdk-$(OPERATOR_SDK_VERSION)
OPM = $(LOCALBIN)/opm-$(OPM_VERSION)
YQ = $(LOCALBIN)/yq-$(YQ_VERSION)
CRD_REF_DOCS = $(LOCALBIN)/crd-ref-docs-$(CRD_REF_DOCS_VERSION)
GINKGO_BIN ?= $(LOCALBIN)/ginkgo-$(GINKGO_VERSION)
CRUST_GATHER_BIN ?= $(LOCALBIN)/crust-gather-$(CRUST_GATHER_VERSION)
MIRRORD_BIN ?= $(LOCALBIN)/mirrord-$(MIRRORD_VERSION)
COSIGN_BIN ?= $(LOCALBIN)/cosign-$(COSIGN_VERSION)

## Tool Versions
Expand All @@ -399,15 +355,10 @@ CONTROLLER_TOOLS_VERSION ?= v0.21.0
ENVTEST_VERSION ?= release-0.23
GOLANGCI_LINT_VERSION ?= v2.12.2
CODEGENERATOR_VERSION ?= v0.36.2
KIND_VERSION ?= v0.32.0
OLM_VERSION ?= 0.45.0

OPERATOR_SDK_VERSION ?= v1.42.2
OPM_VERSION ?= v1.72.0
YQ_VERSION ?= v4.53.3
GINKGO_VERSION ?= v2.31.0
CRUST_GATHER_VERSION ?= v0.15.2
MIRRORD_VERSION ?= 3.217.1
COSIGN_VERSION ?= v3.1.1

CRD_REF_DOCS_VERSION ?= 4deb8b1eb0169ac22ac5d777feaeb26a00e38a33
Expand All @@ -423,7 +374,7 @@ $(CONTROLLER_GEN): $(LOCALBIN)
$(call go-install-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen,$(CONTROLLER_TOOLS_VERSION))

.PHONY: install-tools
install-tools: crd-ref-docs client-gen lister-gen informer-gen controller-gen kustomize envtest ginkgo
install-tools: crd-ref-docs client-gen lister-gen informer-gen controller-gen kustomize envtest

.PHONY: crd-ref-docs
crd-ref-docs: $(CRD_REF_DOCS)
Expand All @@ -436,10 +387,6 @@ client-gen: $(CLIENT_GEN)
$(CLIENT_GEN): $(LOCALBIN)
$(call go-install-tool,$(CLIENT_GEN),k8s.io/code-generator/cmd/client-gen,$(CODEGENERATOR_VERSION))

.PHONY: ginkgo
ginkgo:
$(call go-install-tool,$(GINKGO_BIN),github.com/onsi/ginkgo/v2/ginkgo,$(GINKGO_VERSION))

.PHONY: lister-gen
lister-gen: $(LISTER_GEN)
$(LISTER_GEN): $(LOCALBIN)
Expand Down Expand Up @@ -471,11 +418,6 @@ $(GOLANGCI_LINT): $(LOCALBIN)
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))

.PHONY: kind
kind: $(KIND)
$(KIND): $(LOCALBIN)
$(call go-install-tool,$(KIND),sigs.k8s.io/kind,$(KIND_VERSION))

.PHONY: yq
yq: $(YQ)
$(YQ): $(LOCALBIN)
Expand All @@ -484,21 +426,6 @@ $(YQ): $(LOCALBIN)
UNAME_S=$(shell uname -s 2>/dev/null)
OS=$(shell echo $(UNAME_S) | tr A-Z a-z)
ARCH=$(if $(filter x86_64,$(shell uname -m 2>/dev/null)),amd64,arm64)
MIRRORD_OS=$(if $(filter darwin,$(OS)),mac,linux)
MIRRORD_ARCH=$(if $(filter mac,$(MIRRORD_OS)),universal,$(if $(filter x86_64,$(shell uname -m 2>/dev/null)),x86_64,aarch64))
.PHONY: crust-gather
crust-gather: $(CRUST_GATHER_BIN)
$(CRUST_GATHER_BIN): $(LOCALBIN)
$(call download-github-release,$(CRUST_GATHER_BIN),crust-gather/crust-gather,$(CRUST_GATHER_VERSION),kubectl-crust-gather_$(CRUST_GATHER_VERSION)_$(OS)_$(ARCH).tar.gz,kubectl-crust-gather)

.PHONY: mirrord
mirrord: $(MIRRORD_BIN)
$(MIRRORD_BIN): $(LOCALBIN)
$(call download-github-release,$(MIRRORD_BIN),metalbear-co/mirrord,$(MIRRORD_VERSION),mirrord_$(MIRRORD_OS)_$(MIRRORD_ARCH).zip,mirrord)

.PHONY: allure-report
allure-report:
@[ -d ./allure-results ] && npx allure awesome --single-file ./allure-results -o ./allure-report || echo "allure-results dir not found, skipping report generation"

# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
# $1 - target path with name of binary (ideally with version)
Expand Down
8 changes: 4 additions & 4 deletions renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
{
"customType": "regex",
"managerFilePatterns": [
"/^Makefile$/"
"/^test\\/Makefile$/"
],
"matchStrings": [
"KIND_VERSION \\?= (?<currentValue>v.*)"
Expand Down Expand Up @@ -132,7 +132,7 @@
{
"customType": "regex",
"managerFilePatterns": [
"/^Makefile$/"
"/^test\\/Makefile$/"
],
"matchStrings": [
"GINKGO_VERSION \\?= (?<currentValue>v.*)"
Expand All @@ -143,7 +143,7 @@
{
"customType": "regex",
"managerFilePatterns": [
"/^Makefile$/"
"/^test\\/Makefile$/"
],
"matchStrings": [
"CRUST_GATHER_VERSION \\?= (?<currentValue>v.*)"
Expand Down Expand Up @@ -178,7 +178,7 @@
{
"customType": "regex",
"managerFilePatterns": [
"/^Makefile$/"
"/^test\\/Makefile$/"
],
"matchStrings": [
"MIRRORD_VERSION \\?= (?<currentValue>.*)"
Expand Down
85 changes: 85 additions & 0 deletions test/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
##@ E2E testing
# Targets here require docker, a Kind cluster, or e2e test tooling.
# Kept in a separate file so changes to e2e tool versions do not retrigger
# the full CI workflow for ordinary source-code changes.
# This file is included by the root Makefile.

E2E_TESTS_CONCURRENCY ?= $(shell getconf _NPROCESSORS_ONLN)
E2E_TARGET ?= ./test/e2e/...

## Tool Binaries
KIND = $(LOCALBIN)/kind-$(KIND_VERSION)
GINKGO_BIN ?= $(LOCALBIN)/ginkgo-$(GINKGO_VERSION)
CRUST_GATHER_BIN ?= $(LOCALBIN)/crust-gather-$(CRUST_GATHER_VERSION)
MIRRORD_BIN ?= $(LOCALBIN)/mirrord-$(MIRRORD_VERSION)

## Tool Versions
KIND_VERSION ?= v0.32.0
GINKGO_VERSION ?= v2.31.0
CRUST_GATHER_VERSION ?= v0.15.2
MIRRORD_VERSION ?= 3.217.1

MIRRORD_OS=$(if $(filter darwin,$(OS)),mac,linux)
MIRRORD_ARCH=$(if $(filter mac,$(MIRRORD_OS)),universal,$(if $(filter x86_64,$(shell uname -m 2>/dev/null)),x86_64,aarch64))

# Utilize Kind or modify the e2e tests to load the image locally, enabling compatibility with other vendors.
.PHONY: test-e2e # Run the e2e tests against a Kind k8s instance that is spun up.
test-e2e: load-kind ginkgo crust-gather mirrord
env CGO_ENABLED=1 OPERATOR_IMAGE=$(OPERATOR_IMAGE) CONFIG_RELOADER_IMAGE=$(CONFIG_RELOADER_IMAGE) REPORTS_DIR=$(shell pwd) CRUST_GATHER_BIN=$(CRUST_GATHER_BIN) $(MIRRORD_BIN) exec -f ./mirrord.json -- $(GINKGO_BIN) \
-ldflags="-linkmode=external" \
--output-interceptor-mode=none \
-procs=$(E2E_TESTS_CONCURRENCY) \
-randomize-all \
-timeout=60m \
-junit-report=report.xml $(E2E_TARGET)

.PHONY: test-e2e-upgrade # Run only the e2e upgrade tests against a Kind k8s instance that is spun up.
test-e2e-upgrade: E2E_TARGET=./test/e2e/upgrade/...
test-e2e-upgrade: test-e2e

# builds image and loads it into kind.
ensure-kind-cluster: kind
if [ "`$(KIND) get clusters`" != "kind" ]; then \
$(KIND) create cluster --config=./kind.yaml; \
else \
$(KUBECTL) cluster-info --context kind-kind; \
fi

load-kind: docker-build docker-build-config-reloader ensure-kind-cluster
if [ "$(CONTAINER_TOOL)" != "podman" ]; then \
$(KIND) load docker-image $(REGISTRY)/$(ORG)/$(REPO):$(TAG); \
$(KIND) load docker-image $(CONFIG_RELOADER_IMAGE); \
fi

deploy-kind: OVERLAY=config/base-with-webhook
deploy-kind: load-kind deploy

# deploy-kind-no-build skips docker-build/load — use when image is already loaded (e.g. from test-e2e's load-kind dep)
deploy-kind-no-build: OVERLAY=config/base-with-webhook
deploy-kind-no-build: ensure-kind-cluster deploy

undeploy-kind: OVERLAY=config/base-with-webhook-no-crd
undeploy-kind: ensure-kind-cluster undeploy

.PHONY: allure-report
allure-report:
@[ -d ./allure-results ] && npx allure awesome --single-file ./allure-results -o ./allure-report || echo "allure-results dir not found, skipping report generation"

.PHONY: ginkgo
ginkgo:
$(call go-install-tool,$(GINKGO_BIN),github.com/onsi/ginkgo/v2/ginkgo,$(GINKGO_VERSION))

.PHONY: kind
kind: $(KIND)
$(KIND): $(LOCALBIN)
$(call go-install-tool,$(KIND),sigs.k8s.io/kind,$(KIND_VERSION))

.PHONY: crust-gather
crust-gather: $(CRUST_GATHER_BIN)
$(CRUST_GATHER_BIN): $(LOCALBIN)
$(call download-github-release,$(CRUST_GATHER_BIN),crust-gather/crust-gather,$(CRUST_GATHER_VERSION),kubectl-crust-gather_$(CRUST_GATHER_VERSION)_$(OS)_$(ARCH).tar.gz,kubectl-crust-gather)

.PHONY: mirrord
mirrord: $(MIRRORD_BIN)
$(MIRRORD_BIN): $(LOCALBIN)
$(call download-github-release,$(MIRRORD_BIN),metalbear-co/mirrord,$(MIRRORD_VERSION),mirrord_$(MIRRORD_OS)_$(MIRRORD_ARCH).zip,mirrord)
Loading