blob: 441308e5dc4fb5090de493d4f2f63c2907eb9f9b [file] [log] [blame]
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# 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 build/bin
rm -rf build/release
rm -rf *.out
rm -rf *.test
# 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
go run github.com/skywalking-swck/cmd/build license insert config
# Generate code
generate: controller-gen
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
$(MAKE) format
GO_LICENSER := $(GOBIN)/go-licenser
$(GO_LICENSER):
GO111MODULE=off go get -u github.com/elastic/go-licenser
license: $(GO_LICENSER)
$(GO_LICENSER) -d -licensor='Apache Software Foundation (ASF)' -exclude=api/v1alpha1/zz_generated* .
go run github.com/skywalking-swck/cmd/build license check config
# 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: generate manifests license
$(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
release-manager: generate
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o build/bin/manager-linux-amd64 main.go
RELEASE_SCRIPTS := ./build/package/release.sh
release-binary: release-manager
${RELEASE_SCRIPTS} -b
release-source:
${RELEASE_SCRIPTS} -s
release-sign:
${RELEASE_SCRIPTS} -k bin
${RELEASE_SCRIPTS} -k src
release: release-binary release-source release-sign
.PHONY: release-manager release-binary release-source release