From 7696fb2a2b57761d7c3fbb7d71359f86cb36bbaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charles-Edouard=20Br=C3=A9t=C3=A9ch=C3=A9?= Date: Tue, 28 Feb 2023 10:33:53 +0100 Subject: [PATCH] fix: makefile build/kind targets and add target to save built images to files (#6416) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Charles-Edouard Brétéché --- .github/workflows/conformance.yaml | 48 ++++++++++++++++++++++++------ .gitignore | 1 + Makefile | 42 +++++++++++++++++++------- 3 files changed, 71 insertions(+), 20 deletions(-) diff --git a/.github/workflows/conformance.yaml b/.github/workflows/conformance.yaml index 4ab0aa837f..c8a2eb9145 100644 --- a/.github/workflows/conformance.yaml +++ b/.github/workflows/conformance.yaml @@ -11,11 +11,7 @@ concurrency: cancel-in-progress: true jobs: - run-conformance: - strategy: - fail-fast: false - matrix: - k8s-version: [v1.24.7, v1.25.3, v1.26.0] + prepare-images: runs-on: ubuntu-latest steps: - name: Checkout @@ -23,11 +19,45 @@ jobs: - name: Setup build env uses: ./.github/actions/setup-build-env with: - build-cache-key: run-conformance - - name: Setup test env - uses: ./.github/actions/setup-test-env + build-cache-key: build-images + - name: ko build + run: make docker-save-image-all + - name: upload images archive + uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 with: - version: ${{ matrix.k8s-version }} + name: kyverno.tar + path: kyverno.tar + retention-days: 1 + if-no-files-found: error + + run-conformance: + strategy: + fail-fast: false + matrix: + k8s-version: [v1.24.7, v1.25.3, v1.26.0] + runs-on: ubuntu-latest + needs: prepare-images + steps: + - name: Checkout + uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 + - name: Setup build env + uses: ./.github/actions/setup-build-env + with: + build-cache-key: run-conformance + - name: Create kind cluster + run: | + export KIND_IMAGE=kindest/node:${{ matrix.k8s-version }} + make kind-create-cluster + - name: Download kyverno images archive + uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 + with: + name: kyverno.tar + - name: Load kyverno images archive in kind cluster + run: make kind-load-image-archive + - name: Install kyverno + run: make kind-install-kyverno + - name: Wait for kyverno ready + uses: ./.github/actions/kyverno-wait-ready - name: Test with kuttl run: make test-kuttl - name: Debug failure diff --git a/.gitignore b/.gitignore index dabd532d49..7ec553c4ea 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,4 @@ cmd/background-controller/background-controller /config/.release .dist .manifest +kyverno.tar.gz diff --git a/Makefile b/Makefile index 3930909124..48667c8fec 100644 --- a/Makefile +++ b/Makefile @@ -256,6 +256,7 @@ KO_KYVERNOPRE_REPO := $(PACKAGE)/$(KYVERNOPRE_DIR) KO_KYVERNO_REPO := $(PACKAGE)/$(KYVERNO_DIR) KO_CLEANUP_REPO := $(PACKAGE)/$(CLEANUP_DIR) KO_REPORTS_REPO := $(PACKAGE)/$(REPORTS_DIR) +KO_BACKGROUND_REPO := $(PACKAGE)/$(BACKGROUND_DIR) .PHONY: ko-build-kyverno-init ko-build-kyverno-init: $(KO) ## Build kyvernopre local image (with ko) @@ -290,7 +291,7 @@ ko-build-reports-controller: $(KO) ## Build reports controller local image (with .PHONY: ko-build-background-controller ko-build-background-controller: $(KO) ## Build background controller local image (with ko) @echo Build background controller local image with ko... >&2 - @LD_FLAGS=$(LD_FLAGS_DEV) KOCACHE=$(KOCACHE) KO_DOCKER_REPO=ko.local \ + @LD_FLAGS=$(LD_FLAGS_DEV) KOCACHE=$(KOCACHE) KO_DOCKER_REPO=$(KO_REGISTRY) \ $(KO) build ./$(BACKGROUND_DIR) --preserve-import-paths --tags=$(IMAGE_TAG_DEV) --platform=$(LOCAL_PLATFORM) .PHONY: ko-build-all @@ -301,11 +302,6 @@ ko-build-all: ko-build-kyverno-init ko-build-kyverno ko-build-cli ko-build-clean ################ REGISTRY_USERNAME ?= dummy -KO_KYVERNOPRE_IMAGE := ko.local/github.com/kyverno/kyverno/cmd/kyverno-init -KO_KYVERNO_IMAGE := ko.local/github.com/kyverno/kyverno/cmd/kyverno -KO_CLEANUP_IMAGE := ko.local/github.com/kyverno/kyverno/cmd/cleanup-controller -KO_REPORTS_IMAGE := ko.local/github.com/kyverno/kyverno/cmd/reports-controller -KO_BACKGROUND_IMAGE := ko.local/github.com/kyverno/kyverno/cmd/background-controller PLATFORMS := all KO_TAGS := $(IMAGE_TAG_LATEST),$(IMAGE_TAG) KO_TAGS_DEV := $(IMAGE_TAG_LATEST),$(IMAGE_TAG_DEV) @@ -390,7 +386,7 @@ LOCAL_KYVERNOPRE_REPO := $($(shell echo $(BUILD_WITH) | tr '[:lower:]' '[:upper LOCAL_KYVERNO_REPO := $($(shell echo $(BUILD_WITH) | tr '[:lower:]' '[:upper:]')_KYVERNO_REPO) LOCAL_CLEANUP_REPO := $($(shell echo $(BUILD_WITH) | tr '[:lower:]' '[:upper:]')_CLEANUP_REPO) LOCAL_REPORTS_REPO := $($(shell echo $(BUILD_WITH) | tr '[:lower:]' '[:upper:]')_REPORTS_REPO) -LOCAL_BACKGROUND_IMAGE := $($(shell echo $(BUILD_WITH) | tr '[:lower:]' '[:upper:]')_BACKGROUND_IMAGE) +LOCAL_BACKGROUND_REPO := $($(shell echo $(BUILD_WITH) | tr '[:lower:]' '[:upper:]')_BACKGROUND_REPO) .PHONY: image-build-kyverno-init image-build-kyverno-init: $(BUILD_WITH)-build-kyverno-init @@ -755,6 +751,20 @@ test-perf: $(PACKAGE_SHIM) ## Run perf tests --v=2 \ --report-dir=. +########## +# DOCKER # +########## + +.PHONY: docker-save-image-all +docker-save-image-all: $(KIND) image-build-all ## Save docker images in archive + docker save \ + $(LOCAL_REGISTRY)/$(LOCAL_KYVERNOPRE_REPO):$(IMAGE_TAG_DEV) \ + $(LOCAL_REGISTRY)/$(LOCAL_KYVERNO_REPO):$(IMAGE_TAG_DEV) \ + $(LOCAL_REGISTRY)/$(LOCAL_CLEANUP_REPO):$(IMAGE_TAG_DEV) \ + $(LOCAL_REGISTRY)/$(LOCAL_REPORTS_REPO):$(IMAGE_TAG_DEV) \ + $(LOCAL_REGISTRY)/$(LOCAL_BACKGROUND_REPO):$(IMAGE_TAG_DEV) \ + > kyverno.tar + ######## # KIND # ######## @@ -792,13 +802,18 @@ kind-load-reports-controller: $(KIND) image-build-reports-controller ## Build re .PHONY: kind-load-background-controller kind-load-background-controller: $(KIND) image-build-background-controller ## Build background controller image and load it in kind cluster @echo Load background controller image... >&2 - @$(KIND) load docker-image --name $(KIND_NAME) $(LOCAL_BACKGROUND_IMAGE):$(IMAGE_TAG_DEV) + @$(KIND) load docker-image --name $(KIND_NAME) $(LOCAL_REGISTRY)/$(LOCAL_BACKGROUND_REPO):$(IMAGE_TAG_DEV) .PHONY: kind-load-all kind-load-all: kind-load-kyverno-init kind-load-kyverno kind-load-cleanup-controller kind-load-reports-controller kind-load-background-controller ## Build images and load them in kind cluster -.PHONY: kind-deploy-kyverno -kind-deploy-kyverno: $(HELM) kind-load-all ## Build images, load them in kind cluster and deploy kyverno helm chart +.PHONY: kind-load-image-archive +kind-load-image-archive: $(KIND) ## Load docker images from archive + @echo Load image archive in kind cluster... >&2 + @$(KIND) load image-archive kyverno.tar --name $(KIND_NAME) + +.PHONY: kind-install-kyverno +kind-install-kyverno: $(HELM) ## Install kyverno helm chart @echo Install kyverno chart... >&2 @$(HELM) upgrade --install kyverno --namespace kyverno --create-namespace --wait ./charts/kyverno \ --set image.registry=$(LOCAL_REGISTRY) \ @@ -813,10 +828,15 @@ kind-deploy-kyverno: $(HELM) kind-load-all ## Build images, load them in kind cl --set reportsController.image.registry=$(LOCAL_REGISTRY) \ --set reportsController.image.repository=$(LOCAL_REPORTS_REPO) \ --set reportsController.image.tag=$(IMAGE_TAG_DEV) \ - --set backgroundController.image.repository=$(LOCAL_BACKGROUND_IMAGE) \ + --set backgroundController.image.registry=$(LOCAL_REGISTRY) \ + --set backgroundController.image.repository=$(LOCAL_BACKGROUND_REPO) \ --set backgroundController.image.tag=$(IMAGE_TAG_DEV) \ --values ./scripts/config/$(USE_CONFIG)/kyverno.yaml +.PHONY: kind-deploy-kyverno +kind-deploy-kyverno: $(HELM) kind-load-all ## Build images, load them in kind cluster and deploy kyverno helm chart + $(MAKE) kind-install-kyverno + .PHONY: kind-deploy-kyverno-policies kind-deploy-kyverno-policies: $(HELM) ## Deploy kyverno-policies helm chart @echo Install kyverno-policies chart... >&2