forked from Project-HAMi/mock-device-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
110 lines (83 loc) · 3.1 KB
/
Copy pathMakefile
File metadata and controls
110 lines (83 loc) · 3.1 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# Makefile for HAMi mock-device-plugin
#
# Run `make help` to see the available targets.
# ---- Variables (override on the command line, e.g. `make docker-build IMG=myrepo/mock:dev`) ----
REGISTRY ?= projecthami
IMAGE_NAME ?= mock-device-plugin
TAG ?= latest
IMG ?= $(REGISTRY)/$(IMAGE_NAME):$(TAG)
BINARY ?= k8s-device-plugin
MAIN_PKG ?= ./cmd/k8s-device-plugin
OUTPUT_DIR ?= bin
GIT_DESCRIBE ?= $(shell git describe --always --long --dirty 2>/dev/null || echo "unknown")
LDFLAGS ?= -X main.gitDescribe=$(GIT_DESCRIBE)
GO ?= go
DOCKER ?= docker
# Use `make ... DOCKER=nerdctl` on containerd-only hosts.
# Optional Go module proxy passed into the image build. Set it for faster builds
# behind a slow network, e.g. `make docker-build GOPROXY=https://goproxy.cn,direct`.
GOPROXY ?=
DOCKER_BUILD_ARGS :=
ifneq ($(GOPROXY),)
DOCKER_BUILD_ARGS += --build-arg GOPROXY=$(GOPROXY)
endif
# Detect golangci-lint availability for the lint target.
GOLANGCI_LINT := $(shell command -v golangci-lint 2>/dev/null)
.DEFAULT_GOAL := help
.PHONY: all
all: build ## Alias for `build` (compatibility with standard Makefile tooling).
##@ General
.PHONY: help
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-18s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) }' $(MAKEFILE_LIST)
##@ Development
.PHONY: fmt
fmt: ## Run go fmt against code.
$(GO) fmt ./...
.PHONY: vet
vet: ## Run go vet against code.
$(GO) vet ./...
.PHONY: tidy
tidy: ## Tidy go.mod / go.sum.
$(GO) mod tidy
.PHONY: lint
lint: ## Run golangci-lint (if installed).
ifeq ($(GOLANGCI_LINT),)
@echo "golangci-lint not found; install: https://golangci-lint.run/usage/install/ -- skipping."
else
golangci-lint run ./...
endif
.PHONY: test
test: ## Run unit tests.
$(GO) test ./...
.PHONY: test-verbose
test-verbose: ## Run unit tests with verbose output.
$(GO) test -v ./...
.PHONY: cover
cover: ## Run unit tests and report coverage.
$(GO) test -coverprofile=coverage.out ./...
$(GO) tool cover -func=coverage.out
##@ Build
.PHONY: build
build: vet ## Build the device-plugin binary into bin/. (run `make fmt` separately to format)
mkdir -p $(OUTPUT_DIR)
CGO_ENABLED=0 $(GO) build -ldflags "$(LDFLAGS)" -o $(OUTPUT_DIR)/$(BINARY) $(MAIN_PKG)
.PHONY: clean
clean: ## Remove build artifacts.
rm -rf $(OUTPUT_DIR) coverage.out
##@ Container
.PHONY: docker-build
docker-build: ## Build the container image ($(IMG)). Set GOPROXY=... for a faster module proxy.
$(DOCKER) build $(DOCKER_BUILD_ARGS) -t $(IMG) .
.PHONY: docker-push
docker-push: ## Push the container image ($(IMG)).
$(DOCKER) push $(IMG)
##@ Deployment (requires kubectl + a valid KUBECONFIG)
.PHONY: deploy
deploy: ## Deploy RBAC + DaemonSet to the current cluster.
kubectl apply -f k8s-mock-rbac.yaml
kubectl apply -f k8s-mock-plugin.yaml
.PHONY: undeploy
undeploy: ## Remove the DaemonSet + RBAC from the current cluster.
kubectl delete -f k8s-mock-plugin.yaml --ignore-not-found
kubectl delete -f k8s-mock-rbac.yaml --ignore-not-found