forked from openshift/hypershift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
290 lines (234 loc) · 10.5 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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
DIR := ${CURDIR}
# Image URL to use all building/pushing image targets
IMG ?= hypershift:latest
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
CRD_OPTIONS ?= "crd"
# Runtime CLI to use for building and pushing images
RUNTIME ?= $(shell sh hack/utils.sh get_container_engine)
TOOLS_DIR=./hack/tools
BIN_DIR=bin
TOOLS_BIN_DIR := $(TOOLS_DIR)/$(BIN_DIR)
CONTROLLER_GEN := $(abspath $(TOOLS_BIN_DIR)/controller-gen)
STATICCHECK := $(abspath $(TOOLS_BIN_DIR)/staticcheck)
GENAPIDOCS := $(abspath $(TOOLS_BIN_DIR)/gen-crd-api-reference-docs)
PROMTOOL=$(abspath $(TOOLS_BIN_DIR)/promtool)
GO_GCFLAGS ?= -gcflags=all='-N -l'
GO=GO111MODULE=on GOFLAGS=-mod=vendor go
GO_BUILD_RECIPE=CGO_ENABLED=1 $(GO) build $(GO_GCFLAGS)
GO_E2E_RECIPE=CGO_ENABLED=1 $(GO) test $(GO_GCFLAGS) -tags e2e -c
CI_TESTS_RUN ?= ""
OUT_DIR ?= bin
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif
# Change HOME to writeable location in CI for staticcheck
ifeq ("/","${HOME}")
HOME=/tmp
endif
all: build e2e
pre-commit: all verify test
build: hypershift-operator control-plane-operator control-plane-pki-operator hypershift product-cli
.PHONY: update
update: api-deps api api-docs deps clients app-sre-saas-template
.PHONY: verify
verify: update staticcheck fmt vet
git diff-index --cached --quiet --ignore-submodules HEAD --
git diff-files --quiet --ignore-submodules
git diff --exit-code HEAD --
$(eval STATUS = $(shell git status -s))
$(if $(strip $(STATUS)),$(error untracked files detected: ${STATUS}))
$(CONTROLLER_GEN): $(TOOLS_DIR)/go.mod # Build controller-gen from tools folder.
cd $(TOOLS_DIR); GO111MODULE=on GOFLAGS=-mod=vendor go build -tags=tools -o $(BIN_DIR)/controller-gen sigs.k8s.io/controller-tools/cmd/controller-gen
$(STATICCHECK): $(TOOLS_DIR)/go.mod # Build staticcheck from tools folder.
cd $(TOOLS_DIR); GO111MODULE=on GOFLAGS=-mod=vendor go build -tags=tools -o $(BIN_DIR)/staticcheck honnef.co/go/tools/cmd/staticcheck
$(GENAPIDOCS): $(TOOLS_DIR)/go.mod
cd $(TOOLS_DIR); GO111MODULE=on GOFLAGS=-mod=vendor go build -tags=tools -o $(GENAPIDOCS) github.com/ahmetb/gen-crd-api-reference-docs
# Build hypershift-operator binary
.PHONY: hypershift-operator
hypershift-operator:
$(GO_BUILD_RECIPE) -o $(OUT_DIR)/hypershift-operator ./hypershift-operator
.PHONY: control-plane-operator
control-plane-operator:
$(GO_BUILD_RECIPE) -o $(OUT_DIR)/control-plane-operator ./control-plane-operator
.PHONY: control-plane-pki-operator
control-plane-pki-operator:
$(GO_BUILD_RECIPE) -o $(OUT_DIR)/control-plane-pki-operator ./control-plane-pki-operator
.PHONY: hypershift
hypershift:
$(GO_BUILD_RECIPE) -o $(OUT_DIR)/hypershift .
.PHONY: product-cli
product-cli:
$(GO_BUILD_RECIPE) -o $(OUT_DIR)/hcp ./product-cli
# Run this when updating any of the types in the api package to regenerate the
# deepcopy code and CRD manifest files.
.PHONY: api
api: hypershift-api cluster-api cluster-api-provider-aws cluster-api-provider-ibmcloud cluster-api-provider-kubevirt cluster-api-provider-agent cluster-api-provider-azure api-docs
.PHONY: hypershift-api
hypershift-api: $(CONTROLLER_GEN)
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./api/..."
rm -rf cmd/install/assets/hypershift-operator/*.yaml
$(CONTROLLER_GEN) $(CRD_OPTIONS) paths="./api/..." output:crd:artifacts:config=cmd/install/assets/hypershift-operator
.PHONY: cluster-api
cluster-api: $(CONTROLLER_GEN)
rm -rf cmd/install/assets/cluster-api/*.yaml
$(CONTROLLER_GEN) $(CRD_OPTIONS) paths="./vendor/sigs.k8s.io/cluster-api/api/..." output:crd:artifacts:config=cmd/install/assets/cluster-api
$(CONTROLLER_GEN) $(CRD_OPTIONS) paths="./vendor/sigs.k8s.io/cluster-api/exp/api/..." output:crd:artifacts:config=cmd/install/assets/cluster-api
.PHONY: cluster-api-provider-aws
cluster-api-provider-aws: $(CONTROLLER_GEN)
rm -rf cmd/install/assets/cluster-api-provider-aws/*.yaml
$(CONTROLLER_GEN) $(CRD_OPTIONS) paths="./vendor/sigs.k8s.io/cluster-api-provider-aws/v2/api/..." output:crd:artifacts:config=cmd/install/assets/cluster-api-provider-aws
$(CONTROLLER_GEN) $(CRD_OPTIONS) paths="./vendor/sigs.k8s.io/cluster-api-provider-aws/v2/exp/api/..." output:crd:artifacts:config=cmd/install/assets/cluster-api-provider-aws
$(CONTROLLER_GEN) $(CRD_OPTIONS) paths="./vendor/sigs.k8s.io/cluster-api/exp/addons/api/..." output:crd:artifacts:config=cmd/install/assets/cluster-api
.PHONY: cluster-api-provider-ibmcloud
cluster-api-provider-ibmcloud: $(CONTROLLER_GEN)
rm -rf cmd/install/assets/cluster-api-provider-ibmcloud/*.yaml
$(CONTROLLER_GEN) $(CRD_OPTIONS) paths="./vendor/sigs.k8s.io/cluster-api-provider-ibmcloud/api/..." output:crd:artifacts:config=cmd/install/assets/cluster-api-provider-ibmcloud
.PHONY: cluster-api-provider-kubevirt
cluster-api-provider-kubevirt: $(CONTROLLER_GEN)
rm -rf cmd/install/assets/cluster-api-provider-kubevirt/*.yaml
$(CONTROLLER_GEN) $(CRD_OPTIONS) paths="./vendor/sigs.k8s.io/cluster-api-provider-kubevirt/api/v1alpha1" output:crd:artifacts:config=cmd/install/assets/cluster-api-provider-kubevirt
.PHONY: cluster-api-provider-agent
cluster-api-provider-agent: $(CONTROLLER_GEN)
rm -rf cmd/install/assets/cluster-api-provider-agent/*.yaml
$(CONTROLLER_GEN) $(CRD_OPTIONS) paths="./vendor/github.com/openshift/cluster-api-provider-agent/api/..." output:crd:artifacts:config=cmd/install/assets/cluster-api-provider-agent
.PHONY: cluster-api-provider-azure
cluster-api-provider-azure: $(CONTROLLER_GEN)
rm -rf cmd/install/assets/cluster-api-provider-azure/*.yaml
$(CONTROLLER_GEN) $(CRD_OPTIONS) paths="./vendor/sigs.k8s.io/cluster-api-provider-azure/api/..." output:crd:artifacts:config=cmd/install/assets/cluster-api-provider-azure
.PHONY: api-docs
api-docs: $(GENAPIDOCS)
hack/gen-api-docs.sh $(GENAPIDOCS) $(DIR)
.PHONY: clients
clients:
hack/update-codegen.sh
.PHONY: release
release:
go run ./hack/tools/release/notes.go --from=${FROM} --to=${TO} --token=${TOKEN}
.PHONY: app-sre-saas-template
app-sre-saas-template: hypershift
bin/hypershift install \
--oidc-storage-provider-s3-bucket-name=bucket \
--oidc-storage-provider-s3-secret=oidc-s3-creds \
--oidc-storage-provider-s3-region=us-east-1 \
--oidc-storage-provider-s3-secret-key=credentials \
--platform-monitoring=None \
--enable-ci-debug-output=false \
--enable-admin-rbac-generation=true \
--private-platform=AWS \
--aws-private-region=eu-east-1 \
--aws-private-secret=aws-credentials \
--aws-private-secret-key=credentials \
--external-dns-provider=aws \
--external-dns-secret=dns-credentials \
--external-dns-domain-filter=service.hypershift.example.org \
--external-dns-txt-owner-id=txt-owner-id \
--metrics-set=SRE \
render --template --format yaml > $(DIR)/hack/app-sre/saas_template.yaml
# Run tests
.PHONY: test
test:
$(GO) test -race -count=25 -timeout=30m ./... -coverprofile cover.out
.PHONY: e2e
e2e:
$(GO_E2E_RECIPE) -o bin/test-e2e ./test/e2e
$(GO_BUILD_RECIPE) -o bin/test-setup ./test/setup
cd $(TOOLS_DIR); GO111MODULE=on GOFLAGS=-mod=vendor go build -tags=tools -o ../../bin/gotestsum gotest.tools/gotestsum
# Run go fmt against code
.PHONY: fmt
fmt:
$(GO) fmt ./...
# Run go vet against code
.PHONY: vet
vet:
$(GO) vet -tags integration,e2e ./...
# jparrill: The RHTAP tool is breaking the RHTAP builds from Feb 27th, so we're stop using it for now
# more info here https://redhat-internal.slack.com/archives/C031USXS2FJ/p1710177462151639
#.PHONY: build-promtool
#build-promtool:
# cd $(TOOLS_DIR); $(GO) build -o $(PROMTOOL) github.com/prometheus/prometheus/cmd/promtool
#
#.PHONY: promtool
#promtool: build-promtool
# cd $(TOOLS_DIR); $(PROMTOOL) check rules ../../cmd/install/assets/slos/*.yaml ../../cmd/install/assets/recordingrules/*.yaml ../../control-plane-operator/controllers/hostedcontrolplane/kas/assets/*.yaml
# Updates Go modules
.PHONY: deps
deps:
$(GO) mod tidy
$(GO) mod vendor
$(GO) mod verify
$(GO) list -m -mod=readonly -json all > /dev/null
(cd hack/tools && $(GO) mod tidy && $(GO) mod vendor && $(GO) mod verify && $(GO) list -m -mod=readonly -json all > /dev/null)
.PHONY: api-deps
api-deps:
cd api && \
$(GO) mod tidy && \
$(GO) mod vendor && \
$(GO) mod verify && \
$(GO) list -m -mod=readonly -json all > /dev/null
# Run staticcheck
# How to ignore failures https://staticcheck.io/docs/configuration#line-based-linter-directives
.PHONY: staticcheck
staticcheck: $(STATICCHECK)
$(STATICCHECK) \
./control-plane-operator/... \
./control-plane-pki-operator/... \
./hypershift-operator/controllers/... \
./ignition-server/... \
./cmd/... \
./support/certs/... \
./support/releaseinfo/... \
./support/upsert/... \
./konnectivity-socks5-proxy/... \
./contrib/... \
./availability-prober/... \
./test/integration/... \
# Build the docker image with official golang image
.PHONY: docker-build
docker-build:
${RUNTIME} build . -t ${IMG}
.PHONY: fast.Dockerfile.dockerignore
fast.Dockerfile.dockerignore:
sed -e '/^bin\//d' .dockerignore > fast.Dockerfile.dockerignore
# Build the docker image copying binaries from workspace
.PHONY: docker-build-fast
docker-build-fast: build fast.Dockerfile.dockerignore
ifeq ($(RUNTIME),podman)
${RUNTIME} build . -t ${IMG} -f fast.Dockerfile --ignorefile fast.Dockerfile.dockerignore
else
DOCKER_BUILDKIT=1 ${RUNTIME} build . -t ${IMG} -f fast.Dockerfile
endif
# Push the docker image
.PHONY: docker-push
docker-push:
${RUNTIME} push ${IMG}
.PHONY: run-local
run-local:
bin/hypershift-operator run
.PHONY: ci-install-hypershift
ci-install-hypershift: ci-install-hypershift-private
.PHONY: ci-install-hypershift-private
ci-install-hypershift-private:
bin/hypershift install --hypershift-image $(HYPERSHIFT_RELEASE_LATEST) \
--oidc-storage-provider-s3-credentials=/etc/hypershift-pool-aws-credentials/credentials \
--oidc-storage-provider-s3-bucket-name=hypershift-ci-oidc \
--oidc-storage-provider-s3-region=us-east-1 \
--private-platform=AWS \
--aws-private-creds=/etc/hypershift-pool-aws-credentials/credentials \
--aws-private-region=us-east-1 \
--external-dns-provider=aws \
--external-dns-credentials=/etc/hypershift-pool-aws-credentials/credentials \
--external-dns-domain-filter=service.ci.hypershift.devcluster.openshift.com \
--wait-until-available
.PHONY: ci-test-e2e
ci-test-e2e:
hack/ci-test-e2e.sh ${CI_TESTS_RUN}
.PHONY: ci-test-e2e-azure
ci-test-e2e-azure:
hack/ci-test-e2e-azure.sh
.PHONY: regenerate-pki
regenerate-pki:
REGENERATE_PKI=1 $(GO) test ./control-plane-pki-operator/...
REGENERATE_PKI=1 $(GO) test ./test/e2e/... -run TestRegeneratePKI