-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathMakefile
159 lines (125 loc) · 4.22 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
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
REGISTRY ?= ghcr.io/azure/placement-policy-scheduler-plugins
IMAGE_NAME := placement-policy
IMAGE_VERSION ?= v0.1.0
# Directories
ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
BIN_DIR := $(abspath $(ROOT_DIR)/bin)
TOOLS_DIR := hack/tools
TOOLS_BIN_DIR := $(abspath $(TOOLS_DIR)/bin)
# Binaries
CONTROLLER_GEN_VER := v0.7.0
CONTROLLER_GEN_BIN := controller-gen
CONTROLLER_GEN := $(TOOLS_BIN_DIR)/$(CONTROLLER_GEN_BIN)-$(CONTROLLER_GEN_VER)
GOLANGCI_LINT_VER := v1.41.1
GOLANGCI_LINT_BIN := golangci-lint
GOLANGCI_LINT := $(TOOLS_BIN_DIR)/$(GOLANGCI_LINT_BIN)-$(GOLANGCI_LINT_VER)
# Scripts
GO_INSTALL := ./hack/go-install.sh
UPDATE_GENERATED_OPENAPI := ./hack/update-generated-openapi.sh
INSTALL_ETCD := ./hack/install-etcd.sh
RUN_TEST := ./hack/integration-test.sh
## --------------------------------------
## Tooling Binaries
## --------------------------------------
$(CONTROLLER_GEN):
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) sigs.k8s.io/controller-tools/cmd/controller-gen $(CONTROLLER_GEN_BIN) $(CONTROLLER_GEN_VER)
$(GOLANGCI_LINT):
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) github.com/golangci/golangci-lint/cmd/golangci-lint $(GOLANGCI_LINT_BIN) $(GOLANGCI_LINT_VER)
## --------------------------------------
## Testing
## --------------------------------------
# Run go fmt against code
.PHONY: fmt
fmt:
go fmt ./...
# Run go vet against code
.PHONY: vet
vet:
go vet ./...
# Run go mod vendor against go.mod
.PHONY: vendor
vendor:
go mod tidy
go mod vendor
# Install etcd
.PHONY: install-etcd
install-etcd:
$(INSTALL_ETCD)
# Run unit tests
.PHONY: unit-test
unit-test: autogen manager manifests
go test ./pkg/... -mod=vendor -coverprofile cover.out
## --------------------------------------
## Linting
## --------------------------------------
.PHONY: lint
lint: $(GOLANGCI_LINT)
$(GOLANGCI_LINT) run -v
.PHONY: lint-full
lint-full: $(GOLANGCI_LINT) ## Run slower linters to detect possible issues
$(GOLANGCI_LINT) run -v --fast=false
## --------------------------------------
## Code Generation
## --------------------------------------
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
CRD_OPTIONS ?= "crd:crdVersions=v1"
# Generate manifests e.g. CRD, RBAC etc.
.PHONY: manifests
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="./..."
## --------------------------------------
## Binaries
## --------------------------------------
# Build manager binary
.PHONY: manager
manager: generate fmt vet
go build -o bin/manager cmd/scheduler/main.go
.PHONY: autogen
autogen: vendor
$(UPDATE_GENERATED_OPENAPI)
## --------------------------------------
## Integration Testing
## --------------------------------------
# Run integration tests
.PHONY: integration-test
integration-test: install-etcd autogen manager manifests
$(RUN_TEST)
## --------------------------------------
## E2E Testing
## --------------------------------------
# Run all tests
.PHONY: e2e-test
e2e-test:
REGISTRY=${REGISTRY} IMAGE_NAME=${IMAGE_NAME} IMAGE_VERSION=${IMAGE_VERSION} go test -tags=e2e -v ./test/e2e
## --------------------------------------
## Images
## --------------------------------------
OUTPUT_TYPE ?= type=registry
BUILDX_BUILDER_NAME ?= img-builder
QEMU_VERSION ?= 5.2.0-2
.PHONY: docker-buildx-builder
docker-buildx-builder:
@if ! docker buildx ls | grep $(BUILDX_BUILDER_NAME); then \
docker run --rm --privileged multiarch/qemu-user-static:$(QEMU_VERSION) --reset -p yes; \
docker buildx create --name $(BUILDX_BUILDER_NAME) --use; \
docker buildx inspect $(BUILDX_BUILDER_NAME) --bootstrap; \
fi
.PHONY: docker-build
docker-build: docker-buildx-builder
docker buildx build \
--file Dockerfile \
--output=$(OUTPUT_TYPE) \
--platform="linux/amd64" \
--pull \
--tag $(REGISTRY)/$(IMAGE_NAME):$(IMAGE_VERSION) .
## --------------------------------------
## Release
## --------------------------------------
.PHONY: promote-staging-manifest
promote-staging-manifest:
@rm -rf deploy charts/placement-policy-scheduler-plugins
@cp -r manifest_staging/deploy .
@cp -r manifest_staging/charts .