forked from kubewharf/kubeadmiral
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
145 lines (128 loc) · 5.15 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
SHELL := /bin/bash
# go build arguments
BUILD_FLAGS ?=
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
GOPROXY ?= $(shell go env GOPROXY)
TARGET_NAME ?= kubeadmiral-controller-manager
# image information
REGISTRY ?= ghcr.io/kubewharf
TAG ?= latest
REGION ?=
ifeq (${REGION}, cn)
GOPROXY := https://goproxy.cn,direct
endif
.PHONY: all
all: build
# Production build
#
# Args:
# BUILD_PLATFORMS: platforms to build. e.g.: linux/amd64,darwin/amd64. The default value is the host platform.
#
# Example:
# # compile kubeadmiral-controller-manager with the host platform
# make build
# # compile kubeadmiral-controller-manager with specified platforms
# make build BUILD_PLATFORMS=linux/amd64,darwin/amd64
.PHONY: build
build:
BUILD_FLAGS=$(BUILD_FLAGS) TARGET_NAME=$(TARGET_NAME) GOPROXY=$(GOPROXY) bash hack/make-rules/build.sh
# Start a local kubeadmiral cluster for developers.
#
# It will directly start the kubeadmiral control-plane cluster(excluding the kubeadmiral-controller-manager) and three member-clusters.
# Users can run the kubeadmiral-controller-manager component through binary for easy debugging, e.g.:
# ./output/bin/darwin/amd64/kubeadmiral-controller-manager_debug --create-crds-for-ftcs \
# --klog-logtostderr=false \
# --klog-log-file "./kubeadmiral.log" \
# --kubeconfig "$HOME/.kube/kubeadmiral/kubeadmiral-host.yaml" \
# 2>/dev/null
.PHONY: dev-up
dev-up:
make clean-local-cluster
bash hack/make-rules/dev-up.sh
make debug
# Local up the KubeAdmiral.
#
# Args:
# NUM_MEMBER_CLUSTERS: the number of member clusters you want to startup, default is 3, at least 1.
# REGION: region to build. e.g.: 'cn' means China mainland,
# the script will set the remote mirror address according to the region to speed up the build.
#
# Example:
# # It will locally start a meta-cluster to deploy the kubeadmiral control-plane, and three member cluster clusters
# make local-up
.PHONY: local-up
local-up:
make clean-local-cluster
REGION="$(REGION)" NUM_MEMBER_CLUSTERS="$(NUM_MEMBER_CLUSTERS)" bash hack/make-rules/local-up.sh
# Debug build
.PHONY: debug
debug: BUILD_FLAGS+=-race
debug: TARGET_NAME:=$(TARGET_NAME)_debug
debug: build
# Build binaries and docker images.
# The supported OS is linux, and user can specify the arch type (only amd64,arm64,arm are supported)
#
# ARGS:
# REGISTRY: image registry, the default value is "ghcr.io/kubewharf"
# TAG: image tag, the default value is "latest"
# ARCHS: list of target architectures, e.g.:amd64,arm64,arm. The default value is host arch
# GOPROXY: it specifies the download address of the dependent package
# REGION: region to build. e.g.: 'cn' means china mainland(the default value),
# the script will set the remote mirror address according to the region to speed up the build.
# DOCKER_BUILD_ARGS: additional parameters of the Dockerfile need to be passed in during the image building process,
# e.g.: `--build-arg BUILD_FLAGS=-race`
# DOCKERFILE_PATH: the Dockerfile path used by docker build, default is `kubeadmiral/hack/dockerfiles/Dockerfile`
#
# Examples:
# # build images with the host arch, it will generate "ghcr.io/kubewharf/kubeadmiral-controller-manager:latest"
# make images
#
# # build images with amd64,arm64 arch, and use the mirror source in mainland China during the image building process
# # note: If you specify multiple architectures, the image tag will be added with the architecture name,e.g.:
# # "ghcr.io/kubewharf/kubeadmiral-controller-manager:latest-amd64"
# # "ghcr.io/kubewharf/kubeadmiral-controller-manager:latest-arm64"
# make images ARCHS=amd64,arm64 REGION="cn"
#
# # enable race detection in go build
# make images DOCKER_BUILD_ARGS="--build-arg BUILD_FLAGS=-race"
.PHONY: images
images:
REGISTRY=$(REGISTRY) TAG=$(TAG) ARCHS=$(ARCHS) GOPROXY=$(GOPROXY) REGION=$(REGION) \
DOCKER_BUILD_ARGS="$(DOCKER_BUILD_ARGS)" DOCKERFILE_PATH="$(DOCKERFILE_PATH)" bash hack/make-rules/build-images.sh
# Clean built binaries
.PHONY: clean
clean:
rm -rf output kubeadmiral.log
# Clean up all the local kind clusters and related kubeconfigs
# Users can clean up the local kind clusters started by the `make local-up` command.
.PHONY: clean-local-cluster
clean-local-cluster:
bash hack/make-rules/clean-local-cluster.sh
# Generate code and artifacts
.PHONY: generate
generate: pkg/client
pkg/client: $(shell find pkg/apis)
bash ./hack/generate-groups.sh
# update the directory mtime to avoid unnecessary re-runs
touch pkg/client
LINT_FLAGS := --timeout=5m --max-issues-per-linter=0 --max-same-issues=0 --uniq-by-line=false
# Run golangci-lint
.PHONY: lint
lint:
golangci-lint run $(LINT_FLAGS)
# Run golangci-lint on files changed from the default branch
.PHONY: lint-new
lint-new: LINT_FLAGS += --new-from-rev=main --whole-files
lint-new: lint
# Run tests
.PHONY: test
test:
go test -race -coverprofile coverage0.out ./pkg/...
# exclude generated files from coverage calculation
sed '/generated/d' coverage0.out > coverage.out
rm coverage0.out
# Run e2e tests
.PHONY: e2e
e2e:
ginkgo run -race -tags=e2e $(EXTRA_GINKGO_FLAGS) test/e2e -- --kubeconfig=$(KUBECONFIG) $(EXTRA_E2E_FLAGS)