2020-12-21 19:31:28 +00:00
MAKEFLAGS += --warn-undefined-variables
SHELL := /bin/bash
.SHELLFLAGS := -euo pipefail -c
.DEFAULT_GOAL := all
2020-11-23 14:21:01 +00:00
# Image URL to use all building/pushing image targets
IMG ?= controller:latest
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
CRD_OPTIONS ?= "crd:trivialVersions=true"
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
i f e q ( , $( shell go env GOBIN ) )
GOBIN = $( shell go env GOPATH) /bin
e l s e
GOBIN = $( shell go env GOBIN)
e n d i f
2020-12-21 19:31:28 +00:00
all : build
2020-11-23 14:21:01 +00:00
2020-12-21 19:31:28 +00:00
.PHONY : test
test : generate manifests ## Run tests
2020-11-23 14:21:01 +00:00
go test ./... -coverprofile cover.out
2020-12-21 19:31:28 +00:00
.PHONY : build
build : generate fmt ## Build binary
2020-11-23 14:21:01 +00:00
go build -o bin/manager main.go
# Run against the configured Kubernetes cluster in ~/.kube/config
2020-12-21 19:31:28 +00:00
run : generate fmt manifests
2020-11-23 14:21:01 +00:00
go run ./main.go
# Install CRDs into a cluster
install : manifests
kustomize build config/crd | kubectl apply -f -
# Uninstall CRDs from a cluster
uninstall : manifests
kustomize build config/crd | kubectl delete -f -
2020-12-21 19:31:28 +00:00
.PHONY : deploy
deploy : manifests ## Deploy controller in the Kubernetes cluster of current context
2020-11-23 14:21:01 +00:00
cd config/manager && kustomize edit set image controller = ${ IMG }
kustomize build config/default | kubectl apply -f -
2020-12-21 19:31:28 +00:00
manifests : controller -gen ## Generate manifests e.g. CRD, RBAC etc.
2020-11-23 14:21:01 +00:00
$( CONTROLLER_GEN) $( CRD_OPTIONS) rbac:roleName= manager-role webhook paths = "./..." output:crd:artifacts:config= config/crd/bases
2020-12-21 19:31:28 +00:00
lint/check : # Check install of golanci-lint
@if ! golangci-lint --version > /dev/null 2>& 1; then \
echo -e "\033[0;33mgolangci-lint is not installed: run \`\033[0;32mmake lint-install\033[0m\033[0;33m\` or install it from https://golangci-lint.run\033[0m" ; \
exit 1; \
fi
lint-install : # installs golangci-lint to the go bin dir
@if ! golangci-lint --version > /dev/null 2>& 1; then \
echo "Installing golangci-lint" ; \
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $( GOBIN) v1.33.0; \
fi
lint : lint /check ## run golangci-lint
@if ! golangci-lint run; then \
echo -e "\033[0;33mgolangci-lint failed: some checks can be fixed with \`\033[0;32mmake fmt\033[0m\033[0;33m\`\033[0m" ; \
exit 1; \
fi
fmt : lint /check ## ensure consistent code style
go mod tidy
2020-11-23 14:21:01 +00:00
go fmt ./...
2020-12-21 19:31:28 +00:00
golangci-lint run --fix > /dev/null 2>& 1 || true
2020-11-23 14:21:01 +00:00
2020-12-21 19:31:28 +00:00
generate : controller -gen ## Generate code
2020-11-23 14:21:01 +00:00
$( CONTROLLER_GEN) object:headerFile= "hack/boilerplate.go.txt" paths = "./..."
2020-12-21 19:31:28 +00:00
docker-build : test ## Build the docker image
2020-11-23 14:21:01 +00:00
docker build . -t ${ IMG }
2020-12-21 19:31:28 +00:00
docker-push : ## Push the docker image
2020-11-23 14:21:01 +00:00
docker push ${ IMG }
# find or download controller-gen
# download controller-gen if necessary
controller-gen :
i f e q ( , $( shell which controller -gen ) )
@{ \
set -e ; \
CONTROLLER_GEN_TMP_DIR = $$ ( mktemp -d) ; \
cd $$ CONTROLLER_GEN_TMP_DIR ; \
go mod init tmp ; \
2020-11-30 20:29:46 +00:00
go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.4.1 ; \
2020-11-23 14:21:01 +00:00
rm -rf $$ CONTROLLER_GEN_TMP_DIR ; \
}
CONTROLLER_GEN = $( GOBIN) /controller-gen
e l s e
CONTROLLER_GEN = $( shell which controller-gen)
e n d i f
2020-12-21 19:31:28 +00:00
help : ## displays this help message
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_\/-]+:.*?## / {printf "\033[34m%-18s\033[0m %s\n", $$1, $$2}' $( MAKEFILE_LIST) | \
sort | \
grep -v '#'