-
Notifications
You must be signed in to change notification settings - Fork 13
/
Makefile
74 lines (59 loc) · 2.17 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# Image URL to use all building/pushing image targets
IMG ?= openkruise/kruise-state-metrics:test
# Platforms to build the image for
PLATFORMS ?= linux/amd64,linux/arm64
# 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: build
# Build kruise-state-metrics binary
build: fmt vet
go build -o bin/kruise-state-metrics main.go
# Run against the configured Kubernetes cluster in ~/.kube/config
run: fmt vet
go run main.go --kubeconfig ~/.kube/config
# Run go fmt against code
fmt:
go fmt ./...
# Run go vet against code
vet:
go vet ./...
lint: golangci-lint ## Run golangci-lint against code.
$(GOLANGCI_LINT) run
# Build the docker image
docker-build:
docker build --pull --no-cache . -t ${IMG}
# Push the docker image
docker-push:
docker push ${IMG}
# Build and push the multiarchitecture docker images and manifest.
docker-multiarch:
docker buildx build -f ./Dockerfile_multiarch --pull --no-cache --platform=$(PLATFORMS) --push . -t $(IMG)
deploy: kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
cd deploy && $(KUSTOMIZE) edit set image kruise-state-metrics=${IMG}
$(KUSTOMIZE) build deploy | kubectl apply -f -
echo "resources:\n- deploy.yaml" > deploy/kustomization.yaml
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build deploy | kubectl delete -f -
KUSTOMIZE = $(shell pwd)/bin/kustomize
kustomize: ## Download kustomize locally if necessary.
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/[email protected])
GOLANGCI_LINT = $(shell pwd)/bin/golangci-lint
golangci-lint: ## Download golangci-lint locally if necessary.
$(call go-get-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/[email protected])
# go-get-tool will 'go get' any package $2 and install it to $1.
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
define go-get-tool
@[ -f $(1) ] || { \
set -e ;\
TMP_DIR=$$(mktemp -d) ;\
cd $$TMP_DIR ;\
go mod init tmp ;\
echo "Downloading $(2)" ;\
GOBIN=$(PROJECT_DIR)/bin go install $(2) ;\
rm -rf $$TMP_DIR ;\
}
endef