mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-05 23:46:56 +00:00
* add image verification * inline policy list Signed-off-by: Jim Bugwadia <jim@nirmata.com> * cosign version and dependencies updates Signed-off-by: Jim Bugwadia <jim@nirmata.com> * add registry initialization Signed-off-by: Jim Bugwadia <jim@nirmata.com> * add build tag to exclude k8schain for cloud providers Signed-off-by: Jim Bugwadia <jim@nirmata.com> * add build tag to exclude k8schain for cloud providers Signed-off-by: Jim Bugwadia <jim@nirmata.com> * generate deep copy and other fixtures Signed-off-by: Jim Bugwadia <jim@nirmata.com> * fix deep copy issues Signed-off-by: Jim Bugwadia <jim@nirmata.com> * mutate images to add digest Signed-off-by: Jim Bugwadia <jim@nirmata.com> * add certificates to Kyverno container for HTTPS lookups Signed-off-by: Jim Bugwadia <jim@nirmata.com> * align flag syntax Signed-off-by: Jim Bugwadia <jim@nirmata.com> * update docs Signed-off-by: Jim Bugwadia <jim@nirmata.com> * update dependencies Signed-off-by: Jim Bugwadia <jim@nirmata.com> * update dependencies Signed-off-by: Jim Bugwadia <jim@nirmata.com> * patch image with digest and fix checks Signed-off-by: Jim Bugwadia <jim@nirmata.com> * hardcode image for demos Signed-off-by: Jim Bugwadia <jim@nirmata.com> * add default registry (docker.io) before calling reference.Parse Signed-off-by: Jim Bugwadia <jim@nirmata.com> * fix definition Signed-off-by: Jim Bugwadia <jim@nirmata.com> * increase webhook timeout Signed-off-by: Jim Bugwadia <jim@nirmata.com> * fix args Signed-off-by: Jim Bugwadia <jim@nirmata.com> * run gofmt Signed-off-by: Jim Bugwadia <jim@nirmata.com> * rename for clarity Signed-off-by: Jim Bugwadia <jim@nirmata.com> * fix HasImageVerify check Signed-off-by: Jim Bugwadia <jim@nirmata.com> * align make test commands Signed-off-by: Jim Bugwadia <jim@nirmata.com> * align make test commands Signed-off-by: Jim Bugwadia <jim@nirmata.com> * align make test commands Signed-off-by: Jim Bugwadia <jim@nirmata.com> * fix linter error Signed-off-by: Jim Bugwadia <jim@nirmata.com> * format Signed-off-by: Jim Bugwadia <jim@nirmata.com> * handle API conflict and retry Signed-off-by: Jim Bugwadia <jim@nirmata.com> * format Signed-off-by: Jim Bugwadia <jim@nirmata.com> * fix reviewdog issues Signed-off-by: Jim Bugwadia <jim@nirmata.com> * fix make for unit tests Signed-off-by: Jim Bugwadia <jim@nirmata.com> * improve error message Signed-off-by: Jim Bugwadia <jim@nirmata.com> * fix durations Signed-off-by: Jim Bugwadia <jim@nirmata.com> * handle errors in tests Signed-off-by: Jim Bugwadia <jim@nirmata.com> * print policy name Signed-off-by: Jim Bugwadia <jim@nirmata.com> * update tests Signed-off-by: Jim Bugwadia <jim@nirmata.com> * add retries and duration to error log Signed-off-by: Jim Bugwadia <jim@nirmata.com> * fix time check in tests Signed-off-by: Jim Bugwadia <jim@nirmata.com> * round creation times in test Signed-off-by: Jim Bugwadia <jim@nirmata.com> * fix retry loop Signed-off-by: Jim Bugwadia <jim@nirmata.com> * remove timing check for policy creation Signed-off-by: Jim Bugwadia <jim@nirmata.com> * fix e2e error - policy not found Signed-off-by: Shuting Zhao <shutting06@gmail.com> * update string comparison method Signed-off-by: Shuting Zhao <shutting06@gmail.com> * fix test Generate_Namespace_Label_Actions Signed-off-by: Shuting Zhao <shutting06@gmail.com> * add debug info for e2e tests Signed-off-by: Jim Bugwadia <jim@nirmata.com> * fix error Signed-off-by: Jim Bugwadia <jim@nirmata.com> * fix generate bug Signed-off-by: Jim Bugwadia <jim@nirmata.com> * fix format Signed-off-by: Jim Bugwadia <jim@nirmata.com> * add check for update operations Signed-off-by: Jim Bugwadia <jim@nirmata.com> * increase time for deleteing a resource Signed-off-by: Jim Bugwadia <jim@nirmata.com> * fix check Signed-off-by: Jim Bugwadia <jim@nirmata.com> Co-authored-by: Shuting Zhao <shutting06@gmail.com>
260 lines
10 KiB
Makefile
260 lines
10 KiB
Makefile
.DEFAULT_GOAL: build
|
|
|
|
##################################
|
|
# DEFAULTS
|
|
##################################
|
|
GIT_VERSION := $(shell git describe --always --tags)
|
|
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')
|
|
CONTROLLER_GEN=controller-gen
|
|
CONTROLLER_GEN_REQ_VERSION := v0.4.0
|
|
|
|
REGISTRY?=ghcr.io
|
|
REPO=$(REGISTRY)/kyverno
|
|
IMAGE_TAG?=$(GIT_VERSION)
|
|
GOOS ?= $(shell go env GOOS)
|
|
PACKAGE ?=github.com/kyverno/kyverno
|
|
LD_FLAGS="-s -w -X $(PACKAGE)/pkg/version.BuildVersion=$(GIT_VERSION) -X $(PACKAGE)/pkg/version.BuildHash=$(GIT_HASH) -X $(PACKAGE)/pkg/version.BuildTime=$(TIMESTAMP)"
|
|
|
|
# Used to disable inclusion of cloud provider code in k8schain
|
|
# https://github.com/google/go-containerregistry/tree/main/pkg/authn/k8schain
|
|
TAGS=disable_aws,disable_azure,disable_gcp
|
|
|
|
##################################
|
|
# KYVERNO
|
|
##################################
|
|
|
|
.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
|
|
|
|
KYVERNO_PATH:= cmd/kyverno
|
|
build: kyverno
|
|
PWD := $(CURDIR)
|
|
|
|
##################################
|
|
# INIT CONTAINER
|
|
##################################
|
|
INITC_PATH := cmd/initContainer
|
|
INITC_IMAGE := kyvernopre
|
|
initContainer: fmt vet
|
|
GOOS=$(GOOS) go build -o $(PWD)/$(INITC_PATH)/kyvernopre -ldflags=$(LD_FLAGS) $(PWD)/$(INITC_PATH)/main.go
|
|
|
|
.PHONY: docker-build-initContainer docker-push-initContainer
|
|
|
|
docker-publish-initContainer: docker-build-initContainer docker-push-initContainer
|
|
|
|
docker-build-initContainer:
|
|
@docker buildx build --file $(PWD)/$(INITC_PATH)/Dockerfile --progress plane --platform linux/arm64,linux/amd64 --tag $(REPO)/$(INITC_IMAGE):$(IMAGE_TAG) . --build-arg LD_FLAGS=$(LD_FLAGS)
|
|
|
|
docker-build-initContainer-amd64:
|
|
@docker build -f $(PWD)/$(INITC_PATH)/Dockerfile -t $(REPO)/$(INITC_IMAGE):$(IMAGE_TAG) . --build-arg LD_FLAGS=$(LD_FLAGS) --build-arg TARGETPLATFORM="linux/amd64"
|
|
|
|
docker-push-initContainer:
|
|
@docker buildx build --file $(PWD)/$(INITC_PATH)/Dockerfile --progress plane --push --platform linux/arm64,linux/amd64 --tag $(REPO)/$(INITC_IMAGE):$(IMAGE_TAG) . --build-arg LD_FLAGS=$(LD_FLAGS)
|
|
@docker buildx build --file $(PWD)/$(INITC_PATH)/Dockerfile --progress plane --push --platform linux/arm64,linux/amd64 --tag $(REPO)/$(INITC_IMAGE):latest . --build-arg LD_FLAGS=$(LD_FLAGS)
|
|
|
|
##################################
|
|
# KYVERNO CONTAINER
|
|
##################################
|
|
.PHONY: docker-build-kyverno docker-push-kyverno
|
|
KYVERNO_PATH := cmd/kyverno
|
|
KYVERNO_IMAGE := kyverno
|
|
|
|
local:
|
|
go build -tags $(TAGS) -ldflags=$(LD_FLAGS) $(PWD)/$(KYVERNO_PATH)
|
|
go build -tags $(TAGS) -ldflags=$(LD_FLAGS) $(PWD)/$(CLI_PATH)
|
|
|
|
kyverno: fmt vet
|
|
GOOS=$(GOOS) go build -o $(PWD)/$(KYVERNO_PATH)/kyverno -tags $(TAGS) -ldflags=$(LD_FLAGS) $(PWD)/$(KYVERNO_PATH)/main.go
|
|
|
|
docker-publish-kyverno: docker-build-kyverno docker-push-kyverno
|
|
|
|
docker-build-kyverno:
|
|
@docker buildx build --file $(PWD)/$(KYVERNO_PATH)/Dockerfile --progress plane --platform linux/arm64,linux/amd64 --tag $(REPO)/$(KYVERNO_IMAGE):$(IMAGE_TAG) . --build-arg LD_FLAGS=$(LD_FLAGS) --build-arg TAGS=$(TAGS)
|
|
|
|
docker-build-kyverno-local:
|
|
CGO_ENABLED=0 GOOS=linux go build -o $(PWD)/$(KYVERNO_PATH)/kyverno -tags $(TAGS) -ldflags=$(LD_FLAGS) $(PWD)/$(KYVERNO_PATH)/main.go
|
|
@docker build -f $(PWD)/$(KYVERNO_PATH)/localDockerfile -t $(REPO)/$(KYVERNO_IMAGE):$(IMAGE_TAG) $(PWD)/$(KYVERNO_PATH)
|
|
@docker tag $(REPO)/$(KYVERNO_IMAGE):$(IMAGE_TAG) $(REPO)/$(KYVERNO_IMAGE):latest
|
|
|
|
docker-build-kyverno-amd64:
|
|
@docker build -f $(PWD)/$(KYVERNO_PATH)/Dockerfile -t $(REPO)/$(KYVERNO_IMAGE):$(IMAGE_TAG) . --build-arg LD_FLAGS=$(LD_FLAGS) --build-arg TARGETPLATFORM="linux/amd64" --build-arg TAGS=$(TAGS)
|
|
|
|
docker-push-kyverno:
|
|
@docker buildx build --file $(PWD)/$(KYVERNO_PATH)/Dockerfile --progress plane --push --platform linux/arm64,linux/amd64 --tag $(REPO)/$(KYVERNO_IMAGE):$(IMAGE_TAG) . --build-arg LD_FLAGS=$(LD_FLAGS) --build-arg TAGS=$(TAGS)
|
|
@docker buildx build --file $(PWD)/$(KYVERNO_PATH)/Dockerfile --progress plane --push --platform linux/arm64,linux/amd64 --tag $(REPO)/$(KYVERNO_IMAGE):latest . --build-arg LD_FLAGS=$(LD_FLAGS) --build-arg TAGS=$(TAGS)
|
|
|
|
##################################
|
|
|
|
# Generate Docs for types.go
|
|
##################################
|
|
|
|
generate-api-docs:
|
|
go run github.com/ahmetb/gen-crd-api-reference-docs -api-dir ./pkg/api -config documentation/api/config.json -template-dir documentation/api/template -out-file documentation/index.html
|
|
|
|
|
|
##################################
|
|
# CLI
|
|
##################################
|
|
.PHONY: docker-build-cli docker-push-cli
|
|
CLI_PATH := cmd/cli/kubectl-kyverno
|
|
KYVERNO_CLI_IMAGE := kyverno-cli
|
|
|
|
cli:
|
|
GOOS=$(GOOS) go build -o $(PWD)/$(CLI_PATH)/kyverno -ldflags=$(LD_FLAGS) $(PWD)/$(CLI_PATH)/main.go
|
|
|
|
docker-publish-cli: docker-build-cli docker-push-cli
|
|
|
|
docker-build-cli:
|
|
@docker buildx build --file $(PWD)/$(CLI_PATH)/Dockerfile --progress plane --platform linux/arm64,linux/amd64 --tag $(REPO)/$(KYVERNO_CLI_IMAGE):$(IMAGE_TAG) . --build-arg LD_FLAGS=$(LD_FLAGS)
|
|
|
|
docker-build-cli-amd64:
|
|
@docker build -f $(PWD)/$(CLI_PATH)/Dockerfile -t $(REPO)/$(KYVERNO_CLI_IMAGE):$(IMAGE_TAG) . --build-arg LD_FLAGS=$(LD_FLAGS) --build-arg TARGETPLATFORM="linux/amd64"
|
|
|
|
docker-push-cli:
|
|
@docker buildx build --file $(PWD)/$(CLI_PATH)/Dockerfile --progress plane --push --platform linux/arm64,linux/amd64 --tag $(REPO)/$(KYVERNO_CLI_IMAGE):$(IMAGE_TAG) . --build-arg LD_FLAGS=$(LD_FLAGS)
|
|
@docker buildx build --file $(PWD)/$(CLI_PATH)/Dockerfile --progress plane --push --platform linux/arm64,linux/amd64 --tag $(REPO)/$(KYVERNO_CLI_IMAGE):latest . --build-arg LD_FLAGS=$(LD_FLAGS)
|
|
|
|
##################################
|
|
docker-publish-all: docker-publish-initContainer docker-publish-kyverno docker-publish-cli
|
|
|
|
docker-build-all: docker-build-initContainer docker-build-kyverno docker-build-cli
|
|
|
|
docker-build-all-amd64: docker-build-initContainer-amd64 docker-build-kyverno-amd64 docker-build-cli-amd64
|
|
|
|
##################################
|
|
# Create e2e Infrastruture
|
|
##################################
|
|
|
|
create-e2e-infrastruture:
|
|
chmod a+x $(PWD)/scripts/create-e2e-infrastruture.sh
|
|
$(PWD)/scripts/create-e2e-infrastruture.sh
|
|
|
|
|
|
##################################
|
|
|
|
##################################
|
|
# Testing & Code-Coverage
|
|
##################################
|
|
|
|
## variables
|
|
BIN_DIR := $(GOPATH)/bin
|
|
GO_ACC := $(BIN_DIR)/go-acc
|
|
CODE_COVERAGE_FILE:= coverage
|
|
CODE_COVERAGE_FILE_TXT := $(CODE_COVERAGE_FILE).txt
|
|
CODE_COVERAGE_FILE_HTML := $(CODE_COVERAGE_FILE).html
|
|
|
|
## targets
|
|
$(GO_ACC):
|
|
@echo " downloading testing tools"
|
|
go get -v github.com/ory/go-acc
|
|
$(eval export PATH=$(GO_ACC):$(PATH))
|
|
# go test provides code coverage per packages only.
|
|
# go-acc merges the result for pks so that it be used by
|
|
# go tool cover for reporting
|
|
|
|
test: test-unit test-e2e test-cmd
|
|
|
|
|
|
# go get downloads and installs the binary
|
|
# we temporarily add the GO_ACC to the path
|
|
test-unit: $(GO_ACC)
|
|
@echo " running unit tests"
|
|
go-acc ./... -o $(CODE_COVERAGE_FILE_TXT)
|
|
|
|
code-cov-report: $(CODE_COVERAGE_FILE_TXT)
|
|
# transform to html format
|
|
@echo " generating code coverage report"
|
|
go tool cover -html=coverage.txt
|
|
if [ -a $(CODE_COVERAGE_FILE_HTML) ]; then open $(CODE_COVERAGE_FILE_HTML); fi;
|
|
|
|
# Test E2E
|
|
test-e2e:
|
|
$(eval export E2E="ok")
|
|
go test ./test/e2e/metrics -v
|
|
go test ./test/e2e/mutate -v
|
|
go test ./test/e2e/generate -v
|
|
$(eval export E2E="")
|
|
|
|
#Test TestCmd Policy
|
|
test-cmd: cli
|
|
$(PWD)/$(CLI_PATH)/kyverno test https://github.com/kyverno/policies/main
|
|
$(PWD)/$(CLI_PATH)/kyverno test ./test/cli/test
|
|
$(PWD)/$(CLI_PATH)/kyverno test ./test/cli/test-fail/missing-policy && exit 1 || exit 0
|
|
$(PWD)/$(CLI_PATH)/kyverno test ./test/cli/test-fail/missing-rule && exit 1 || exit 0
|
|
$(PWD)/$(CLI_PATH)/kyverno test ./test/cli/test-fail/missing-resource && exit 1 || exit 0
|
|
|
|
# godownloader create downloading script for kyverno-cli
|
|
godownloader:
|
|
godownloader .goreleaser.yml --repo kyverno/kyverno -o ./scripts/install-cli.sh --source="raw"
|
|
|
|
# kustomize-crd will create install.yaml
|
|
kustomize-crd:
|
|
# Create CRD for helm deployment Helm
|
|
kustomize build ./definitions/crds > ./charts/kyverno/crds/crds.yaml
|
|
# Generate install.yaml that have all resources for kyverno
|
|
kustomize build ./definitions > ./definitions/install.yaml
|
|
# Generate install_debug.yaml that for developer testing
|
|
kustomize build ./definitions/debug > ./definitions/install_debug.yaml
|
|
|
|
# guidance https://github.com/kyverno/kyverno/wiki/Generate-a-Release
|
|
release:
|
|
kustomize build ./definitions > ./definitions/install.yaml
|
|
kustomize build ./definitions > ./definitions/release/install.yaml
|
|
|
|
kyverno-crd: controller-gen
|
|
$(CONTROLLER_GEN) crd paths=./pkg/api/kyverno/v1alpha1 output:dir=./definitions/crds
|
|
$(CONTROLLER_GEN) crd paths=./pkg/api/kyverno/v1 output:dir=./definitions/crds
|
|
|
|
report-crd: controller-gen
|
|
$(CONTROLLER_GEN) crd paths=./pkg/api/policyreport/v1alpha1 output:dir=./definitions/crds
|
|
|
|
# install the right version of controller-gen
|
|
install-controller-gen:
|
|
@{ \
|
|
set -e ;\
|
|
CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\
|
|
cd $$CONTROLLER_GEN_TMP_DIR ;\
|
|
go mod init tmp ;\
|
|
go get sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_GEN_REQ_VERSION) ;\
|
|
rm -rf $$CONTROLLER_GEN_TMP_DIR ;\
|
|
}
|
|
CONTROLLER_GEN=$(GOPATH)/bin/controller-gen
|
|
|
|
# setup controller-gen with the right version, if necessary
|
|
controller-gen:
|
|
ifeq (, $(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;\
|
|
}
|
|
else
|
|
CONTROLLER_GEN=$(shell which controller-gen)
|
|
endif
|
|
|
|
# Bootstrap auto-generable code associated with deepcopy
|
|
deepcopy-autogen: controller-gen
|
|
$(CONTROLLER_GEN) object:headerFile="scripts/boilerplate.go.txt" paths="./..."
|
|
|
|
# Run go fmt against code
|
|
fmt:
|
|
gofmt -s -w .
|
|
|
|
vet:
|
|
go vet ./...
|