2022-08-31 04:22:46 +00:00
.DEFAULT_GOAL : build -all
2019-05-29 21:44:21 +00:00
2022-08-30 15:30:28 +00:00
############
# DEFAULTS #
############
2023-04-07 12:10:53 +00:00
GIT_SHA := $( shell git rev-parse HEAD)
2022-08-30 15:30:28 +00:00
REGISTRY ?= ghcr.io
2022-09-27 17:47:59 +00:00
REPO ?= kyverno
2023-08-17 11:20:06 +00:00
KIND_IMAGE ?= kindest/node:v1.27.3
2022-08-31 08:06:12 +00:00
KIND_NAME ?= kind
2023-08-21 13:56:57 +00:00
KIND_CONFIG ?= default
2022-08-31 04:22:46 +00:00
GOOS ?= $( shell go env GOOS)
GOARCH ?= $( shell go env GOARCH)
2022-09-09 09:00:25 +00:00
KOCACHE ?= /tmp/ko-cache
2022-09-02 13:34:22 +00:00
BUILD_WITH ?= ko
2022-09-27 17:47:59 +00:00
KYVERNOPRE_IMAGE := kyvernopre
KYVERNO_IMAGE := kyverno
CLI_IMAGE := kyverno-cli
2022-11-14 11:00:40 +00:00
CLEANUP_IMAGE := cleanup-controller
2023-01-18 13:38:47 +00:00
REPORTS_IMAGE := reports-controller
2023-01-31 16:12:34 +00:00
BACKGROUND_IMAGE := background-controller
2022-09-27 17:47:59 +00:00
REPO_KYVERNOPRE := $( REGISTRY) /$( REPO) /$( KYVERNOPRE_IMAGE)
REPO_KYVERNO := $( REGISTRY) /$( REPO) /$( KYVERNO_IMAGE)
REPO_CLI := $( REGISTRY) /$( REPO) /$( CLI_IMAGE)
2022-12-21 13:44:22 +00:00
REPO_CLEANUP := $( REGISTRY) /$( REPO) /$( CLEANUP_IMAGE)
2023-01-18 13:38:47 +00:00
REPO_REPORTS := $( REGISTRY) /$( REPO) /$( REPORTS_IMAGE)
2023-01-31 16:12:34 +00:00
REPO_BACKGROUND := $( REGISTRY) /$( REPO) /$( BACKGROUND_IMAGE)
2022-12-12 05:58:36 +00:00
USE_CONFIG ?= standard
2022-03-07 09:43:36 +00:00
2022-08-25 16:59:24 +00:00
#########
# TOOLS #
#########
TOOLS_DIR := $( PWD) /.tools
KIND := $( TOOLS_DIR) /kind
2023-07-03 11:30:17 +00:00
KIND_VERSION := v0.20.0
2022-08-25 16:59:24 +00:00
CONTROLLER_GEN := $( TOOLS_DIR) /controller-gen
2023-06-29 15:58:18 +00:00
CONTROLLER_GEN_VERSION := v0.12.0
2022-09-01 06:14:56 +00:00
CLIENT_GEN := $( TOOLS_DIR) /client-gen
LISTER_GEN := $( TOOLS_DIR) /lister-gen
INFORMER_GEN := $( TOOLS_DIR) /informer-gen
2022-09-28 11:45:16 +00:00
OPENAPI_GEN := $( TOOLS_DIR) /openapi-gen
2023-07-06 08:43:59 +00:00
REGISTER_GEN := $( TOOLS_DIR) /register-gen
2023-07-06 12:56:17 +00:00
DEEPCOPY_GEN := $( TOOLS_DIR) /deepcopy-gen
2023-07-06 11:02:36 +00:00
DEFAULTER_GEN := $( TOOLS_DIR) /defaulter-gen
2023-07-10 09:53:25 +00:00
APPLYCONFIGURATION_GEN := $( TOOLS_DIR) /applyconfiguration-gen
2023-08-16 12:03:14 +00:00
CODE_GEN_VERSION := v0.28.0
2022-08-25 16:59:24 +00:00
GEN_CRD_API_REFERENCE_DOCS := $( TOOLS_DIR) /gen-crd-api-reference-docs
GEN_CRD_API_REFERENCE_DOCS_VERSION := latest
GO_ACC := $( TOOLS_DIR) /go-acc
GO_ACC_VERSION := latest
GOIMPORTS := $( TOOLS_DIR) /goimports
GOIMPORTS_VERSION := latest
2022-10-20 12:17:33 +00:00
HELM := $( TOOLS_DIR) /helm
2023-08-16 12:03:14 +00:00
HELM_VERSION := v3.12.3
2022-08-25 16:59:24 +00:00
HELM_DOCS := $( TOOLS_DIR) /helm-docs
2022-09-01 23:03:14 +00:00
HELM_DOCS_VERSION := v1.11.0
2022-08-25 16:59:24 +00:00
KO := $( TOOLS_DIR) /ko
2023-07-03 10:47:49 +00:00
KO_VERSION := v0.14.1
2022-11-07 18:01:25 +00:00
KUTTL := $( TOOLS_DIR) /kubectl-kuttl
2023-08-29 14:36:26 +00:00
KUTTL_VERSION := v0.0.0-20230829104447-1e404d2e3902
2023-07-10 09:53:25 +00:00
TOOLS := $( KIND) $( CONTROLLER_GEN) $( CLIENT_GEN) $( LISTER_GEN) $( INFORMER_GEN) $( OPENAPI_GEN) $( REGISTER_GEN) $( DEEPCOPY_GEN) $( DEFAULTER_GEN) $( APPLYCONFIGURATION_GEN) $( GEN_CRD_API_REFERENCE_DOCS) $( GO_ACC) $( GOIMPORTS) $( HELM) $( HELM_DOCS) $( KO) $( KUTTL)
2022-08-30 14:06:30 +00:00
i f e q ( $( GOOS ) , d a r w i n )
SED := gsed
e l s e
SED := sed
e n d i f
2023-04-06 15:05:34 +00:00
COMMA := ,
2022-08-25 16:59:24 +00:00
$(KIND) :
2022-09-28 12:39:03 +00:00
@echo Install kind... >& 2
2022-08-25 16:59:24 +00:00
@GOBIN= $( TOOLS_DIR) go install sigs.k8s.io/kind@$( KIND_VERSION)
$(CONTROLLER_GEN) :
2022-09-28 12:39:03 +00:00
@echo Install controller-gen... >& 2
2022-08-25 16:59:24 +00:00
@GOBIN= $( TOOLS_DIR) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$( CONTROLLER_GEN_VERSION)
2022-09-01 06:14:56 +00:00
$(CLIENT_GEN) :
2022-09-28 12:39:03 +00:00
@echo Install client-gen... >& 2
2022-09-01 06:14:56 +00:00
@GOBIN= $( TOOLS_DIR) go install k8s.io/code-generator/cmd/client-gen@$( CODE_GEN_VERSION)
$(LISTER_GEN) :
2022-09-28 12:39:03 +00:00
@echo Install lister-gen... >& 2
2022-09-01 06:14:56 +00:00
@GOBIN= $( TOOLS_DIR) go install k8s.io/code-generator/cmd/lister-gen@$( CODE_GEN_VERSION)
$(INFORMER_GEN) :
2022-09-28 12:39:03 +00:00
@echo Install informer-gen... >& 2
2022-09-01 06:14:56 +00:00
@GOBIN= $( TOOLS_DIR) go install k8s.io/code-generator/cmd/informer-gen@$( CODE_GEN_VERSION)
2022-09-28 11:45:16 +00:00
$(OPENAPI_GEN) :
2022-09-28 12:39:03 +00:00
@echo Install openapi-gen... >& 2
2022-09-28 11:45:16 +00:00
@GOBIN= $( TOOLS_DIR) go install k8s.io/code-generator/cmd/openapi-gen@$( CODE_GEN_VERSION)
2023-07-06 08:43:59 +00:00
$(REGISTER_GEN) :
@echo Install register-gen... >& 2
@GOBIN= $( TOOLS_DIR) go install k8s.io/code-generator/cmd/register-gen@$( CODE_GEN_VERSION)
2023-07-06 12:56:17 +00:00
$(DEEPCOPY_GEN) :
@echo Install deepcopy-gen... >& 2
@GOBIN= $( TOOLS_DIR) go install k8s.io/code-generator/cmd/deepcopy-gen@$( CODE_GEN_VERSION)
2023-07-06 11:02:36 +00:00
$(DEFAULTER_GEN) :
@echo Install defaulter-gen... >& 2
@GOBIN= $( TOOLS_DIR) go install k8s.io/code-generator/cmd/defaulter-gen@$( CODE_GEN_VERSION)
2023-07-10 09:53:25 +00:00
$(APPLYCONFIGURATION_GEN) :
@echo Install applyconfiguration-gen... >& 2
@GOBIN= $( TOOLS_DIR) go install k8s.io/code-generator/cmd/applyconfiguration-gen@$( CODE_GEN_VERSION)
2022-08-25 16:59:24 +00:00
$(GEN_CRD_API_REFERENCE_DOCS) :
2022-09-28 12:39:03 +00:00
@echo Install gen-crd-api-reference-docs... >& 2
2022-08-25 16:59:24 +00:00
@GOBIN= $( TOOLS_DIR) go install github.com/ahmetb/gen-crd-api-reference-docs@$( GEN_CRD_API_REFERENCE_DOCS_VERSION)
$(GO_ACC) :
2022-09-28 12:39:03 +00:00
@echo Install go-acc... >& 2
2022-08-25 16:59:24 +00:00
@GOBIN= $( TOOLS_DIR) go install github.com/ory/go-acc@$( GO_ACC_VERSION)
$(GOIMPORTS) :
2022-09-28 12:39:03 +00:00
@echo Install goimports... >& 2
2022-08-25 16:59:24 +00:00
@GOBIN= $( TOOLS_DIR) go install golang.org/x/tools/cmd/goimports@$( GOIMPORTS_VERSION)
2022-10-20 12:17:33 +00:00
$(HELM) :
@echo Install helm... >& 2
@GOBIN= $( TOOLS_DIR) go install helm.sh/helm/v3/cmd/helm@$( HELM_VERSION)
2022-08-25 16:59:24 +00:00
$(HELM_DOCS) :
2022-09-28 12:39:03 +00:00
@echo Install helm-docs... >& 2
2022-08-25 16:59:24 +00:00
@GOBIN= $( TOOLS_DIR) go install github.com/norwoodj/helm-docs/cmd/helm-docs@$( HELM_DOCS_VERSION)
$(KO) :
2022-09-28 12:39:03 +00:00
@echo Install ko... >& 2
2022-08-25 16:59:24 +00:00
@GOBIN= $( TOOLS_DIR) go install github.com/google/ko@$( KO_VERSION)
2022-11-07 18:01:25 +00:00
$(KUTTL) :
@echo Install kuttl... >& 2
2022-12-28 05:40:07 +00:00
@GOBIN= $( TOOLS_DIR) go install github.com/kyverno/kuttl/cmd/kubectl-kuttl@$( KUTTL_VERSION)
2022-11-07 18:01:25 +00:00
2022-08-25 16:59:24 +00:00
.PHONY : install -tools
install-tools : $( TOOLS ) ## Install tools
.PHONY : clean -tools
2022-08-30 15:30:28 +00:00
clean-tools : ## Remove installed tools
2022-09-28 12:39:03 +00:00
@echo Clean tools... >& 2
2022-08-25 16:59:24 +00:00
@rm -rf $( TOOLS_DIR)
2022-08-26 07:23:04 +00:00
#################
# BUILD (LOCAL) #
#################
2023-01-30 16:58:46 +00:00
CMD_DIR := cmd
2022-08-26 07:23:04 +00:00
KYVERNO_DIR := $( CMD_DIR) /kyverno
2023-01-29 20:49:45 +00:00
KYVERNOPRE_DIR := $( CMD_DIR) /kyverno-init
2022-08-26 07:23:04 +00:00
CLI_DIR := $( CMD_DIR) /cli/kubectl-kyverno
2022-11-14 11:00:40 +00:00
CLEANUP_DIR := $( CMD_DIR) /cleanup-controller
2023-01-18 13:38:47 +00:00
REPORTS_DIR := $( CMD_DIR) /reports-controller
2023-01-31 16:12:34 +00:00
BACKGROUND_DIR := $( CMD_DIR) /background-controller
2022-08-30 15:30:28 +00:00
KYVERNO_BIN := $( KYVERNO_DIR) /kyverno
KYVERNOPRE_BIN := $( KYVERNOPRE_DIR) /kyvernopre
CLI_BIN := $( CLI_DIR) /kubectl-kyverno
2022-11-14 11:00:40 +00:00
CLEANUP_BIN := $( CLEANUP_DIR) /cleanup-controller
2023-01-18 13:38:47 +00:00
REPORTS_BIN := $( REPORTS_DIR) /reports-controller
2023-01-31 16:12:34 +00:00
BACKGROUND_BIN := $( BACKGROUND_DIR) /background-controller
2022-08-26 07:23:04 +00:00
PACKAGE ?= github.com/kyverno/kyverno
2022-12-07 14:09:14 +00:00
CGO_ENABLED ?= 0
2023-04-07 12:10:53 +00:00
i f d e f V E R S I O N
2023-06-30 23:27:06 +00:00
LD_FLAGS := " -s -w -X $( PACKAGE) /pkg/version.BuildVersion= $( VERSION) "
2023-04-07 12:10:53 +00:00
e l s e
2023-06-30 23:27:06 +00:00
LD_FLAGS := "-s -w"
2023-04-07 12:10:53 +00:00
e n d i f
2022-08-26 07:23:04 +00:00
.PHONY : fmt
fmt : ## Run go fmt
2022-09-28 12:39:03 +00:00
@echo Go fmt... >& 2
2022-08-30 04:59:08 +00:00
@go fmt ./...
2022-08-26 07:23:04 +00:00
.PHONY : vet
vet : ## Run go vet
2022-09-28 12:39:03 +00:00
@echo Go vet... >& 2
2022-08-30 04:59:08 +00:00
@go vet ./...
2022-08-26 07:23:04 +00:00
2023-01-06 20:42:21 +00:00
.PHONY : imports
imports : $( GOIMPORTS )
@echo Go imports... >& 2
@$( GOIMPORTS) -w .
.PHONY : fmt -check
fmt-check : fmt
@echo Checking code format... >& 2
@git --no-pager diff .
@echo 'If this test fails, it is because the git diff is non-empty after running "make fmt".' >& 2
@echo 'To correct this, locally run "make fmt" and commit the changes.' >& 2
@git diff --quiet --exit-code .
.PHONY : imports -check
imports-check : imports
@echo Checking go imports... >& 2
@git --no-pager diff .
@echo 'If this test fails, it is because the git diff is non-empty after running "make imports-check".' >& 2
@echo 'To correct this, locally run "make imports" and commit the changes.' >& 2
@git diff --quiet --exit-code .
2022-09-02 15:14:04 +00:00
.PHONY : unused -package -check
unused-package-check :
@tidy= $$ ( go mod tidy) ; \
if [ -n " $$ {tidy} " ] ; then \
echo "go mod tidy checking failed!" ; echo " $$ {tidy} " ; echo; \
fi
2022-08-30 15:30:28 +00:00
$(KYVERNOPRE_BIN) : fmt vet
2022-09-28 12:39:03 +00:00
@echo Build kyvernopre binary... >& 2
2023-02-03 14:33:36 +00:00
@CGO_ENABLED= $( CGO_ENABLED) GOOS = $( GOOS) \
go build -o ./$( KYVERNOPRE_BIN) -ldflags= $( LD_FLAGS) ./$( KYVERNOPRE_DIR)
2022-08-26 07:23:04 +00:00
2022-09-02 13:34:22 +00:00
$(KYVERNO_BIN) : fmt vet
2022-09-28 12:39:03 +00:00
@echo Build kyverno binary... >& 2
2023-02-03 14:33:36 +00:00
@CGO_ENABLED= $( CGO_ENABLED) GOOS = $( GOOS) \
go build -o ./$( KYVERNO_BIN) -ldflags= $( LD_FLAGS) ./$( KYVERNO_DIR)
2022-09-02 13:34:22 +00:00
2022-08-30 15:30:28 +00:00
$(CLI_BIN) : fmt vet
2022-09-28 12:39:03 +00:00
@echo Build cli binary... >& 2
2023-04-07 21:07:32 +00:00
@CGO_ENABLED= $( CGO_ENABLED) GOOS = $( GOOS) \
2023-02-03 14:33:36 +00:00
go build -o ./$( CLI_BIN) -ldflags= $( LD_FLAGS) ./$( CLI_DIR)
2022-08-26 07:23:04 +00:00
2022-11-14 11:00:40 +00:00
$(CLEANUP_BIN) : fmt vet
@echo Build cleanup controller binary... >& 2
2023-02-03 14:33:36 +00:00
@CGO_ENABLED= $( CGO_ENABLED) GOOS = $( GOOS) \
go build -o ./$( CLEANUP_BIN) -ldflags= $( LD_FLAGS) ./$( CLEANUP_DIR)
2022-11-14 11:00:40 +00:00
2023-01-18 13:38:47 +00:00
$(REPORTS_BIN) : fmt vet
@echo Build reports controller binary... >& 2
2023-02-03 14:33:36 +00:00
@CGO_ENABLED= $( CGO_ENABLED) GOOS = $( GOOS) \
go build -o ./$( REPORTS_BIN) -ldflags= $( LD_FLAGS) ./$( REPORTS_DIR)
2023-01-18 13:38:47 +00:00
2023-02-02 08:56:00 +00:00
$(BACKGROUND_BIN) : fmt vet
2023-01-31 16:12:34 +00:00
@echo Build background controller binary... >& 2
2023-02-03 14:33:36 +00:00
@CGO_ENABLED= $( CGO_ENABLED) GOOS = $( GOOS) \
go build -o ./$( BACKGROUND_BIN) -ldflags= $( LD_FLAGS) ./$( BACKGROUND_DIR)
2023-01-31 16:12:34 +00:00
2023-01-29 20:49:45 +00:00
.PHONY : build -kyverno -init
build-kyverno-init : $( KYVERNOPRE_BIN ) ## Build kyvernopre binary
2022-08-26 07:23:04 +00:00
2022-09-01 10:16:36 +00:00
.PHONY : build -kyverno
build-kyverno : $( KYVERNO_BIN ) ## Build kyverno binary
2022-08-26 07:23:04 +00:00
.PHONY : build -cli
2022-09-01 10:16:36 +00:00
build-cli : $( CLI_BIN ) ## Build cli binary
2022-08-26 07:23:04 +00:00
2022-11-14 11:00:40 +00:00
.PHONY : build -cleanup -controller
build-cleanup-controller : $( CLEANUP_BIN ) ## Build cleanup controller binary
2023-01-18 13:38:47 +00:00
.PHONY : build -reports -controller
build-reports-controller : $( REPORTS_BIN ) ## Build reports controller binary
2023-01-31 16:12:34 +00:00
.PHONY : build -background -controller
build-background-controller : $( BACKGROUND_BIN ) ## Build background controller binary
build-all : build -kyverno -init build -kyverno build -cli build -cleanup -controller build -reports -controller build -background -controller ## Build all binaries
2022-08-26 07:23:04 +00:00
##############
# BUILD (KO) #
##############
2022-09-01 01:04:47 +00:00
LOCAL_PLATFORM := linux/$( GOARCH)
2023-01-30 16:58:46 +00:00
KO_REGISTRY := ko.local
2023-04-07 12:10:53 +00:00
i f n d e f V E R S I O N
KO_TAGS := $( GIT_SHA)
e l s e i f e q ( $( VERSION ) , m a i n )
KO_TAGS := $( GIT_SHA) ,latest
e l s e
KO_TAGS := $( GIT_SHA) ,$( subst /,-,$( VERSION) )
e n d i f
2023-01-30 16:58:46 +00:00
KO_CLI_REPO := $( PACKAGE) /$( CLI_DIR)
KO_KYVERNOPRE_REPO := $( PACKAGE) /$( KYVERNOPRE_DIR)
KO_KYVERNO_REPO := $( PACKAGE) /$( KYVERNO_DIR)
KO_CLEANUP_REPO := $( PACKAGE) /$( CLEANUP_DIR)
KO_REPORTS_REPO := $( PACKAGE) /$( REPORTS_DIR)
2023-02-28 09:33:53 +00:00
KO_BACKGROUND_REPO := $( PACKAGE) /$( BACKGROUND_DIR)
2022-08-26 07:23:04 +00:00
2023-01-29 20:49:45 +00:00
.PHONY : ko -build -kyverno -init
ko-build-kyverno-init : $( KO ) ## Build kyvernopre local image (with ko)
2022-09-28 12:39:03 +00:00
@echo Build kyvernopre local image with ko... >& 2
2023-04-07 21:07:32 +00:00
@LD_FLAGS= $( LD_FLAGS) KOCACHE = $( KOCACHE) KO_DOCKER_REPO = $( KO_REGISTRY) \
2023-04-07 12:10:53 +00:00
$( KO) build ./$( KYVERNOPRE_DIR) --preserve-import-paths --tags= $( KO_TAGS) --platform= $( LOCAL_PLATFORM)
2022-08-26 07:23:04 +00:00
.PHONY : ko -build -kyverno
2022-08-30 15:30:28 +00:00
ko-build-kyverno : $( KO ) ## Build kyverno local image (with ko)
2022-09-28 12:39:03 +00:00
@echo Build kyverno local image with ko... >& 2
2023-04-07 12:10:53 +00:00
@LD_FLAGS= $( LD_FLAGS) KOCACHE = $( KOCACHE) KO_DOCKER_REPO = $( KO_REGISTRY) \
$( KO) build ./$( KYVERNO_DIR) --preserve-import-paths --tags= $( KO_TAGS) --platform= $( LOCAL_PLATFORM)
2022-08-26 07:23:04 +00:00
.PHONY : ko -build -cli
2022-09-01 10:16:36 +00:00
ko-build-cli : $( KO ) ## Build cli local image (with ko)
2022-09-28 12:39:03 +00:00
@echo Build cli local image with ko... >& 2
2023-04-07 12:10:53 +00:00
@LD_FLAGS= $( LD_FLAGS) KOCACHE = $( KOCACHE) KO_DOCKER_REPO = $( KO_REGISTRY) \
$( KO) build ./$( CLI_DIR) --preserve-import-paths --tags= $( KO_TAGS) --platform= $( LOCAL_PLATFORM)
2022-08-26 07:23:04 +00:00
2022-11-14 11:00:40 +00:00
.PHONY : ko -build -cleanup -controller
ko-build-cleanup-controller : $( KO ) ## Build cleanup controller local image (with ko)
@echo Build cleanup controller local image with ko... >& 2
2023-04-07 12:10:53 +00:00
@LD_FLAGS= $( LD_FLAGS) KOCACHE = $( KOCACHE) KO_DOCKER_REPO = $( KO_REGISTRY) \
$( KO) build ./$( CLEANUP_DIR) --preserve-import-paths --tags= $( KO_TAGS) --platform= $( LOCAL_PLATFORM)
2022-11-14 11:00:40 +00:00
2023-01-18 13:38:47 +00:00
.PHONY : ko -build -reports -controller
ko-build-reports-controller : $( KO ) ## Build reports controller local image (with ko)
@echo Build reports controller local image with ko... >& 2
2023-04-07 12:10:53 +00:00
@LD_FLAGS= $( LD_FLAGS) KOCACHE = $( KOCACHE) KO_DOCKER_REPO = $( KO_REGISTRY) \
$( KO) build ./$( REPORTS_DIR) --preserve-import-paths --tags= $( KO_TAGS) --platform= $( LOCAL_PLATFORM)
2023-01-18 13:38:47 +00:00
2023-01-31 16:12:34 +00:00
.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
2023-04-07 12:10:53 +00:00
@LD_FLAGS= $( LD_FLAGS) KOCACHE = $( KOCACHE) KO_DOCKER_REPO = $( KO_REGISTRY) \
$( KO) build ./$( BACKGROUND_DIR) --preserve-import-paths --tags= $( KO_TAGS) --platform= $( LOCAL_PLATFORM)
2023-01-31 16:12:34 +00:00
2022-08-30 15:30:28 +00:00
.PHONY : ko -build -all
2023-01-31 16:12:34 +00:00
ko-build-all : ko -build -kyverno -init ko -build -kyverno ko -build -cli ko -build -cleanup -controller ko -build -reports -controller ko -build -background -controller ## Build all local images (with ko)
2022-08-26 07:23:04 +00:00
2022-08-30 15:30:28 +00:00
################
# PUBLISH (KO) #
################
2022-08-26 07:23:04 +00:00
2022-09-02 13:34:22 +00:00
REGISTRY_USERNAME ?= dummy
2023-02-14 06:02:37 +00:00
PLATFORMS := all
2022-08-26 07:23:04 +00:00
2022-08-30 15:30:28 +00:00
.PHONY : ko -login
ko-login : $( KO )
@$( KO) login $( REGISTRY) --username $( REGISTRY_USERNAME) --password $( REGISTRY_PASSWORD)
2022-08-26 07:23:04 +00:00
2023-01-29 20:49:45 +00:00
.PHONY : ko -publish -kyverno -init
ko-publish-kyverno-init : ko -login ## Build and publish kyvernopre image (with ko)
2023-02-03 14:33:36 +00:00
@LD_FLAGS= $( LD_FLAGS) KOCACHE = $( KOCACHE) KO_DOCKER_REPO = $( REPO_KYVERNOPRE) \
$( KO) build ./$( KYVERNOPRE_DIR) --bare --tags= $( KO_TAGS) --platform= $( PLATFORMS)
2022-08-26 07:23:04 +00:00
2022-08-30 15:30:28 +00:00
.PHONY : ko -publish -kyverno
2022-09-01 10:16:36 +00:00
ko-publish-kyverno : ko -login ## Build and publish kyverno image (with ko)
2023-02-03 14:33:36 +00:00
@LD_FLAGS= $( LD_FLAGS) KOCACHE = $( KOCACHE) KO_DOCKER_REPO = $( REPO_KYVERNO) \
$( KO) build ./$( KYVERNO_DIR) --bare --tags= $( KO_TAGS) --platform= $( PLATFORMS)
2022-08-26 07:23:04 +00:00
2022-08-30 15:30:28 +00:00
.PHONY : ko -publish -cli
2022-09-01 10:16:36 +00:00
ko-publish-cli : ko -login ## Build and publish cli image (with ko)
2023-02-03 14:33:36 +00:00
@LD_FLAGS= $( LD_FLAGS) KOCACHE = $( KOCACHE) KO_DOCKER_REPO = $( REPO_CLI) \
$( KO) build ./$( CLI_DIR) --bare --tags= $( KO_TAGS) --platform= $( PLATFORMS)
2022-08-30 15:30:28 +00:00
2022-11-14 17:30:12 +00:00
.PHONY : ko -publish -cleanup -controller
ko-publish-cleanup-controller : ko -login ## Build and publish cleanup controller image (with ko)
2023-02-03 14:33:36 +00:00
@LD_FLAGS= $( LD_FLAGS) KOCACHE = $( KOCACHE) KO_DOCKER_REPO = $( REPO_CLEANUP) \
$( KO) build ./$( CLEANUP_DIR) --bare --tags= $( KO_TAGS) --platform= $( PLATFORMS)
2022-11-14 17:30:12 +00:00
2023-01-18 13:38:47 +00:00
.PHONY : ko -publish -reports -controller
ko-publish-reports-controller : ko -login ## Build and publish reports controller image (with ko)
2023-02-03 14:33:36 +00:00
@LD_FLAGS= $( LD_FLAGS) KOCACHE = $( KOCACHE) KO_DOCKER_REPO = $( REPO_REPORTS) \
$( KO) build ./$( REPORTS_DIR) --bare --tags= $( KO_TAGS) --platform= $( PLATFORMS)
2023-01-18 13:38:47 +00:00
2023-02-02 18:51:14 +00:00
.PHONY : ko -publish -background -controller
ko-publish-background-controller : ko -login ## Build and publish background controller image (with ko)
2023-02-03 14:33:36 +00:00
@LD_FLAGS= $( LD_FLAGS) KOCACHE = $( KOCACHE) KO_DOCKER_REPO = $( REPO_BACKGROUND) \
$( KO) build ./$( BACKGROUND_DIR) --bare --tags= $( KO_TAGS) --platform= $( PLATFORMS)
2023-01-31 16:12:34 +00:00
2022-08-30 15:30:28 +00:00
.PHONY : ko -publish -all
2023-02-02 18:51:14 +00:00
ko-publish-all : ko -publish -kyverno -init ko -publish -kyverno ko -publish -cli ko -publish -cleanup -controller ko -publish -reports -controller ko -publish -background -controller ## Build and publish all images (with ko)
2022-08-26 07:23:04 +00:00
2022-09-02 13:34:22 +00:00
#################
# BUILD (IMAGE) #
#################
2023-01-30 16:58:46 +00:00
LOCAL_REGISTRY := $( $( shell echo $( BUILD_WITH) | tr '[:lower:]' '[:upper:]' ) _REGISTRY)
LOCAL_CLI_REPO := $( $( shell echo $( BUILD_WITH) | tr '[:lower:]' '[:upper:]' ) _CLI_REPO)
LOCAL_KYVERNOPRE_REPO := $( $( shell echo $( BUILD_WITH) | tr '[:lower:]' '[:upper:]' ) _KYVERNOPRE_REPO)
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)
2023-02-28 09:33:53 +00:00
LOCAL_BACKGROUND_REPO := $( $( shell echo $( BUILD_WITH) | tr '[:lower:]' '[:upper:]' ) _BACKGROUND_REPO)
2022-09-02 13:34:22 +00:00
2023-01-29 20:49:45 +00:00
.PHONY : image -build -kyverno -init
image-build-kyverno-init : $( BUILD_WITH ) -build -kyverno -init
2022-09-02 13:34:22 +00:00
.PHONY : image -build -kyverno
image-build-kyverno : $( BUILD_WITH ) -build -kyverno
.PHONY : image -build -cli
image-build-cli : $( BUILD_WITH ) -build -cli
2022-11-14 17:30:12 +00:00
.PHONY : image -build -cleanup -controller
image-build-cleanup-controller : $( BUILD_WITH ) -build -cleanup -controller
2023-01-18 13:38:47 +00:00
.PHONY : image -build -reports -controller
image-build-reports-controller : $( BUILD_WITH ) -build -reports -controller
2023-01-31 16:12:34 +00:00
.PHONY : image -build -background -controller
image-build-background-controller : $( BUILD_WITH ) -build -background -controller
2022-09-02 13:34:22 +00:00
.PHONY : image -build -all
image-build-all : $( BUILD_WITH ) -build -all
2022-08-31 14:19:37 +00:00
###########
# CODEGEN #
###########
2023-07-10 09:53:25 +00:00
GOPATH_SHIM := ${ PWD } /.gopath
PACKAGE_SHIM := $( GOPATH_SHIM) /src/$( PACKAGE)
OUT_PACKAGE := $( PACKAGE) /pkg/client
INPUT_DIRS := $( PACKAGE) /api/kyverno/v1,$( PACKAGE) /api/kyverno/v1alpha2,$( PACKAGE) /api/kyverno/v1beta1,$( PACKAGE) /api/kyverno/v2beta1,$( PACKAGE) /api/kyverno/v2alpha1,$( PACKAGE) /api/policyreport/v1alpha2
CLIENTSET_PACKAGE := $( OUT_PACKAGE) /clientset
LISTERS_PACKAGE := $( OUT_PACKAGE) /listers
INFORMERS_PACKAGE := $( OUT_PACKAGE) /informers
APPLYCONFIGURATIONS_PACKAGE := $( OUT_PACKAGE) /applyconfigurations
CRDS_PATH := ${ PWD } /config/crds
INSTALL_MANIFEST_PATH := ${ PWD } /config/install-latest-testing.yaml
2022-09-01 06:14:56 +00:00
$(GOPATH_SHIM) :
2022-09-28 12:39:03 +00:00
@echo Create gopath shim... >& 2
2022-09-01 06:14:56 +00:00
@mkdir -p $( GOPATH_SHIM)
.INTERMEDIATE : $( PACKAGE_SHIM )
$(PACKAGE_SHIM) : $( GOPATH_SHIM )
2022-09-28 12:39:03 +00:00
@echo Create package shim... >& 2
2022-09-01 06:14:56 +00:00
@mkdir -p $( GOPATH_SHIM) /src/github.com/kyverno && ln -s -f ${ PWD } $( PACKAGE_SHIM)
.PHONY : codegen -client -clientset
codegen-client-clientset : $( PACKAGE_SHIM ) $( CLIENT_GEN ) ## Generate clientset
2022-09-28 12:39:03 +00:00
@echo Generate clientset... >& 2
2023-07-06 12:56:17 +00:00
@GOPATH= $( GOPATH_SHIM) $( CLIENT_GEN) \
--go-header-file ./scripts/boilerplate.go.txt \
--clientset-name versioned \
--output-package $( CLIENTSET_PACKAGE) \
--input-base "" \
--input $( INPUT_DIRS)
2022-09-01 06:14:56 +00:00
.PHONY : codegen -client -listers
codegen-client-listers : $( PACKAGE_SHIM ) $( LISTER_GEN ) ## Generate listers
2022-09-28 12:39:03 +00:00
@echo Generate listers... >& 2
2023-07-06 12:56:17 +00:00
@GOPATH= $( GOPATH_SHIM) $( LISTER_GEN) \
--go-header-file ./scripts/boilerplate.go.txt \
--output-package $( LISTERS_PACKAGE) \
--input-dirs $( INPUT_DIRS)
2022-09-01 06:14:56 +00:00
.PHONY : codegen -client -informers
codegen-client-informers : $( PACKAGE_SHIM ) $( INFORMER_GEN ) ## Generate informers
2022-09-28 12:39:03 +00:00
@echo Generate informers... >& 2
2023-07-06 12:56:17 +00:00
@GOPATH= $( GOPATH_SHIM) $( INFORMER_GEN) \
--go-header-file ./scripts/boilerplate.go.txt \
--output-package $( INFORMERS_PACKAGE) \
--input-dirs $( INPUT_DIRS) \
--versioned-clientset-package $( CLIENTSET_PACKAGE) /versioned \
--listers-package $( LISTERS_PACKAGE)
2022-09-01 06:14:56 +00:00
2022-11-17 16:01:30 +00:00
.PHONY : codegen -client -wrappers
2022-11-24 17:20:03 +00:00
codegen-client-wrappers : codegen -client -clientset $( GOIMPORTS ) ## Generate client wrappers
2022-11-17 16:01:30 +00:00
@echo Generate client wrappers... >& 2
@go run ./hack/main.go
2022-11-21 17:16:25 +00:00
@$( GOIMPORTS) -w ./pkg/clients
@go fmt ./pkg/clients/...
2022-11-17 16:01:30 +00:00
2023-07-06 08:43:59 +00:00
.PHONY : codegen -register
codegen-register : $( PACKAGE_SHIM ) $( REGISTER_GEN ) ## Generate types registrations
@echo Generate registration... >& 2
2023-07-06 12:56:17 +00:00
@GOPATH= $( GOPATH_SHIM) $( REGISTER_GEN) \
--go-header-file= ./scripts/boilerplate.go.txt \
--input-dirs= $( INPUT_DIRS)
.PHONY : codegen -deepcopy
codegen-deepcopy : $( PACKAGE_SHIM ) $( DEEPCOPY_GEN ) ## Generate deep copy functions
@echo Generate deep copy functions... >& 2
@GOPATH= $( GOPATH_SHIM) $( DEEPCOPY_GEN) \
--go-header-file= ./scripts/boilerplate.go.txt \
--input-dirs= $( INPUT_DIRS) \
--output-file-base= zz_generated.deepcopy
2023-07-06 08:43:59 +00:00
2023-07-06 11:02:36 +00:00
.PHONY : codegen -defaulters
codegen-defaulters : $( PACKAGE_SHIM ) $( DEFAULTER_GEN ) ## Generate defaulters
@echo Generate defaulters... >& 2
2023-07-10 09:53:25 +00:00
@GOPATH= $( GOPATH_SHIM) $( DEFAULTER_GEN) --go-header-file= ./scripts/boilerplate.go.txt --input-dirs= $( INPUT_DIRS)
.PHONY : codegen -applyconfigurations
codegen-applyconfigurations : $( PACKAGE_SHIM ) $( APPLYCONFIGURATION_GEN ) ## Generate apply configurations
@echo Generate applyconfigurations... >& 2
@GOPATH= $( GOPATH_SHIM) $( APPLYCONFIGURATION_GEN) \
--go-header-file= ./scripts/boilerplate.go.txt \
--input-dirs= $( INPUT_DIRS) \
--output-package $( APPLYCONFIGURATIONS_PACKAGE)
2023-07-06 11:02:36 +00:00
2022-09-01 06:14:56 +00:00
.PHONY : codegen -client -all
2023-07-10 09:53:25 +00:00
codegen-client-all : codegen -register codegen -defaulters codegen -applyconfigurations codegen -client -clientset codegen -client -listers codegen -client -informers codegen -client -wrappers ## Generate clientset, listers and informers
2022-09-01 06:14:56 +00:00
2022-08-31 14:19:37 +00:00
.PHONY : codegen -crds -kyverno
2022-09-01 10:16:36 +00:00
codegen-crds-kyverno : $( CONTROLLER_GEN ) ## Generate kyverno CRDs
2022-09-28 12:39:03 +00:00
@echo Generate kyverno crds... >& 2
2022-12-19 15:26:07 +00:00
@$( CONTROLLER_GEN) crd paths = ./api/kyverno/... crd:crdVersions= v1 output:dir= $( CRDS_PATH)
2022-08-31 14:19:37 +00:00
.PHONY : codegen -crds -report
codegen-crds-report : $( CONTROLLER_GEN ) ## Generate policy reports CRDs
2022-09-28 12:39:03 +00:00
@echo Generate policy reports crds... >& 2
2022-12-19 15:26:07 +00:00
@$( CONTROLLER_GEN) crd paths = ./api/policyreport/... crd:crdVersions= v1 output:dir= $( CRDS_PATH)
2022-08-31 14:19:37 +00:00
.PHONY : codegen -crds -all
codegen-crds-all : codegen -crds -kyverno codegen -crds -report ## Generate all CRDs
2023-08-30 13:45:43 +00:00
.PHONY : codegen -helm -docs
codegen-helm-docs : ## Generate helm docs
@echo Generate helm docs... >& 2
@docker run -v ${ PWD } /charts:/work -w /work jnorwood/helm-docs:v1.11.0 -s file
2022-09-01 11:23:31 +00:00
.PHONY : codegen -api -docs
codegen-api-docs : $( PACKAGE_SHIM ) $( GEN_CRD_API_REFERENCE_DOCS ) ## Generate API docs
2022-09-28 12:39:03 +00:00
@echo Generate api docs... >& 2
2022-10-21 14:51:15 +00:00
@rm -rf docs/user/crd && mkdir -p docs/user/crd
@GOPATH= $( GOPATH_SHIM) $( GEN_CRD_API_REFERENCE_DOCS) -v 4 \
2023-01-30 16:58:46 +00:00
-api-dir $( PACKAGE) /api \
2022-12-19 15:26:07 +00:00
-config docs/user/config.json \
-template-dir docs/user/template \
-out-file docs/user/crd/index.html
2022-09-01 11:23:31 +00:00
2023-08-30 13:45:43 +00:00
.PHONY : codegen -cli -docs
codegen-cli-docs : $( CLI_BIN ) ## Generate CLI docs
@echo Generate cli docs... >& 2
@rm -rf docs/user/cli && mkdir -p docs/user/cli
2023-08-31 15:17:26 +00:00
@$( CLI_BIN) docs -o docs/user/cli --autogenTag= false
2023-08-30 13:45:43 +00:00
.PHONY : codegen -docs -all
codegen-docs-all : codegen -helm -docs codegen -cli -docs codegen -api -docs ## Generate all docs
2022-09-02 15:14:04 +00:00
.PHONY : codegen -helm -crds
2022-12-19 15:26:07 +00:00
codegen-helm-crds : codegen -crds -all ## Generate helm CRDs
2022-09-28 12:39:03 +00:00
@echo Generate helm crds... >& 2
2022-12-19 15:26:07 +00:00
@cat $( CRDS_PATH) /* \
2023-01-20 21:01:33 +00:00
| $( SED) -e '1i{{- if .Values.crds.install }}' \
2022-12-19 15:26:07 +00:00
| $( SED) -e '$$a{{- end }}' \
2023-06-29 15:58:18 +00:00
| $( SED) -e '/^ annotations:/a \ \ \ \ {{- end }}' \
| $( SED) -e '/^ annotations:/a \ \ \ \ {{- toYaml . | nindent 4 }}' \
| $( SED) -e '/^ annotations:/a \ \ \ \ {{- with .Values.crds.annotations }}' \
| $( SED) -e '/^ annotations:/i \ \ labels:' \
| $( SED) -e '/^ labels:/a \ \ \ \ {{- include "kyverno.crds.labels" . | nindent 4 }}' \
2023-01-20 21:01:33 +00:00
> ./charts/kyverno/templates/crds/crds.yaml
2022-09-02 15:14:04 +00:00
.PHONY : codegen -helm -all
codegen-helm-all : codegen -helm -crds codegen -helm -docs ## Generate helm docs and CRDs
2023-03-15 16:28:59 +00:00
.PHONY : codegen -manifest -install -latest
codegen-manifest-install-latest : $( HELM ) ## Create install_latest manifest
@echo Generate latest install manifest... >& 2
@$( HELM) template kyverno --namespace kyverno --skip-tests ./charts/kyverno \
--set templating.enabled= true \
--set templating.version= latest \
--set admissionController.container.image.tag= latest \
--set admissionController.initContainer.image.tag= latest \
--set cleanupController.image.tag= latest \
--set reportsController.image.tag= latest \
--set backgroundController.image.tag= latest \
| $( SED) -e '/^#.*/d' \
> ./config/install-latest-testing.yaml
2022-12-19 15:26:07 +00:00
.PHONY : codegen -manifest -debug
codegen-manifest-debug : $( HELM ) ## Create debug manifest
@echo Generate debug manifest... >& 2
@mkdir -p ./.manifest
@$( HELM) template kyverno --namespace kyverno --skip-tests ./charts/kyverno \
--set templating.enabled= true \
--set templating.version= latest \
--set templating.debug= true \
2023-03-06 08:25:28 +00:00
--set admissionController.container.image.tag= latest \
2023-03-03 14:38:33 +00:00
--set admissionController.initContainer.image.tag= latest \
2023-01-28 21:40:14 +00:00
--set cleanupController.image.tag= latest \
--set reportsController.image.tag= latest \
2022-12-19 15:26:07 +00:00
| $( SED) -e '/^#.*/d' \
> ./.manifest/debug.yaml
2022-09-27 06:08:06 +00:00
# guidance https://github.com/kyverno/kyverno/wiki/Generate-a-Release
2022-12-19 15:26:07 +00:00
.PHONY : codegen -manifest -release
codegen-manifest-release : $( HELM ) ## Create release manifest
@echo Generate release manifest... >& 2
@mkdir -p ./.manifest
@$( HELM) template kyverno --namespace kyverno --skip-tests ./charts/kyverno \
--set templating.enabled= true \
2023-04-07 12:10:53 +00:00
--set templating.version= $( VERSION) \
--set admissionController.container.image.tag= $( VERSION) \
--set admissionController.initContainer.image.tag= $( VERSION) \
--set cleanupController.image.tag= $( VERSION) \
--set reportsController.image.tag= $( VERSION) \
2022-12-19 15:26:07 +00:00
| $( SED) -e '/^#.*/d' \
> ./.manifest/release.yaml
.PHONY : codegen -manifest -all
2023-04-07 12:10:53 +00:00
codegen-manifest-all : codegen -manifest -install -latest codegen -manifest -debug ## Create all manifests
2022-09-27 06:08:06 +00:00
2022-09-10 18:01:10 +00:00
.PHONY : codegen -quick
2023-08-30 13:45:43 +00:00
codegen-quick : codegen -deepcopy codegen -crds -all codegen -docs -all codegen -helm -all codegen -manifest -all ## Generate all generated code except client
2022-09-27 06:08:06 +00:00
.PHONY : codegen -slow
codegen-slow : codegen -client -all ## Generate client code
2022-09-10 18:01:10 +00:00
2022-08-31 14:19:37 +00:00
.PHONY : codegen -all
2022-09-27 06:08:06 +00:00
codegen-all : codegen -quick codegen -slow ## Generate all generated code
2022-08-31 14:19:37 +00:00
2022-09-02 09:49:35 +00:00
##################
# VERIFY CODEGEN #
##################
.PHONY : verify -crds
verify-crds : codegen -crds -all ## Check CRDs are up to date
2022-11-24 17:20:03 +00:00
@echo Checking crds are up to date... >& 2
2022-12-19 15:26:07 +00:00
@git --no-pager diff $( CRDS_PATH)
2022-10-03 15:12:43 +00:00
@echo 'If this test fails, it is because the git diff is non-empty after running "make codegen-crds-all".' >& 2
@echo 'To correct this, locally run "make codegen-crds-all", commit the changes, and re-run tests.' >& 2
2022-12-19 15:26:07 +00:00
@git diff --quiet --exit-code $( CRDS_PATH)
2022-09-02 09:49:35 +00:00
.PHONY : verify -client
verify-client : codegen -client -all ## Check client is up to date
2022-11-24 17:20:03 +00:00
@echo Checking client is up to date... >& 2
2022-09-28 09:31:06 +00:00
@git --no-pager diff --ignore-space-change pkg/client
2022-10-03 15:12:43 +00:00
@echo 'If this test fails, it is because the git diff is non-empty after running "make codegen-client-all".' >& 2
@echo 'To correct this, locally run "make codegen-client-all", commit the changes, and re-run tests.' >& 2
2022-09-28 09:31:06 +00:00
@git diff --ignore-space-change --quiet --exit-code pkg/client
2022-11-24 17:20:03 +00:00
@git --no-pager diff --ignore-space-change pkg/clients
@echo 'If this test fails, it is because the git diff is non-empty after running "make codegen-client-all".' >& 2
@echo 'To correct this, locally run "make codegen-client-all", commit the changes, and re-run tests.' >& 2
@git diff --ignore-space-change --quiet --exit-code pkg/clients
2022-09-02 09:49:35 +00:00
.PHONY : verify -deepcopy
2023-07-06 12:56:17 +00:00
verify-deepcopy : codegen -deepcopy ## Check deepcopy functions are up to date
2022-11-24 17:20:03 +00:00
@echo Checking deepcopy functions are up to date... >& 2
2022-09-02 09:49:35 +00:00
@git --no-pager diff api
2023-07-06 12:56:17 +00:00
@echo 'If this test fails, it is because the git diff is non-empty after running "make codegen-deepcopy".' >& 2
@echo 'To correct this, locally run "make codegen-deepcopy", commit the changes, and re-run tests.' >& 2
2022-09-02 09:49:35 +00:00
@git diff --quiet --exit-code api
2023-08-30 13:45:43 +00:00
.PHONY : verify -docs
2023-08-31 15:17:26 +00:00
verify-docs : codegen -docs -all ## Check docs are up to date
2023-08-31 09:19:42 +00:00
@echo Checking docs are up to date... >& 2
2023-08-31 15:17:26 +00:00
@git --no-pager diff docs/user
2023-08-30 13:45:43 +00:00
@echo 'If this test fails, it is because the git diff is non-empty after running "make codegen-docs-all".' >& 2
@echo 'To correct this, locally run "make codegen-docs-all", commit the changes, and re-run tests.' >& 2
2023-08-31 15:17:26 +00:00
@git diff --quiet --exit-code docs/user
2022-09-02 09:49:35 +00:00
2022-09-02 15:14:04 +00:00
.PHONY : verify -helm
verify-helm : codegen -helm -all ## Check Helm charts are up to date
2022-11-24 17:20:03 +00:00
@echo Checking helm charts are up to date... >& 2
2022-09-02 15:14:04 +00:00
@git --no-pager diff charts
2022-10-03 15:12:43 +00:00
@echo 'If this test fails, it is because the git diff is non-empty after running "make codegen-helm-all".' >& 2
2022-12-01 22:09:44 +00:00
@echo 'To correct this, locally run "make codegen-helm-all", commit the changes, and re-run tests.' >& 2
2022-09-02 15:14:04 +00:00
@git diff --quiet --exit-code charts
2023-03-30 11:09:40 +00:00
.PHONY : verify -manifests
verify-manifests : codegen -manifest -all ## Check manifests are up to date
@echo Checking manifests are up to date... >& 2
@git --no-pager diff ${ INSTALL_MANIFEST_PATH }
@echo 'If this test fails, it is because the git diff is non-empty after running "make codegen-manifest-all".' >& 2
@echo 'To correct this, locally run "make codegen-manifest-all", commit the changes, and re-run tests.' >& 2
@git diff --quiet --exit-code ${ INSTALL_MANIFEST_PATH }
2022-09-02 09:49:35 +00:00
.PHONY : verify -codegen
2023-08-30 13:45:43 +00:00
verify-codegen : verify -crds verify -client verify -deepcopy verify -docs verify -helm verify -manifests ## Verify all generated code and docs are up to date
2022-09-02 09:49:35 +00:00
2022-09-28 03:55:17 +00:00
##############
# UNIT TESTS #
##############
2022-03-25 16:08:38 +00:00
2022-09-28 03:55:17 +00:00
CODE_COVERAGE_FILE := coverage
CODE_COVERAGE_FILE_TXT := $( CODE_COVERAGE_FILE) .txt
CODE_COVERAGE_FILE_HTML := $( CODE_COVERAGE_FILE) .html
2022-08-26 07:23:04 +00:00
2022-09-28 03:55:17 +00:00
.PHONY : test
2022-12-21 16:12:08 +00:00
test : test -clean test -unit ## Clean tests cache then run unit tests
2022-08-26 07:23:04 +00:00
2022-09-28 03:55:17 +00:00
.PHONY : test -clean
test-clean : ## Clean tests cache
2022-09-28 12:39:03 +00:00
@echo Clean test cache... >& 2
2023-04-03 11:40:47 +00:00
@go clean -testcache
2022-03-25 16:08:38 +00:00
2022-09-28 03:55:17 +00:00
.PHONY : test -unit
test-unit : test -clean $( GO_ACC ) ## Run unit tests
2022-09-28 12:39:03 +00:00
@echo Running unit tests... >& 2
2022-09-28 03:55:17 +00:00
@$( GO_ACC) ./... -o $( CODE_COVERAGE_FILE_TXT)
2020-08-11 00:16:13 +00:00
2022-09-28 03:55:17 +00:00
.PHONY : code -cov -report
code-cov-report : test -clean ## Generate code coverage report
2022-09-28 12:39:03 +00:00
@echo Generating code coverage report... >& 2
2022-09-28 03:55:17 +00:00
@GO111MODULE= on go test -v -coverprofile= coverage.out ./...
@go tool cover -func= coverage.out -o $( CODE_COVERAGE_FILE_TXT)
@go tool cover -html= coverage.out -o $( CODE_COVERAGE_FILE_HTML)
2019-06-07 18:50:12 +00:00
2022-11-07 18:01:25 +00:00
###############
# KUTTL TESTS #
###############
.PHONY : test -kuttl
test-kuttl : $( KUTTL ) ## Run kuttl tests
@echo Running kuttl tests... >& 2
@$( KUTTL) test --config ./test/conformance/kuttl/kuttl-test.yaml
2022-09-28 03:55:17 +00:00
#############
# CLI TESTS #
#############
2019-06-07 18:50:12 +00:00
2022-09-28 03:55:17 +00:00
TEST_GIT_BRANCH ?= main
2021-07-10 01:01:46 +00:00
2022-02-24 15:34:12 +00:00
.PHONY : test -cli
2023-08-23 15:55:39 +00:00
test-cli : test -cli -policies test -cli -local test -cli -local -mutate test -cli -local -generate test -cli -test -case -selector -flag test -cli -registry test -cli -scenarios -to -cli ## Run all CLI tests
2022-02-24 15:34:12 +00:00
.PHONY : test -cli -policies
2022-08-30 15:30:28 +00:00
test-cli-policies : $( CLI_BIN )
2023-06-20 12:04:06 +00:00
@echo Testing against branch $( TEST_GIT_BRANCH) ...
2022-08-30 15:30:28 +00:00
@$( CLI_BIN) test https://github.com/kyverno/policies/$( TEST_GIT_BRANCH)
2022-02-24 15:34:12 +00:00
.PHONY : test -cli -local
2022-08-30 15:30:28 +00:00
test-cli-local : $( CLI_BIN )
@$( CLI_BIN) test ./test/cli/test
2022-02-24 15:34:12 +00:00
.PHONY : test -cli -local -mutate
2022-08-30 15:30:28 +00:00
test-cli-local-mutate : $( CLI_BIN )
2023-06-27 16:58:50 +00:00
@$( CLI_BIN) test ./test/cli/test-mutate
2022-02-24 15:34:12 +00:00
2022-05-25 14:26:22 +00:00
.PHONY : test -cli -local -generate
2022-08-30 15:30:28 +00:00
test-cli-local-generate : $( CLI_BIN )
@$( CLI_BIN) test ./test/cli/test-generate
2022-05-25 14:26:22 +00:00
2022-03-09 07:40:53 +00:00
.PHONY : test -cli -test -case -selector -flag
2022-08-30 15:30:28 +00:00
test-cli-test-case-selector-flag : $( CLI_BIN )
@$( CLI_BIN) test ./test/cli/test --test-case-selector "policy=disallow-latest-tag, rule=require-image-tag, resource=test-require-image-tag-pass"
2021-07-10 01:01:46 +00:00
2022-03-16 04:26:47 +00:00
.PHONY : test -cli -registry
2022-08-30 15:30:28 +00:00
test-cli-registry : $( CLI_BIN )
@$( CLI_BIN) test ./test/cli/registry --registry
2022-03-16 04:26:47 +00:00
2023-08-23 15:55:39 +00:00
.PHONY : test -cli -scenarios -to -cli
test-cli-scenarios-to-cli : $( CLI_BIN )
@$( CLI_BIN) test ./test/cli/scenarios_to_cli --registry
2023-01-20 07:40:44 +00:00
#############
# HELM TEST #
#############
.PHONY : helm -test
helm-test : $( HELM ) ## Run helm test
@echo Running helm test... >& 2
@$( HELM) test --namespace kyverno kyverno
2023-01-28 22:25:51 +00:00
#################
# RELEASE NOTES #
#################
2022-02-04 06:47:36 +00:00
2023-01-28 22:25:51 +00:00
.PHONY : release -notes
release-notes : ## Generate release notes
@echo Generating release notes... >& 2
2021-08-12 16:58:25 +00:00
@bash -c 'while IFS= read -r line ; do if [[ "$$line" == "## "* && "$$line" != "## $(VERSION)" ]]; then break ; fi; echo "$$line"; done < "CHANGELOG.md"' \
2021-08-10 16:07:46 +00:00
true
2022-10-06 07:41:05 +00:00
#########
# DEBUG #
#########
.PHONY : debug -deploy
2023-01-07 23:14:51 +00:00
debug-deploy : codegen -manifest -debug ## Install debug manifests
@kubectl create -f ./.manifest/debug.yaml || kubectl replace -f ./.manifest/debug.yaml
2022-10-06 07:41:05 +00:00
2022-11-17 06:31:35 +00:00
#############
# PERF TEST #
#############
PERF_TEST_NODE_COUNT ?= 3
PERF_TEST_MEMORY_REQUEST ?= "1Gi"
.PHONY : test -perf
2023-01-28 22:25:51 +00:00
test-perf : $( PACKAGE_SHIM ) ## Run perf tests
2022-11-17 06:31:35 +00:00
GO111MODULE = off GOPATH = $( GOPATH_SHIM) go get k8s.io/perf-tests || true
cd $( GOPATH_SHIM) /src/k8s.io/perf-tests && \
GOPATH = $( GOPATH_SHIM) ./run-e2e.sh cluster-loader2 \
--testconfig= ./testing/load/config.yaml \
--provider= kind \
--kubeconfig= ${ HOME } /.kube/config \
--nodes= $( PERF_TEST_NODE_COUNT) \
--prometheus-memory-request= $( PERF_TEST_MEMORY_REQUEST) \
--enable-prometheus-server= true \
--tear-down-prometheus-server= true \
--prometheus-apiserver-scrape-port= 6443 \
--prometheus-scrape-kubelets= true \
--prometheus-scrape-master-kubelets= true \
--prometheus-scrape-etcd= true \
--prometheus-scrape-kube-proxy= true \
--prometheus-kube-proxy-selector-key= k8s-app \
--prometheus-scrape-node-exporter= false \
--prometheus-scrape-kube-state-metrics= true \
--prometheus-scrape-metrics-server= true \
--prometheus-pvc-storage-class= standard \
--v= 2 \
--report-dir= .
2023-02-28 09:33:53 +00:00
##########
# DOCKER #
##########
.PHONY : docker -save -image -all
docker-save-image-all : $( KIND ) image -build -all ## Save docker images in archive
2023-04-07 12:10:53 +00:00
docker save \
$( LOCAL_REGISTRY) /$( LOCAL_KYVERNOPRE_REPO) :$( GIT_SHA) \
$( LOCAL_REGISTRY) /$( LOCAL_KYVERNO_REPO) :$( GIT_SHA) \
$( LOCAL_REGISTRY) /$( LOCAL_CLEANUP_REPO) :$( GIT_SHA) \
$( LOCAL_REGISTRY) /$( LOCAL_REPORTS_REPO) :$( GIT_SHA) \
$( LOCAL_REGISTRY) /$( LOCAL_BACKGROUND_REPO) :$( GIT_SHA) \
2023-02-28 09:33:53 +00:00
> kyverno.tar
2022-08-31 08:06:12 +00:00
########
# KIND #
########
2022-03-16 13:48:31 +00:00
2022-08-31 08:06:12 +00:00
.PHONY : kind -create -cluster
2022-09-01 10:16:36 +00:00
kind-create-cluster : $( KIND ) ## Create kind cluster
2022-09-28 12:39:03 +00:00
@echo Create kind cluster... >& 2
2023-08-21 13:56:57 +00:00
@$( KIND) create cluster --name $( KIND_NAME) --image $( KIND_IMAGE) --config ./scripts/config/kind/$( KIND_CONFIG) .yaml
2022-04-04 20:16:45 +00:00
2022-08-31 08:06:12 +00:00
.PHONY : kind -delete -cluster
2022-09-01 10:16:36 +00:00
kind-delete-cluster : $( KIND ) ## Delete kind cluster
2022-09-28 12:39:03 +00:00
@echo Delete kind cluster... >& 2
2022-08-31 08:06:12 +00:00
@$( KIND) delete cluster --name $( KIND_NAME)
2023-01-29 20:49:45 +00:00
.PHONY : kind -load -kyverno -init
kind-load-kyverno-init : $( KIND ) image -build -kyverno -init ## Build kyvernopre image and load it in kind cluster
2022-09-28 12:39:03 +00:00
@echo Load kyvernopre image... >& 2
2023-04-07 12:10:53 +00:00
@$( KIND) load docker-image --name $( KIND_NAME) $( LOCAL_REGISTRY) /$( LOCAL_KYVERNOPRE_REPO) :$( GIT_SHA)
2022-08-31 08:06:12 +00:00
.PHONY : kind -load -kyverno
2022-09-02 13:34:22 +00:00
kind-load-kyverno : $( KIND ) image -build -kyverno ## Build kyverno image and load it in kind cluster
2022-09-28 12:39:03 +00:00
@echo Load kyverno image... >& 2
2023-04-07 12:10:53 +00:00
@$( KIND) load docker-image --name $( KIND_NAME) $( LOCAL_REGISTRY) /$( LOCAL_KYVERNO_REPO) :$( GIT_SHA)
2022-08-31 08:06:12 +00:00
2022-11-14 17:30:12 +00:00
.PHONY : kind -load -cleanup -controller
kind-load-cleanup-controller : $( KIND ) image -build -cleanup -controller ## Build cleanup controller image and load it in kind cluster
@echo Load cleanup controller image... >& 2
2023-04-07 12:10:53 +00:00
@$( KIND) load docker-image --name $( KIND_NAME) $( LOCAL_REGISTRY) /$( LOCAL_CLEANUP_REPO) :$( GIT_SHA)
2022-11-14 17:30:12 +00:00
2023-01-18 13:38:47 +00:00
.PHONY : kind -load -reports -controller
kind-load-reports-controller : $( KIND ) image -build -reports -controller ## Build reports controller image and load it in kind cluster
@echo Load reports controller image... >& 2
2023-04-07 12:10:53 +00:00
@$( KIND) load docker-image --name $( KIND_NAME) $( LOCAL_REGISTRY) /$( LOCAL_REPORTS_REPO) :$( GIT_SHA)
2023-01-18 13:38:47 +00:00
2023-01-31 16:12:34 +00:00
.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
2023-04-07 12:10:53 +00:00
@$( KIND) load docker-image --name $( KIND_NAME) $( LOCAL_REGISTRY) /$( LOCAL_BACKGROUND_REPO) :$( GIT_SHA)
2023-01-31 16:12:34 +00:00
2022-08-31 08:06:12 +00:00
.PHONY : kind -load -all
2023-01-31 16:12:34 +00:00
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
2022-08-31 08:06:12 +00:00
2023-02-28 09:33:53 +00:00
.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
2022-09-28 12:39:03 +00:00
@echo Install kyverno chart... >& 2
2023-04-10 21:45:21 +00:00
@$( HELM) upgrade --install kyverno --namespace kyverno --create-namespace --wait ./charts/kyverno \
2023-03-06 08:25:28 +00:00
--set admissionController.container.image.registry= $( LOCAL_REGISTRY) \
--set admissionController.container.image.repository= $( LOCAL_KYVERNO_REPO) \
2023-04-07 12:10:53 +00:00
--set admissionController.container.image.tag= $( GIT_SHA) \
2023-03-03 14:38:33 +00:00
--set admissionController.initContainer.image.registry= $( LOCAL_REGISTRY) \
--set admissionController.initContainer.image.repository= $( LOCAL_KYVERNOPRE_REPO) \
2023-04-07 12:10:53 +00:00
--set admissionController.initContainer.image.tag= $( GIT_SHA) \
2023-01-30 16:58:46 +00:00
--set cleanupController.image.registry= $( LOCAL_REGISTRY) \
--set cleanupController.image.repository= $( LOCAL_CLEANUP_REPO) \
2023-04-07 12:10:53 +00:00
--set cleanupController.image.tag= $( GIT_SHA) \
2023-01-30 16:58:46 +00:00
--set reportsController.image.registry= $( LOCAL_REGISTRY) \
--set reportsController.image.repository= $( LOCAL_REPORTS_REPO) \
2023-04-07 12:10:53 +00:00
--set reportsController.image.tag= $( GIT_SHA) \
2023-02-28 09:33:53 +00:00
--set backgroundController.image.registry= $( LOCAL_REGISTRY) \
--set backgroundController.image.repository= $( LOCAL_BACKGROUND_REPO) \
2023-04-07 12:10:53 +00:00
--set backgroundController.image.tag= $( GIT_SHA) \
2023-04-06 15:05:34 +00:00
$( foreach CONFIG,$( subst $( COMMA) , ,$( USE_CONFIG) ) ,--values ./scripts/config/$( CONFIG) /kyverno.yaml)
2022-08-31 08:06:12 +00:00
2023-02-28 09:33:53 +00:00
.PHONY : kind -deploy -kyverno
kind-deploy-kyverno : $( HELM ) kind -load -all ## Build images, load them in kind cluster and deploy kyverno helm chart
2023-04-10 21:45:21 +00:00
@$( MAKE) kind-install-kyverno
2023-02-28 09:33:53 +00:00
2022-08-31 08:06:12 +00:00
.PHONY : kind -deploy -kyverno -policies
2022-10-20 12:17:33 +00:00
kind-deploy-kyverno-policies : $( HELM ) ## Deploy kyverno-policies helm chart
2022-09-28 12:39:03 +00:00
@echo Install kyverno-policies chart... >& 2
2022-12-12 05:58:36 +00:00
@$( HELM) upgrade --install kyverno-policies --namespace kyverno --create-namespace --wait ./charts/kyverno-policies \
2023-04-06 15:05:34 +00:00
$( foreach CONFIG,$( subst $( COMMA) , ,$( USE_CONFIG) ) ,--values ./scripts/config/$( CONFIG) /kyverno-policies.yaml)
2022-09-15 06:18:02 +00:00
2022-08-31 08:06:12 +00:00
.PHONY : kind -deploy -all
2022-12-12 05:58:36 +00:00
kind-deploy-all : | kind -deploy -kyverno kind -deploy -kyverno -policies ## Build images, load them in kind cluster and deploy helm charts
2022-08-31 08:06:12 +00:00
2022-09-15 04:15:49 +00:00
.PHONY : kind -deploy -reporter
2022-10-20 12:17:33 +00:00
kind-deploy-reporter : $( HELM ) ## Deploy policy-reporter helm chart
2022-09-28 12:39:03 +00:00
@echo Install policy-reporter chart... >& 2
2022-12-12 05:58:36 +00:00
@$( HELM) upgrade --install policy-reporter --namespace policy-reporter --create-namespace --wait \
--repo https://kyverno.github.io/policy-reporter policy-reporter \
--values ./scripts/config/standard/kyverno-reporter.yaml
2022-09-15 04:15:49 +00:00
@kubectl port-forward -n policy-reporter services/policy-reporter-ui 8082:8080
2023-01-28 23:09:54 +00:00
###########
# ROLLOUT #
###########
.PHONY : rollout -cleanup -controller
rollout-cleanup-controller : ## Rollout cleanup-controller deployment
@kubectl rollout restart deployment -n kyverno -l app.kubernetes.io/component= cleanup-controller
.PHONY : rollout -reports -controller
rollout-reports-controller : ## Rollout reports-controller deployment
@kubectl rollout restart deployment -n kyverno -l app.kubernetes.io/component= reports-controller
.PHONY : rollout -admission -controller
rollout-admission-controller : ## Rollout admission-controller deployment
@kubectl rollout restart deployment -n kyverno -l app.kubernetes.io/component= admission-controller
.PHONY : rollout -all
rollout-all : rollout -cleanup -controller rollout -reports -controller rollout -admission -controller ## Rollout all deployment
2022-12-12 05:58:36 +00:00
###########
# DEV LAB #
###########
.PHONY : dev -lab -ingress -ngingx
dev-lab-ingress-ngingx : ## Deploy ingress-ngingx
@echo Install ingress-ngingx... >& 2
@kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/kind/deploy.yaml
@sleep 15
@kubectl wait --namespace ingress-nginx --for= condition = ready pod --selector= app.kubernetes.io/component= controller --timeout= 90s
.PHONY : dev -lab -prometheus
dev-lab-prometheus : $( HELM ) ## Deploy kube-prometheus-stack helm chart
@echo Install kube-prometheus-stack chart... >& 2
2022-11-17 06:31:35 +00:00
@$( HELM) upgrade --install kube-prometheus-stack --namespace monitoring --create-namespace --wait \
--repo https://prometheus-community.github.io/helm-charts kube-prometheus-stack \
2022-12-12 05:58:36 +00:00
--values ./scripts/config/dev/kube-prometheus-stack.yaml
.PHONY : dev -lab -loki
dev-lab-loki : $( HELM ) ## Deploy loki-stack helm chart
@echo Install loki-stack chart... >& 2
@$( HELM) upgrade --install loki-stack --namespace monitoring --create-namespace --wait \
--repo https://grafana.github.io/helm-charts loki-stack \
--values ./scripts/config/dev/loki-stack.yaml
.PHONY : dev -lab -tempo
dev-lab-tempo : $( HELM ) ## Deploy tempo helm chart
@echo Install tempo chart... >& 2
@$( HELM) upgrade --install tempo --namespace monitoring --create-namespace --wait \
--repo https://grafana.github.io/helm-charts tempo \
--values ./scripts/config/dev/tempo.yaml
@kubectl apply -f ./scripts/config/dev/tempo-datasource.yaml
2023-08-24 13:04:01 +00:00
.PHONY : dev -lab -otel -collector
dev-lab-otel-collector : $( HELM ) ## Deploy tempo helm chart
@echo Install otel-collector chart... >& 2
@$( HELM) upgrade --install opentelemetry-collector --namespace monitoring --create-namespace --wait \
--repo https://open-telemetry.github.io/opentelemetry-helm-charts opentelemetry-collector \
--values ./scripts/config/dev/otel-collector.yaml
2022-12-12 05:58:36 +00:00
.PHONY : dev -lab -metrics -server
dev-lab-metrics-server : $( HELM ) ## Deploy metrics-server helm chart
@echo Install metrics-server chart... >& 2
@$( HELM) upgrade --install metrics-server --namespace kube-system --wait \
--repo https://charts.bitnami.com/bitnami metrics-server \
--values ./scripts/config/dev/metrics-server.yaml
2023-05-15 15:13:42 +00:00
.PHONY : dev -lab -all
2023-08-24 13:04:01 +00:00
dev-lab-all : dev -lab -ingress -ngingx dev -lab -metrics -server dev -lab -prometheus dev -lab -loki dev -lab -tempo dev -lab -otel -collector ## Deploy all dev lab components
2023-05-15 15:13:42 +00:00
2023-04-06 13:38:28 +00:00
.PHONY : dev -lab -policy -reporter
dev-lab-policy-reporter : $( HELM ) ## Deploy policy-reporter helm chart
@echo Install policy-reporter chart... >& 2
@$( HELM) upgrade --install policy-reporter --namespace policy-reporter --create-namespace --wait \
--repo https://kyverno.github.io/policy-reporter policy-reporter \
--values ./scripts/config/dev/policy-reporter.yaml
2023-05-05 05:41:37 +00:00
.PHONY : dev -lab -kwok
2023-05-15 15:13:42 +00:00
dev-lab-kwok : ## Deploy kwok
2023-05-05 05:41:37 +00:00
@kubectl apply -k ./scripts/config/kwok
2022-08-31 08:06:12 +00:00
########
# HELP #
########
.PHONY : help
help : ## Shows the available commands
2022-09-01 10:16:36 +00:00
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $( MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-40s\033[0m %s\n", $$1, $$2}'