2019-05-23 04:41:24 +00:00
.DEFAULT_GOAL : build
2019-05-29 21:44:21 +00:00
2019-11-18 19:41:37 +00:00
##################################
# DEFAULTS
##################################
2022-03-07 09:43:36 +00:00
2022-03-01 19:59:28 +00:00
GIT_VERSION := $( shell git describe --match "v[0-9]*" --tags $( git rev-list --tags --max-count= 1) )
2021-12-17 02:46:59 +00:00
GIT_VERSION_DEV := $( shell git describe --match "[0-9].[0-9]-dev*" )
2020-01-11 02:52:11 +00:00
GIT_BRANCH := $( shell git branch | grep \* | cut -d ' ' -f2)
GIT_HASH := $( GIT_BRANCH) /$( shell git log -1 --pretty= format:"%H" )
TIMESTAMP := $( shell date '+%Y-%m-%d_%I:%M:%S%p' )
2021-07-10 01:01:46 +00:00
CONTROLLER_GEN = controller-gen
2022-04-14 16:08:30 +00:00
CONTROLLER_GEN_REQ_VERSION := v0.8.0
2021-09-14 08:06:56 +00:00
VERSION ?= $( shell git describe --match "v[0-9]*" )
2020-01-11 02:52:11 +00:00
2020-11-24 19:49:08 +00:00
REGISTRY ?= ghcr.io
REPO = $( REGISTRY) /kyverno
2021-12-17 02:46:59 +00:00
IMAGE_TAG_LATEST_DEV = $( shell git describe --match "[0-9].[0-9]-dev*" | cut -d '-' -f-2)
IMAGE_TAG_DEV = $( GIT_VERSION_DEV)
2020-05-15 20:11:28 +00:00
IMAGE_TAG ?= $( GIT_VERSION)
2019-11-18 19:41:37 +00:00
GOOS ?= $( shell go env GOOS)
2021-11-02 02:21:10 +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
2020-10-07 22:09:52 +00:00
PACKAGE ?= github.com/kyverno/kyverno
2019-11-18 19:41:37 +00:00
LD_FLAGS = " -s -w -X $( PACKAGE) /pkg/version.BuildVersion= $( GIT_VERSION) -X $( PACKAGE) /pkg/version.BuildHash= $( GIT_HASH) -X $( PACKAGE) /pkg/version.BuildTime= $( TIMESTAMP) "
2021-12-17 02:46:59 +00:00
LD_FLAGS_DEV = " -s -w -X $( PACKAGE) /pkg/version.BuildVersion= $( GIT_VERSION_DEV) -X $( PACKAGE) /pkg/version.BuildHash= $( GIT_HASH) -X $( PACKAGE) /pkg/version.BuildTime= $( TIMESTAMP) "
2022-02-23 15:52:08 +00:00
K8S_VERSION ?= $( shell kubectl version --short | grep -i server | cut -d" " -f3 | cut -c2-)
export K8S_VERSION
2022-02-24 15:34:12 +00:00
TEST_GIT_BRANCH ?= main
2022-03-07 09:43:36 +00:00
2022-03-25 16:08:38 +00:00
KIND_VERSION = v0.11.1
KIND_IMAGE ?= kindest/node:v1.23.3
2019-11-18 19:41:37 +00:00
##################################
# KYVERNO
##################################
2019-05-29 21:44:21 +00:00
2021-03-11 18:14:46 +00:00
.PHONY : unused -package -check
unused-package-check :
@echo "------------------"
@echo "--> Check unused packages for the all kyverno components"
@echo "------------------"
@tidy= $$ ( go mod tidy) ; \
if [ -n " $$ {tidy} " ] ; then \
echo "go mod tidy checking failed!" ; echo " $$ {tidy} " ; echo; \
fi
2019-11-18 19:41:37 +00:00
KYVERNO_PATH := cmd/kyverno
2019-12-30 23:50:47 +00:00
build : kyverno
2020-02-03 21:38:24 +00:00
PWD := $( CURDIR)
2019-05-23 04:41:24 +00:00
2019-11-18 19:41:37 +00:00
##################################
2021-04-08 23:14:08 +00:00
# INIT CONTAINER
2019-11-18 19:41:37 +00:00
##################################
2022-03-07 09:43:36 +00:00
2019-11-18 19:41:37 +00:00
INITC_PATH := cmd/initContainer
INITC_IMAGE := kyvernopre
2020-08-14 19:21:06 +00:00
initContainer : fmt vet
2022-05-04 12:39:14 +00:00
GOOS = $( GOOS) go build -o $( PWD) /$( INITC_PATH) /kyvernopre -ldflags= $( LD_FLAGS) $( PWD) /$( INITC_PATH)
2019-05-23 04:41:24 +00:00
2021-02-19 02:09:01 +00:00
.PHONY : docker -build -initContainer docker -push -initContainer
2019-05-29 21:44:21 +00:00
2022-01-18 23:07:59 +00:00
docker-buildx-builder :
if ! docker buildx ls | grep -q kyverno; then \
docker buildx create --name kyverno --use; \
fi
2021-11-10 20:07:40 +00:00
docker-publish-initContainer : docker -buildx -builder docker -build -initContainer docker -push -initContainer
2019-11-18 19:41:37 +00:00
2021-11-10 20:07:40 +00:00
docker-build-initContainer : docker -buildx -builder
2022-02-22 15:40:46 +00:00
@docker buildx build --file $( PWD) /$( INITC_PATH) /Dockerfile --progress plane --platform linux/arm64,linux/amd64,linux/s390x --tag $( REPO) /$( INITC_IMAGE) :$( IMAGE_TAG) . --build-arg LD_FLAGS = $( LD_FLAGS)
2019-05-23 04:41:24 +00:00
2021-11-10 20:07:40 +00:00
docker-build-initContainer-amd64 :
2022-02-03 07:41:58 +00:00
@docker build -f $( PWD) /$( INITC_PATH) /Dockerfile -t $( REPO) /$( INITC_IMAGE) :$( IMAGE_TAG_DEV) . --build-arg LD_FLAGS = $( LD_FLAGS) --build-arg TARGETPLATFORM = "linux/amd64"
@docker tag $( REPO) /$( INITC_IMAGE) :$( IMAGE_TAG_DEV) $( REPO) /$( INITC_IMAGE) :latest
2019-05-23 04:41:24 +00:00
2021-11-10 20:07:40 +00:00
docker-push-initContainer : docker -buildx -builder
2022-02-22 15:40:46 +00:00
@docker buildx build --file $( PWD) /$( INITC_PATH) /Dockerfile --progress plane --push --platform linux/arm64,linux/amd64,linux/s390x --tag $( REPO) /$( INITC_IMAGE) :$( IMAGE_TAG) . --build-arg LD_FLAGS = $( LD_FLAGS)
2019-05-29 21:44:21 +00:00
2022-01-10 14:10:44 +00:00
docker-get-initContainer-digest :
@docker buildx imagetools inspect --raw $( REPO) /$( INITC_IMAGE) :$( IMAGE_TAG) | perl -pe 'chomp if eof' | openssl dgst -sha256 | sed 's/^.* //'
2021-10-06 23:12:07 +00:00
docker-build-initContainer-local :
2022-05-04 12:39:14 +00:00
CGO_ENABLED = 0 GOOS = linux go build -o $( PWD) /$( INITC_PATH) /kyvernopre -ldflags= $( LD_FLAGS) $( PWD) /$( INITC_PATH)
2022-02-18 01:47:35 +00:00
@docker build -f $( PWD) /$( INITC_PATH) /localDockerfile -t $( REPO) /$( INITC_IMAGE) :$( IMAGE_TAG_DEV) $( PWD) /$( INITC_PATH)
@docker tag $( REPO) /$( INITC_IMAGE) :$( IMAGE_TAG_DEV) $( REPO) /$( INITC_IMAGE) :latest
2021-10-06 23:12:07 +00:00
2021-12-17 02:46:59 +00:00
docker-publish-initContainer-dev : docker -buildx -builder docker -push -initContainer -dev
docker-push-initContainer-dev : docker -buildx -builder
2022-02-22 15:40:46 +00:00
@docker buildx build --file $( PWD) /$( INITC_PATH) /Dockerfile --progress plane --push --platform linux/arm64,linux/amd64,linux/s390x --tag $( REPO) /$( INITC_IMAGE) :$( IMAGE_TAG_DEV) . --build-arg LD_FLAGS = $( LD_FLAGS_DEV)
@docker buildx build --file $( PWD) /$( INITC_PATH) /Dockerfile --progress plane --push --platform linux/arm64,linux/amd64,linux/s390x --tag $( REPO) /$( INITC_IMAGE) :$( IMAGE_TAG_LATEST_DEV) -latest . --build-arg LD_FLAGS = $( LD_FLAGS_DEV)
2022-02-28 19:02:24 +00:00
@docker buildx build --file $( PWD) /$( INITC_PATH) /Dockerfile --progress plane --push --platform linux/arm64,linux/amd64,linux/s390x --tag $( REPO) /$( INITC_IMAGE) :latest . --build-arg LD_FLAGS = $( LD_FLAGS_DEV)
2021-12-17 02:46:59 +00:00
2022-03-01 13:06:16 +00:00
docker-get-initContainer-digest-dev :
2022-01-06 14:48:20 +00:00
@docker buildx imagetools inspect --raw $( REPO) /$( INITC_IMAGE) :$( IMAGE_TAG_DEV) | perl -pe 'chomp if eof' | openssl dgst -sha256 | sed 's/^.* //'
2022-03-07 09:43:36 +00:00
2019-11-18 19:41:37 +00:00
##################################
# KYVERNO CONTAINER
##################################
2022-03-07 09:43:36 +00:00
2021-02-19 02:09:01 +00:00
.PHONY : docker -build -kyverno docker -push -kyverno
2019-11-18 19:41:37 +00:00
KYVERNO_PATH := cmd/kyverno
KYVERNO_IMAGE := kyverno
2020-05-17 16:51:46 +00:00
local :
2022-01-26 07:28:36 +00:00
go build -ldflags= $( LD_FLAGS) $( PWD) /$( KYVERNO_PATH)
go build -ldflags= $( LD_FLAGS) $( PWD) /$( CLI_PATH)
2020-05-17 16:51:46 +00:00
2020-08-14 19:21:06 +00:00
kyverno : fmt vet
2022-05-04 12:39:14 +00:00
GOOS = $( GOOS) go build -o $( PWD) /$( KYVERNO_PATH) /kyverno -ldflags= $( LD_FLAGS) $( PWD) /$( KYVERNO_PATH)
2019-12-30 23:50:47 +00:00
2021-11-10 20:07:40 +00:00
docker-publish-kyverno : docker -buildx -builder docker -build -kyverno docker -push -kyverno
2019-05-29 21:44:21 +00:00
2021-11-10 20:07:40 +00:00
docker-build-kyverno : docker -buildx -builder
2022-02-22 15:40:46 +00:00
@docker buildx build --file $( PWD) /$( KYVERNO_PATH) /Dockerfile --progress plane --platform linux/arm64,linux/amd64,linux/s390x --tag $( REPO) /$( KYVERNO_IMAGE) :$( IMAGE_TAG) . --build-arg LD_FLAGS = $( LD_FLAGS)
2019-06-05 01:05:10 +00:00
2021-07-10 01:01:46 +00:00
docker-build-kyverno-local :
2022-05-04 12:39:14 +00:00
CGO_ENABLED = 0 GOOS = linux go build -o $( PWD) /$( KYVERNO_PATH) /kyverno -ldflags= $( LD_FLAGS_DEV) $( PWD) /$( KYVERNO_PATH)
2022-01-17 04:06:44 +00:00
@docker build -f $( PWD) /$( KYVERNO_PATH) /localDockerfile -t $( REPO) /$( KYVERNO_IMAGE) :$( IMAGE_TAG_DEV) -t $( REPO) /$( KYVERNO_IMAGE) :latest $( PWD) /$( KYVERNO_PATH)
2022-01-05 07:47:42 +00:00
@docker tag $( REPO) /$( KYVERNO_IMAGE) :$( IMAGE_TAG_DEV) $( REPO) /$( KYVERNO_IMAGE) :$( IMAGE_TAG_LATEST_DEV) -latest
2021-02-08 03:46:50 +00:00
2021-02-19 02:09:01 +00:00
docker-build-kyverno-amd64 :
2022-02-03 07:41:58 +00:00
@docker build -f $( PWD) /$( KYVERNO_PATH) /Dockerfile -t $( REPO) /$( KYVERNO_IMAGE) :$( IMAGE_TAG_DEV) . --build-arg LD_FLAGS = $( LD_FLAGS) --build-arg TARGETPLATFORM = "linux/amd64"
@docker tag $( REPO) /$( KYVERNO_IMAGE) :$( IMAGE_TAG_DEV) $( REPO) /$( KYVERNO_IMAGE) :latest
2019-06-05 01:05:10 +00:00
2021-11-10 20:07:40 +00:00
docker-push-kyverno : docker -buildx -builder
2022-02-22 15:40:46 +00:00
@docker buildx build --file $( PWD) /$( KYVERNO_PATH) /Dockerfile --progress plane --push --platform linux/arm64,linux/amd64,linux/s390x --tag $( REPO) /$( KYVERNO_IMAGE) :$( IMAGE_TAG) . --build-arg LD_FLAGS = $( LD_FLAGS)
2019-06-05 01:05:10 +00:00
2022-01-10 14:10:44 +00:00
docker-get-kyverno-digest :
@docker buildx imagetools inspect --raw $( REPO) /$( KYVERNO_IMAGE) :$( IMAGE_TAG) | perl -pe 'chomp if eof' | openssl dgst -sha256 | sed 's/^.* //'
2021-12-17 02:46:59 +00:00
docker-publish-kyverno-dev : docker -buildx -builder docker -push -kyverno -dev
docker-push-kyverno-dev : docker -buildx -builder
2022-02-22 15:40:46 +00:00
@docker buildx build --file $( PWD) /$( KYVERNO_PATH) /Dockerfile --progress plane --push --platform linux/arm64,linux/amd64,linux/s390x --tag $( REPO) /$( KYVERNO_IMAGE) :$( IMAGE_TAG_DEV) . --build-arg LD_FLAGS = $( LD_FLAGS_DEV)
@docker buildx build --file $( PWD) /$( KYVERNO_PATH) /Dockerfile --progress plane --push --platform linux/arm64,linux/amd64,linux/s390x --tag $( REPO) /$( KYVERNO_IMAGE) :$( IMAGE_TAG_LATEST_DEV) -latest . --build-arg LD_FLAGS = $( LD_FLAGS_DEV)
2022-02-28 19:02:24 +00:00
@docker buildx build --file $( PWD) /$( KYVERNO_PATH) /Dockerfile --progress plane --push --platform linux/arm64,linux/amd64,linux/s390x --tag $( REPO) /$( KYVERNO_IMAGE) :latest . --build-arg LD_FLAGS = $( LD_FLAGS_DEV)
2022-01-06 14:48:20 +00:00
2022-03-01 13:06:16 +00:00
docker-get-kyverno-digest-dev :
2022-01-06 14:48:20 +00:00
@docker buildx imagetools inspect --raw $( REPO) /$( KYVERNO_IMAGE) :$( IMAGE_TAG_DEV) | perl -pe 'chomp if eof' | openssl dgst -sha256 | sed 's/^.* //'
2020-08-06 06:26:31 +00:00
2022-03-07 09:43:36 +00:00
##################################
2020-07-20 14:35:06 +00:00
# Generate Docs for types.go
##################################
2022-03-11 14:32:59 +00:00
.PHONY : gen -crd -api -reference -docs
gen-crd-api-reference-docs : ## Install gen-crd-api-reference-docs
go install github.com/ahmetb/gen-crd-api-reference-docs@latest
.PHONY : gen -crd -api -reference -docs
generate-api-docs : gen -crd -api -reference -docs ## Generate api reference docs
rm -rf docs/crd
mkdir docs/crd
gen-crd-api-reference-docs -v 6 -api-dir ./api/kyverno/v1alpha2 -config docs/config.json -template-dir docs/template -out-file docs/crd/v1alpha2/index.html
2022-04-25 12:20:40 +00:00
gen-crd-api-reference-docs -v 6 -api-dir ./api/kyverno/v1beta1 -config docs/config.json -template-dir docs/template -out-file docs/crd/v1beta1/index.html
2022-03-11 14:32:59 +00:00
gen-crd-api-reference-docs -v 6 -api-dir ./api/kyverno/v1 -config docs/config.json -template-dir docs/template -out-file docs/crd/v1/index.html
.PHONY : verify -api -docs
verify-api-docs : generate -api -docs ## Check api reference docs are up to date
2022-03-16 09:31:35 +00:00
git --no-pager diff docs
2022-03-11 14:32:59 +00:00
@echo 'If this test fails, it is because the git diff is non-empty after running "make generate-api-docs".'
@echo 'To correct this, locally run "make generate-api-docs", commit the changes, and re-run tests.'
git diff --quiet --exit-code docs
2019-06-05 01:05:10 +00:00
2019-11-18 19:41:37 +00:00
##################################
# CLI
##################################
2021-02-19 02:09:01 +00:00
.PHONY : docker -build -cli docker -push -cli
2020-02-20 03:13:05 +00:00
CLI_PATH := cmd/cli/kubectl-kyverno
2020-08-21 16:45:04 +00:00
KYVERNO_CLI_IMAGE := kyverno-cli
2019-11-18 19:41:37 +00:00
cli :
2022-05-04 12:39:14 +00:00
GOOS = $( GOOS) go build -o $( PWD) /$( CLI_PATH) /kyverno -ldflags= $( LD_FLAGS) $( PWD) /$( CLI_PATH)
2019-06-05 01:05:10 +00:00
2021-11-10 20:07:40 +00:00
docker-publish-cli : docker -buildx -builder docker -build -cli docker -push -cli
2020-08-21 16:45:04 +00:00
2021-11-10 20:07:40 +00:00
docker-build-cli : docker -buildx -builder
2022-02-22 15:40:46 +00:00
@docker buildx build --file $( PWD) /$( CLI_PATH) /Dockerfile --progress plane --platform linux/arm64,linux/amd64,linux/s390x --tag $( REPO) /$( KYVERNO_CLI_IMAGE) :$( IMAGE_TAG) . --build-arg LD_FLAGS = $( LD_FLAGS)
2020-08-21 16:45:04 +00:00
2021-02-19 02:09:01 +00:00
docker-build-cli-amd64 :
2022-02-03 07:41:58 +00:00
@docker build -f $( PWD) /$( CLI_PATH) /Dockerfile -t $( REPO) /$( KYVERNO_CLI_IMAGE) :$( IMAGE_TAG_DEV) . --build-arg LD_FLAGS = $( LD_FLAGS) --build-arg TARGETPLATFORM = "linux/amd64"
@docker tag $( REPO) /$( KYVERNO_CLI_IMAGE) :$( IMAGE_TAG_DEV) $( REPO) /$( KYVERNO_CLI_IMAGE) :latest
2020-08-21 16:45:04 +00:00
2021-11-10 20:07:40 +00:00
docker-push-cli : docker -buildx -builder
2022-02-22 15:40:46 +00:00
@docker buildx build --file $( PWD) /$( CLI_PATH) /Dockerfile --progress plane --push --platform linux/arm64,linux/amd64,linux/s390x --tag $( REPO) /$( KYVERNO_CLI_IMAGE) :$( IMAGE_TAG) . --build-arg LD_FLAGS = $( LD_FLAGS)
2021-04-08 23:14:08 +00:00
2022-01-10 14:10:44 +00:00
docker-get-cli-digest :
@docker buildx imagetools inspect --raw $( REPO) /$( KYVERNO_CLI_IMAGE) :$( IMAGE_TAG) | perl -pe 'chomp if eof' | openssl dgst -sha256 | sed 's/^.* //'
2021-12-17 02:46:59 +00:00
docker-publish-cli-dev : docker -buildx -builder docker -push -cli -dev
docker-push-cli-dev : docker -buildx -builder
2022-02-22 15:40:46 +00:00
@docker buildx build --file $( PWD) /$( CLI_PATH) /Dockerfile --progress plane --push --platform linux/arm64,linux/amd64,linux/s390x --tag $( REPO) /$( KYVERNO_CLI_IMAGE) :$( IMAGE_TAG_DEV) . --build-arg LD_FLAGS = $( LD_FLAGS_DEV)
@docker buildx build --file $( PWD) /$( CLI_PATH) /Dockerfile --progress plane --push --platform linux/arm64,linux/amd64,linux/s390x --tag $( REPO) /$( KYVERNO_CLI_IMAGE) :$( IMAGE_TAG_LATEST_DEV) -latest . --build-arg LD_FLAGS = $( LD_FLAGS_DEV)
2022-02-28 19:02:24 +00:00
@docker buildx build --file $( PWD) /$( CLI_PATH) /Dockerfile --progress plane --push --platform linux/arm64,linux/amd64,linux/s390x --tag $( REPO) /$( KYVERNO_CLI_IMAGE) :latest . --build-arg LD_FLAGS = $( LD_FLAGS_DEV)
2021-12-17 02:46:59 +00:00
2022-03-01 13:06:16 +00:00
docker-get-cli-digest-dev :
2022-01-06 14:48:20 +00:00
@docker buildx imagetools inspect --raw $( REPO) /$( KYVERNO_CLI_IMAGE) :$( IMAGE_TAG_DEV) | perl -pe 'chomp if eof' | openssl dgst -sha256 | sed 's/^.* //'
2020-08-06 06:26:31 +00:00
##################################
2021-11-10 20:07:40 +00:00
docker-publish-all : docker -buildx -builder docker -publish -initContainer docker -publish -kyverno docker -publish -cli
2020-08-11 16:32:51 +00:00
2021-11-10 20:07:40 +00:00
docker-build-all : docker -buildx -builder docker -build -initContainer docker -build -kyverno docker -build -cli
2020-08-21 16:45:04 +00:00
2021-11-10 20:07:40 +00:00
docker-build-all-amd64 : docker -buildx -builder docker -build -initContainer -amd 64 docker -build -kyverno -amd 64 docker -build -cli -amd 64
2020-11-09 19:26:12 +00:00
2020-08-21 16:45:04 +00:00
##################################
2020-12-15 19:46:53 +00:00
# Create e2e Infrastruture
2020-08-21 16:45:04 +00:00
##################################
2020-08-11 16:32:51 +00:00
2022-03-25 16:08:38 +00:00
.PHONY : kind -install
kind-install : ## Install kind
i f e q ( , $( shell which kind ) )
go install sigs.k8s.io/kind@$( KIND_VERSION)
e n d i f
.PHONY : kind -e 2e -cluster
kind-e2e-cluster : kind -install ## Create kind cluster for e2e tests
kind create cluster --image= $( KIND_IMAGE)
.PHONY : e 2e -kustomize
e2e-kustomize : kustomize ## Build kustomize manifests for e2e tests
cd config && \
kustomize edit set image $( REPO) /$( KYVERNO_IMAGE) :$( IMAGE_TAG_DEV) && \
kustomize edit set image $( REPO) /$( INITC_IMAGE) :$( IMAGE_TAG_DEV)
kustomize build config/ -o config/install.yaml
.PHONY : e 2e -init -container
e2e-init-container : kind -e 2e -cluster docker -build -initContainer -local
kind load docker-image $( REPO) /$( INITC_IMAGE) :$( IMAGE_TAG_DEV)
.PHONY : e 2e -kyverno -container
e2e-kyverno-container : kind -e 2e -cluster docker -build -kyverno -local
kind load docker-image $( REPO) /$( KYVERNO_IMAGE) :$( IMAGE_TAG_DEV)
.PHONY : create -e 2e -infrastruture
create-e2e-infrastruture : e 2e -init -container e 2e -kyverno -container e 2e -kustomize ## Setup infrastructure for e2e tests
2020-08-11 00:16:13 +00:00
2019-11-18 19:41:37 +00:00
##################################
2021-04-08 23:14:08 +00:00
# Testing & Code-Coverage
2019-11-18 19:41:37 +00:00
##################################
2019-06-07 18:50:12 +00:00
## variables
BIN_DIR := $( GOPATH) /bin
2021-09-27 01:30:53 +00:00
GO_ACC := $( BIN_DIR) /go-acc@latest
2019-06-07 18:50:12 +00:00
CODE_COVERAGE_FILE := coverage
CODE_COVERAGE_FILE_TXT := $( CODE_COVERAGE_FILE) .txt
CODE_COVERAGE_FILE_HTML := $( CODE_COVERAGE_FILE) .html
## targets
$(GO_ACC) :
2021-09-27 01:30:53 +00:00
@echo " installing testing tools"
go install -v github.com/ory/go-acc@latest
2019-06-07 18:50:12 +00:00
$( eval export PATH = $( GO_ACC) :$( PATH) )
# go test provides code coverage per packages only.
2021-04-08 23:14:08 +00:00
# go-acc merges the result for pks so that it be used by
2019-06-07 18:50:12 +00:00
# go tool cover for reporting
2022-04-28 12:30:23 +00:00
test : test -clean test -unit test -e 2e ## Clean tests cache then run unit and e2e tests
2021-09-27 01:30:53 +00:00
2022-04-28 12:30:23 +00:00
test-clean : ## Clean tests cache
2021-09-27 01:30:53 +00:00
@echo " cleaning test cache"
go clean -testcache ./...
2021-07-10 01:01:46 +00:00
2022-02-24 15:34:12 +00:00
.PHONY : test -cli
2022-05-25 14:26:22 +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
2022-02-24 15:34:12 +00:00
.PHONY : test -cli -policies
test-cli-policies : cli
cmd/cli/kubectl-kyverno/kyverno test https://github.com/kyverno/policies/$( TEST_GIT_BRANCH)
.PHONY : test -cli -local
test-cli-local : cli
cmd/cli/kubectl-kyverno/kyverno test ./test/cli/test
.PHONY : test -cli -local -mutate
test-cli-local-mutate : cli
2022-03-16 04:26:47 +00:00
cmd/cli/kubectl-kyverno/kyverno 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
test-cli-local-generate : cli
cmd/cli/kubectl-kyverno/kyverno test ./test/cli/test-generate
2022-03-09 07:40:53 +00:00
.PHONY : test -cli -test -case -selector -flag
test-cli-test-case-selector-flag : cli
cmd/cli/kubectl-kyverno/kyverno 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
test-cli-registry : cli
2022-05-01 21:20:22 +00:00
cmd/cli/kubectl-kyverno/kyverno test ./test/cli/registry --registry
2022-03-16 04:26:47 +00:00
2022-04-28 12:30:23 +00:00
test-unit : $( GO_ACC ) ## Run unit tests
2019-06-07 18:50:12 +00:00
@echo " running unit tests"
go-acc ./... -o $( CODE_COVERAGE_FILE_TXT)
2022-03-28 14:01:27 +00:00
code-cov-report : ## Generate code coverage report
2019-06-07 18:50:12 +00:00
@echo " generating code coverage report"
2022-03-14 08:21:27 +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)
2020-06-04 18:45:37 +00:00
2020-08-06 05:16:10 +00:00
# Test E2E
test-e2e :
$( eval export E2E = "ok" )
2022-05-01 21:20:22 +00:00
go test ./test/e2e/verifyimages -v
2021-05-13 23:16:24 +00:00
go test ./test/e2e/metrics -v
2021-04-08 23:14:08 +00:00
go test ./test/e2e/mutate -v
go test ./test/e2e/generate -v
2020-08-06 05:16:10 +00:00
$( eval export E2E = "" )
2021-07-27 06:49:28 +00:00
test-e2e-local :
$( eval export E2E = "ok" )
2021-10-29 16:13:20 +00:00
kubectl apply -f https://raw.githubusercontent.com/kyverno/kyverno/main/config/github/rbac.yaml
2021-07-27 06:49:28 +00:00
kubectl port-forward -n kyverno service/kyverno-svc-metrics 8000:8000 &
2022-05-01 21:20:22 +00:00
go test ./test/e2e/verifyimages -v
2021-07-27 06:49:28 +00:00
go test ./test/e2e/metrics -v
go test ./test/e2e/mutate -v
go test ./test/e2e/generate -v
kill $!
$( eval export E2E = "" )
2022-02-04 06:47:36 +00:00
helm-test-values :
sed -i -e "s|nameOverride:.*|nameOverride: kyverno|g" charts/kyverno/values.yaml
sed -i -e "s|fullnameOverride:.*|fullnameOverride: kyverno|g" charts/kyverno/values.yaml
sed -i -e "s|namespace:.*|namespace: kyverno|g" charts/kyverno/values.yaml
2022-02-04 23:12:12 +00:00
sed -i -e " s|tag: # replaced in e2e tests.*|tag: $( GIT_VERSION_DEV) | " charts/kyverno/values.yaml
2022-02-04 06:47:36 +00:00
2020-06-05 20:42:53 +00:00
# godownloader create downloading script for kyverno-cli
2020-06-04 18:45:37 +00:00
godownloader :
2020-10-08 20:10:52 +00:00
godownloader .goreleaser.yml --repo kyverno/kyverno -o ./scripts/install-cli.sh --source= "raw"
2020-06-05 20:42:53 +00:00
2022-03-14 15:12:29 +00:00
.PHONY : kustomize
kustomize : ## Install kustomize
2022-03-25 16:08:38 +00:00
i f e q ( , $( shell which kustomize ) )
2022-03-15 11:00:57 +00:00
go install sigs.k8s.io/kustomize/kustomize/v4@latest
2022-03-25 16:08:38 +00:00
e n d i f
2022-03-14 15:12:29 +00:00
.PHONY : kustomize -crd
kustomize-crd : kustomize ## Create install.yaml
2021-04-08 23:14:08 +00:00
# Create CRD for helm deployment Helm
2021-11-02 02:21:10 +00:00
kustomize build ./config/release | kustomize cfg grep kind = CustomResourceDefinition | $( SED) -e "1i{{- if .Values.installCRDs }}" -e '$$a{{- end }}' > ./charts/kyverno/templates/crds.yaml
2020-06-05 20:44:47 +00:00
# Generate install.yaml that have all resources for kyverno
2021-10-29 16:13:20 +00:00
kustomize build ./config > ./config/install.yaml
2020-06-05 20:44:47 +00:00
# Generate install_debug.yaml that for developer testing
2021-10-29 16:13:20 +00:00
kustomize build ./config/debug > ./config/install_debug.yaml
2020-08-12 14:54:45 +00:00
2020-10-07 18:12:31 +00:00
# guidance https://github.com/kyverno/kyverno/wiki/Generate-a-Release
2020-11-29 08:37:36 +00:00
release :
2021-10-29 16:13:20 +00:00
kustomize build ./config > ./config/install.yaml
kustomize build ./config/release > ./config/release/install.yaml
2020-08-14 19:21:06 +00:00
2021-08-10 16:07:46 +00:00
release-notes :
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-03-07 09:43:36 +00:00
##################################
# CODEGEN
##################################
.PHONY : kyverno -crd
2022-03-28 14:01:27 +00:00
kyverno-crd : controller -gen ## Generate Kyverno CRDs
2021-10-29 16:13:20 +00:00
$( CONTROLLER_GEN) crd paths = ./api/kyverno/... crd:crdVersions= v1 output:dir= ./config/crds
2020-11-13 03:48:39 +00:00
2022-03-07 09:43:36 +00:00
.PHONY : report -crd
2022-03-28 14:01:27 +00:00
report-crd : controller -gen ## Generate policy reports CRDs
2021-10-29 16:13:20 +00:00
$( CONTROLLER_GEN) crd paths = ./api/policyreport/... crd:crdVersions= v1 output:dir= ./config/crds
2020-11-09 19:26:12 +00:00
2022-03-07 09:43:36 +00:00
.PHONY : install -controller -gen
2022-03-28 14:01:27 +00:00
install-controller-gen : ## Install controller-gen
2020-11-09 19:26:12 +00:00
@{ \
set -e ; \
CONTROLLER_GEN_TMP_DIR = $$ ( mktemp -d) ; \
cd $$ CONTROLLER_GEN_TMP_DIR ; \
go mod init tmp ; \
2022-05-29 07:27:14 +00:00
go mod edit -replace= sigs.k8s.io/controller-tools@$( CONTROLLER_GEN_REQ_VERSION) = github.com/eddycharly/controller-tools@704af868d45a3a78448b9a6a2279c12ea96a621e ; \
go get sigs.k8s.io/controller-tools/cmd/controller-gen@$( CONTROLLER_GEN_REQ_VERSION) ; \
2020-11-09 19:26:12 +00:00
rm -rf $$ CONTROLLER_GEN_TMP_DIR ; \
}
2021-02-19 04:53:53 +00:00
CONTROLLER_GEN = $( GOPATH) /bin/controller-gen
2022-03-07 09:43:36 +00:00
.PHONY : controller -gen
2022-03-28 14:01:27 +00:00
controller-gen : ## Setup controller-gen
2021-02-19 04:53:53 +00:00
i f e q ( , $( shell which controller -gen ) )
@{ \
echo "controller-gen not found!" ; \
echo " installing controller-gen $( CONTROLLER_GEN_REQ_VERSION) ... " ; \
make install-controller-gen; \
}
else ifneq (Version : $( CONTROLLER_GEN_REQ_VERSION ) , $( shell controller -gen --version ) )
@{ \
echo " controller-gen $( shell controller-gen --version) found! " ; \
echo " required controller-gen $( CONTROLLER_GEN_REQ_VERSION) " ; \
echo " installing controller-gen $( CONTROLLER_GEN_REQ_VERSION) ... " ; \
make install-controller-gen; \
}
2020-11-09 19:26:12 +00:00
e l s e
CONTROLLER_GEN = $( shell which controller-gen)
e n d i f
2022-03-07 09:43:36 +00:00
.PHONY : deepcopy -autogen
2022-04-07 05:18:47 +00:00
deepcopy-autogen : controller -gen ## Generate deep copy code
2021-03-01 18:58:58 +00:00
$( CONTROLLER_GEN) object:headerFile= "scripts/boilerplate.go.txt" paths = "./..."
2022-03-07 09:43:36 +00:00
.PHONY : codegen
2022-03-16 09:31:35 +00:00
codegen : kyverno -crd report -crd deepcopy -autogen generate -api -docs gen -helm ## Update all generated code and docs
2022-03-07 09:43:36 +00:00
2022-03-16 09:31:35 +00:00
.PHONY : verify -api
verify-api : kyverno -crd report -crd deepcopy -autogen ## Check api is up to date
git --no-pager diff api
2022-03-07 09:43:36 +00:00
@echo 'If this test fails, it is because the git diff is non-empty after running "make codegen".'
@echo 'To correct this, locally run "make codegen", commit the changes, and re-run tests.'
git diff --quiet --exit-code api
2022-03-16 09:31:35 +00:00
.PHONY : verify -config
verify-config : kyverno -crd report -crd ## Check config is up to date
git --no-pager diff config
@echo 'If this test fails, it is because the git diff is non-empty after running "make codegen".'
@echo 'To correct this, locally run "make codegen", commit the changes, and re-run tests.'
git diff --quiet --exit-code config
.PHONY : verify -codegen
verify-codegen : verify -api verify -config verify -api -docs verify -helm ## Verify all generated code and docs are up to date
2022-03-07 09:43:36 +00:00
.PHONY : goimports
2022-04-07 05:18:47 +00:00
goimports : ## Install goimports if needed
2021-10-29 10:24:26 +00:00
i f e q ( , $( shell which goimports ) )
@{ \
echo "goimports not found!" ; \
echo "installing goimports..." ; \
2022-03-15 11:00:57 +00:00
go install golang.org/x/tools/cmd/goimports@latest; \
2021-10-29 10:24:26 +00:00
}
e l s e
GO_IMPORTS = $( shell which goimports)
e n d i f
2022-03-07 09:43:36 +00:00
.PHONY : fmt
2022-04-07 05:18:47 +00:00
fmt : goimports ## Run go fmt
2021-10-29 10:24:26 +00:00
go fmt ./... && $( GO_IMPORTS) -w ./
2020-08-14 19:21:06 +00:00
2022-03-07 09:43:36 +00:00
.PHONY : vet
2022-04-07 05:18:47 +00:00
vet : ## Run go vet
2020-08-14 19:21:06 +00:00
go vet ./...
2021-12-10 04:34:06 +00:00
2022-02-25 16:22:00 +00:00
##################################
# HELM
##################################
.PHONY : gen -helm -docs
gen-helm-docs : ## Generate Helm docs
@docker run -v ${ PWD } :/work -w /work jnorwood/helm-docs:v1.6.0 -s file
2022-03-08 15:10:53 +00:00
2022-03-10 15:07:48 +00:00
.PHONY : gen -helm
gen-helm : gen -helm -docs kustomize -crd ## Generate Helm charts stuff
.PHONY : verify -helm
verify-helm : gen -helm ## Check Helm charts are up to date
2022-03-16 09:31:35 +00:00
git --no-pager diff charts
2022-03-10 15:07:48 +00:00
@echo 'If this test fails, it is because the git diff is non-empty after running "make gen-helm".'
@echo 'To correct this, locally run "make gen-helm", commit the changes, and re-run tests.'
git diff --quiet --exit-code charts
2022-03-16 13:48:31 +00:00
##################################
# HELP
##################################
.PHONY : help
help : ## Shows the available commands
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $( MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
2022-04-04 20:16:45 +00:00
.PHONY : kind -deploy
kind-deploy : docker -build -initContainer -local docker -build -kyverno -local
kind load docker-image $( REPO) /$( INITC_IMAGE) :$( IMAGE_TAG_DEV)
kind load docker-image $( REPO) /$( KYVERNO_IMAGE) :$( IMAGE_TAG_DEV)
2022-04-07 05:18:47 +00:00
helm upgrade --install kyverno --namespace kyverno --wait --create-namespace ./charts/kyverno \
2022-04-04 20:16:45 +00:00
--set image.repository= $( REPO) /$( KYVERNO_IMAGE) \
--set image.tag= $( IMAGE_TAG_DEV) \
--set initImage.repository= $( REPO) /$( INITC_IMAGE) \
--set initImage.tag= $( IMAGE_TAG_DEV) \
2022-04-07 05:18:47 +00:00
--set extraArgs = { --autogenInternals= false}
2022-04-04 20:16:45 +00:00
helm upgrade --install kyverno-policies --namespace kyverno --create-namespace ./charts/kyverno-policies