This repository has been archived by the owner on Feb 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
201 lines (170 loc) · 7.34 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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# Copyright 2020 The Bulward Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
CERTMANAGER_VERSION = v0.14.0
COMPONENTS = manager apiserver
IMAGE_ORG = quay.io/kubermatic
KIND_CLUSTER ?= bulward
KUBECONFIG ?= ${HOME}/.kube/kind-config-${KIND_CLUSTER}
SHELL=/bin/bash
.SHELLFLAGS=-euo pipefail -c
VERSION = v1
# Dev Image to use
# Always bump this version, when changing ANY component version below.
DEV_IMAGE_TAG=v2
# Versions used to build DEV image:
export CONTROLLER_GEN_VERSION=0.2.9
export APISERVER_BUILDER_VERSION=1.18.0
export PROTOBUF_VERSION=3.12.4
# Debug BUILD_ARGS
# BUILD_ARGS?=-gcflags "all=-N -l"
# sudo dlv attach --headless=true -l localhost:9060 --api-version=2 --accept-multiclient --only-same-user=false <PID>
# <PID> could be find via pgrep e.g. $(pgrep apiserver -n)
BUILD_ARGS?=
export CGO_ENABLED:=0
ifdef CI
# prow sets up GOPATH and we want to make sure it's in the PATH
# https://github.com/kubernetes/test-infra/issues/9469
# https://github.com/kubernetes/test-infra/blob/895df89b7e4238125063157842c191dac6f7e58f/prow/pod-utils/decorate/podspec.go#L474
export PATH:=${PATH}:${GOPATH}/bin
endif
# -----------------
# Compile & Release
# -----------------
bin/linux_amd64/%: GOARGS = GOOS=linux GOARCH=amd64
bin/darwin_amd64/%: GOARGS = GOOS=darwin GOARCH=amd64
bin/windows_amd64/%: GOARGS = GOOS=windows GOARCH=amd64
bin/%:
$(eval COMPONENT=$(shell basename $*))
$(GOARGS) go build $(BUILD_ARGS) -o bin/$* cmd/$(COMPONENT)/main.go
# ---------------
# Code Generators
# ---------------
# This should only be executed once the new crd is added in the apiserver api group.
generate-apiregister:
ifdef CI
apiregister-gen --input-dirs k8c.io/bulward/pkg/apis/apiserver/... --input-dirs k8c.io/bulward/pkg/apis --go-header-file ./hack/boilerplate/boilerplate.go.txt
@rm -Rf ./plugin
else
@docker run --rm -e CI=true \
-w /go/src/k8c.io/bulward \
-v $(PWD):/go/src/k8c.io/bulward:delegated \
--user "$(id -u):$(id -g)" \
${IMAGE_ORG}/bulward-dev:${DEV_IMAGE_TAG} \
make generate-apiregister
endif
generate:
ifdef CI
@hack/codegen.sh
else
@docker run --rm -e CI=true \
-w /go/src/k8c.io/bulward \
-v $(PWD):/go/src/k8c.io/bulward:delegated \
--user "$(id -u):$(id -g)" \
${IMAGE_ORG}/bulward-dev:${DEV_IMAGE_TAG} \
make generate
endif
setup-cluster: require-docker
@mkdir -p /tmp/bulward-hack
@cp ./hack/audit.yaml /tmp/bulward-hack
@kind create cluster --retain --config=./hack/kind-config.yaml --name=${KIND_CLUSTER} --image=${KIND_NODE_IMAGE} || true
@kind get kubeconfig --name=${KIND_CLUSTER} > "${KUBECONFIG}"
@kubectl create namespace bulward-system || true # ignore if exists
deploy-manager: setup-cluster kind-load-manager
@echo "deploying manager"
@kubectl apply -k config/manager/default -o yaml --dry-run | sed "s|quay.io/kubermatic/bulward-manager:v1|${IMAGE_ORG}/bulward-manager:${VERSION}|g" | kubectl apply -f -
kubectl wait --for=condition=available deployment/bulward-controller-manager -n bulward-system --timeout=120s
deploy-apiserver: setup-cluster cert-manager kind-load-apiserver
@echo "deploying API extension server"
@#kubectl 1.18.3 has older kustomize version which improperly renders APIService name
@kustomize build config/apiserver/default | sed "s|quay.io/kubermatic/bulward-apiserver:v1|${IMAGE_ORG}/bulward-apiserver:${VERSION}|g" | kubectl apply -f -
@kubectl apply -f config/apiserver/rbac/extension_apiserver_auth_role_binding.yaml
kubectl wait --for=condition=available deployment/bulward-apiserver-controller-manager -n bulward-system --timeout=120s
deploy: deploy-apiserver deploy-manager
e2e-test: deploy
@./hack/e2e-test.sh
# ------------
# Test Runners
# ------------
test:
CGO_ENABLED=1 go test -race -v ./pkg/...
.PHONY: test
lint: pre-commit
@hack/validate-directory-clean.sh
golangci-lint run ./... --skip-files ".*generated.*" --deadline=15m
# -------------
# Util Commands
# -------------
fmt:
go fmt ./...
vet:
go vet ./...
tidy:
go mod tidy
pre-commit:
pre-commit run -a
require-docker:
@docker ps > /dev/null 2>&1 || start-docker.sh || ./hack/start-docker.sh || (echo "cannot find running docker daemon nor can start new one" && false)
@[[ -z "${QUAY_IO_USERNAME}" ]] || ( echo "logging in to ${QUAY_IO_USERNAME}" && docker login -u ${QUAY_IO_USERNAME} -p ${QUAY_IO_PASSWORD} quay.io )
.PHONY: require-docker
# Install cert-manager in the configured Kubernetes cluster
cert-manager: setup-cluster
@echo "Deploy cert-manger in management cluster"
docker pull quay.io/jetstack/cert-manager-controller:${CERTMANAGER_VERSION}
docker pull quay.io/jetstack/cert-manager-cainjector:${CERTMANAGER_VERSION}
docker pull quay.io/jetstack/cert-manager-webhook:${CERTMANAGER_VERSION}
kind load docker-image quay.io/jetstack/cert-manager-controller:${CERTMANAGER_VERSION} --name=${KIND_CLUSTER}
kind load docker-image quay.io/jetstack/cert-manager-cainjector:${CERTMANAGER_VERSION} --name=${KIND_CLUSTER}
kind load docker-image quay.io/jetstack/cert-manager-webhook:${CERTMANAGER_VERSION} --name=${KIND_CLUSTER}
kubectl apply -f https://github.com/jetstack/cert-manager/releases/download/${CERTMANAGER_VERSION}/cert-manager.yaml
kubectl wait --for=condition=available deployment/cert-manager -n cert-manager --timeout=120s
kubectl wait --for=condition=available deployment/cert-manager-cainjector -n cert-manager --timeout=120s
kubectl wait --for=condition=available deployment/cert-manager-webhook -n cert-manager --timeout=120s
# ----------------
# Container Images
# ----------------
.SECONDEXPANSION:
build-image-%: bin/linux_amd64/$$* require-docker
@mkdir -p bin/image/$*
@mv bin/linux_amd64/$* bin/image/$*
@cp -a config/dockerfiles/$*.Dockerfile bin/image/$*/Dockerfile
@docker build -t ${IMAGE_ORG}/bulward-$*:${VERSION} bin/image/$*
kind-load-%: build-image-$$* setup-cluster
kind load docker-image ${IMAGE_ORG}/bulward-$*:${VERSION} --name=${KIND_CLUSTER}
build-image-test: require-docker
@mkdir -p bin/image/test
@cp -a config/dockerfiles/test.Dockerfile bin/image/test/Dockerfile
@cp -a .pre-commit-config.yaml bin/image/test
@cp -a go.mod go.sum bin/image/test
@cp -a hack/start-docker.sh bin/image/test
@docker build -t ${IMAGE_ORG}/bulward-test bin/image/test
push-image-test: build-image-test require-docker
@docker push ${IMAGE_ORG}/bulward-test
@echo pushed ${IMAGE_ORG}/bulward-test
build-image-dev: require-docker
@mkdir -p bin/image/dev
@cp -a config/dockerfiles/dev.Dockerfile bin/image/dev/Dockerfile
@docker build -t ${IMAGE_ORG}/bulward-dev:${DEV_IMAGE_TAG} bin/image/dev \
--build-arg CONTROLLER_GEN_VERSION=${CONTROLLER_GEN_VERSION} \
--build-arg APISERVER_BUILDER_VERSION=${APISERVER_BUILDER_VERSION} \
--build-arg PROTOBUF_VERSION=${PROTOBUF_VERSION}
push-image-dev: build-image-dev
@docker push ${IMAGE_ORG}/bulward-dev:${DEV_IMAGE_TAG}
@echo pushed ${IMAGE_ORG}/bulward-dev:${DEV_IMAGE_TAG}
# -------
# Cleanup
# -------
clean:
@rm -rf bin/$*
@kind delete cluster --name=${KIND_CLUSTER}
.PHONY: clean