| |
| # 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) |
| ifeq (,$(shell go env GOBIN)) |
| GOBIN=$(shell go env GOPATH)/bin |
| else |
| GOBIN=$(shell go env GOBIN) |
| endif |
| |
| |
| all: manager |
| |
| clean: |
| rm -rf bin/ |
| |
| # Run tests |
| test: generate manifests |
| go test ./... -coverprofile cover.out |
| |
| # Build manager binary |
| manager: generate |
| go build -o bin/manager main.go |
| |
| # Run against the configured Kubernetes cluster in ~/.kube/config |
| run: generate manifests |
| 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 - |
| |
| # Deploy controller in the configured Kubernetes cluster in ~/.kube/config |
| deploy: manifests |
| cd config/manager && kustomize edit set image controller=${IMG} |
| kustomize build config/default | kubectl apply -f - |
| |
| # Generate manifests e.g. CRD, RBAC etc. |
| manifests: controller-gen |
| $(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases |
| |
| # Generate code |
| generate: controller-gen |
| $(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..." |
| |
| GO_LICENSER := $(GOBIN)/go-licenser |
| $(GO_LICENSER): |
| GO111MODULE=off go get -u github.com/elastic/go-licenser |
| license: clean $(GO_LICENSER) |
| $(GO_LICENSER) -d -licensor='Apache Software Foundation (ASF)' -exclude=api/v1alpha1/zz_generated* . |
| |
| # Build the docker image |
| docker-build: test |
| docker build . -t ${IMG} |
| |
| # Push the docker image |
| docker-push: |
| docker push ${IMG} |
| |
| # find or download controller-gen |
| # download controller-gen if necessary |
| controller-gen: |
| ifeq (, $(shell which 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@v0.2.5 ;\ |
| rm -rf $$CONTROLLER_GEN_TMP_DIR ;\ |
| } |
| CONTROLLER_GEN=$(GOBIN)/controller-gen |
| else |
| CONTROLLER_GEN=$(shell which controller-gen) |
| endif |
| |
| GOIMPORTS := $(GOBIN)/goimports |
| $(GOIMPORTS): |
| GO111MODULE=off go get -u golang.org/x/tools/cmd/goimports |
| # The goimports tool does not arrange imports in 3 blocks if there are already more than three blocks. |
| # To avoid that, before running it, we collapse all imports in one block, then run the formatter. |
| format: $(GOIMPORTS) ## Format all Go code |
| @for f in `find . -name '*.go'`; do \ |
| awk '/^import \($$/,/^\)$$/{if($$0=="")next}{print}' $$f > /tmp/fmt; \ |
| mv /tmp/fmt $$f; \ |
| done |
| $(GOIMPORTS) -w -local github.com/skywalking-swck . |
| |
| ## Check that the status is consistent with CI. |
| check: clean generate manifests |
| $(MAKE) format |
| mkdir -p /tmp/artifacts |
| git diff >/tmp/artifacts/check.diff 2>&1 |
| @go mod tidy &> /dev/null |
| @if [ ! -z "`git status -s`" ]; then \ |
| echo "Following files are not consistent with CI:"; \ |
| git status -s; \ |
| exit 1; \ |
| fi |
| |
| ## Code quality and integrity |
| |
| LINTER := bin/golangci-lint |
| $(LINTER): |
| wget -O - -q https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.23.6 |
| |
| lint: $(LINTER) |
| $(LINTER) run --config ./golangci.yml |
| |
| .PHONY: lint |