This repository has been archived by the owner on Jun 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 172
/
Makefile
174 lines (153 loc) · 7.3 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# Explicitly opt into go modules, even though we're inside a GOPATH directory
export GO111MODULE=on
# Image URL to use all building/pushing image targets
DOCKER_REG ?= ${or ${VC_DOCKER_REGISTRY},"virtualcluster"}
IMG ?= ${DOCKER_REG}/manager-amd64 ${DOCKER_REG}/vn-agent-amd64 ${DOCKER_REG}/syncer-amd64
# TEST_FLAGS used as flags of go test.
TEST_FLAGS ?= -v --race
# COVERAGE_PACKAGES is the coverage we care about.
COVERAGE_PACKAGES=$(shell go list ./... | \
grep -v sigs.k8s.io/multi-tenancy/incubator/virtualcluster/pkg/client | \
grep -v sigs.k8s.io/multi-tenancy/incubator/virtualcluster/pkg/apis | \
grep -v sigs.k8s.io/multi-tenancy/incubator/virtualcluster/cmd | \
grep -v sigs.k8s.io/multi-tenancy/incubator/virtualcluster/test/e2e)
# CRD_OPTIONS ?= "crd:trivialVersions=true"
CRD_OPTIONS ?= "crd:trivialVersions=true,maxDescLen=0"
# Build code.
#
# Args:
# WHAT: Directory names to build. If any of these directories has a 'main'
# package, the build will produce executable files under $(OUT_DIR).
# If not specified, "everything" will be built.
# GOFLAGS: Extra flags to pass to 'go' when building.
# GOLDFLAGS: Extra linking flags passed to 'go' when building.
# GOGCFLAGS: Additional go compile flags passed to 'go' when building.
#
# Example:
# make
# make all
# make all WHAT=cmd/kubelet GOFLAGS=-v
# make all GOLDFLAGS=""
# Note: Specify GOLDFLAGS as an empty string for building unstripped binaries, which allows
# you to use code debugging tools like delve. When GOLDFLAGS is unspecified, it defaults
# to "-s -w" which strips debug information. Other flags that can be used for GOLDFLAGS
# are documented at https://golang.org/cmd/link/
.PHONY: all
all: test build
build:
hack/make-rules/build.sh $(WHAT)
# Run tests
.PHONY: test
PWD = $(CURDIR)
test: generate fmt vet manifests
@mkdir -p coverage
@( for pkg in ${COVERAGE_PACKAGES}; do \
go test ${TEST_FLAGS} \
-coverprofile=coverage/unit-test-`echo $$pkg | tr "/" "_"`.out \
$$pkg || exit 1 ;\
done )
@( cd ./pkg/vn-agent/server/test; \
go test ${TEST_FLAGS} \
-coverprofile=${PWD}/coverage/unit-test-pkg_vn-agent_server_test.out )
@cd ${PWD}
.PHONY: coverage
coverage: ## combine coverage after test
@mkdir -p coverage
@gocovmerge coverage/* > coverage/coverage.txt
@go tool cover -html=coverage/coverage.txt -o coverage/coverage.html
.PHONY: clean
clean: ## clean to remove bin/* and files created by module
@go mod tidy
@rm -rf _output/*
@rm -rf coverage/*
# Run against the configured Kubernetes cluster in ~/.kube/config
run: generate fmt vet
go run ./cmd/manager/main.go
# Install CRDs into a cluster
install: manifests
kubectl apply -f config/crds
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
deploy: manifests
kubectl apply -f config/crds
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 paths="./..." output:crd:artifacts:config=config/crds
hack/make-rules/replace-null.sh
# To work around a known controller gen issue
# https://github.com/kubernetes-sigs/kubebuilder/issues/1544
ifeq (, $(shell which yq))
@echo "Please install yq for yaml patching. Get it from here: https://github.com/mikefarah/yq"
@exit
else
@{ \
yq w -i config/crds/tenancy.x-k8s.io_clusterversions.yaml "spec.validation.openAPIV3Schema.properties.spec.properties.apiServer.properties.statefulset.properties.spec.properties.template.properties.spec.properties.containers.items.properties.ports.items.required[1]" protocol;\
yq w -i config/crds/tenancy.x-k8s.io_clusterversions.yaml "spec.validation.openAPIV3Schema.properties.spec.properties.controllerManager.properties.statefulset.properties.spec.properties.template.properties.spec.properties.containers.items.properties.ports.items.required[1]" protocol;\
yq w -i config/crds/tenancy.x-k8s.io_clusterversions.yaml "spec.validation.openAPIV3Schema.properties.spec.properties.etcd.properties.statefulset.properties.spec.properties.template.properties.spec.properties.containers.items.properties.ports.items.required[1]" protocol;\
yq w -i config/crds/tenancy.x-k8s.io_clusterversions.yaml "spec.validation.openAPIV3Schema.properties.spec.properties.apiServer.properties.statefulset.properties.spec.properties.template.properties.spec.properties.initContainers.items.properties.ports.items.required[1]" protocol;\
yq w -i config/crds/tenancy.x-k8s.io_clusterversions.yaml "spec.validation.openAPIV3Schema.properties.spec.properties.controllerManager.properties.statefulset.properties.spec.properties.template.properties.spec.properties.initContainers.items.properties.ports.items.required[1]" protocol;\
yq w -i config/crds/tenancy.x-k8s.io_clusterversions.yaml "spec.validation.openAPIV3Schema.properties.spec.properties.etcd.properties.statefulset.properties.spec.properties.template.properties.spec.properties.initContainers.items.properties.ports.items.required[1]" protocol;\
yq w -i config/crds/tenancy.x-k8s.io_clusterversions.yaml "spec.validation.openAPIV3Schema.properties.spec.properties.apiServer.properties.service.properties.spec.properties.ports.items.required[1]" protocol;\
yq w -i config/crds/tenancy.x-k8s.io_clusterversions.yaml "spec.validation.openAPIV3Schema.properties.spec.properties.controllerManager.properties.service.properties.spec.properties.ports.items.required[1]" protocol;\
yq w -i config/crds/tenancy.x-k8s.io_clusterversions.yaml "spec.validation.openAPIV3Schema.properties.spec.properties.etcd.properties.service.properties.spec.properties.ports.items.required[1]" protocol;\
}
endif
# Run go fmt against code
fmt:
go fmt ./pkg/... ./cmd/...
# Run go vet against code
vet:
go vet ./pkg/... ./cmd/...
# Generate code
generate: controller-gen
ifndef GOPATH
$(error GOPATH not defined, please define GOPATH. Run "go help gopath" to learn more about GOPATH)
endif
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
# Build release image.
#
# 1. run tests
# 2. build docker image
.PHONY: release-images
release-images: test build-images
# Build docker image.
#
# 1. build all binaries.
# 2. copy binaries to the corresponding docker image.
build-images:
hack/make-rules/release-images.sh $(WHAT)
# Push the docker image
docker-push:
$(foreach i,$(IMG),docker push $i;)
# 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/[email protected] ;\
rm -rf $$CONTROLLER_GEN_TMP_DIR ;\
}
CONTROLLER_GEN=$(GOPATH)/bin/controller-gen
else
CONTROLLER_GEN=$(shell which controller-gen)
endif
# Build and run kubernetes e2e tests.
#
# Args:
# KUBECONFIG: kubeconfig to virtual cluster. If empty, create a virtual cluster.
# Defaults to "".
# FOCUS: Regexp that matches the tests to be run. Defaults to "\[Conformance\]".
# SKIP: Regexp that matches the tests that needs to be skipped.
# Defaults to "\[Flaky\]|\[Slow\]|\[Serial\]"
# BUILD_DEPENDENCIES: if true, build dependencies related to e2e test.
# Defaults to true.
#
# Example:
# make test-e2e-k8s KUBECONFIG=/path/to/vc-kubeconfig
.PHONY: test-e2e-k8s
test-e2e-k8s:
hack/make-rules/test-e2e-k8s.sh