-
Notifications
You must be signed in to change notification settings - Fork 328
/
Makefile
322 lines (256 loc) · 13.4 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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
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)
CODE_GEN := $(abspath $(TOOLS_BIN_DIR)/codegen)
STATICCHECK := $(abspath $(TOOLS_BIN_DIR)/staticcheck)
GENAPIDOCS := $(abspath $(TOOLS_BIN_DIR)/gen-crd-api-reference-docs)
CODESPELL_VER := 2.3.0
CODESPELL_BIN := codespell
CODESPELL_DIST_DIR := codespell_dist
CODESPELL := $(TOOLS_BIN_DIR)/$(CODESPELL_DIST_DIR)/$(CODESPELL_BIN)
PROMTOOL=$(abspath $(TOOLS_BIN_DIR)/promtool)
GO_GCFLAGS ?= -gcflags=all='-N -l'
GO=GO111MODULE=on GOWORK=off GOFLAGS=-mod=vendor go
GOWS=GO111MODULE=on GOWORK=$(shell pwd)/hack/workspace/go.work GOFLAGS=-mod=vendor go
GO_BUILD_RECIPE=CGO_ENABLED=1 $(GO) build $(GO_GCFLAGS)
GO_CLI_RECIPE=CGO_ENABLED=0 $(GO) build $(GO_GCFLAGS) -ldflags '-extldflags "-static"'
GO_E2E_RECIPE=CGO_ENABLED=1 $(GO) test $(GO_GCFLAGS) -tags e2e -c
OUT_DIR ?= bin
# run the HO locally
HYPERSHIFT_INSTALL_AWS := ./hack/dev/aws/hypershft-install-aws.sh
RUN_OPERATOR_LOCALLY_AWS := ./hack/dev/aws/run-operator-locally-aws-dev.sh
# 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 tests
pre-commit: all verify test
build: hypershift-operator control-plane-operator control-plane-pki-operator hypershift product-cli
.PHONY: update
update: workspace-sync api-deps api api-docs deps clients
.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 GOWORK=off go build -tags=tools -o $(BIN_DIR)/controller-gen sigs.k8s.io/controller-tools/cmd/controller-gen
$(CODE_GEN): $(TOOLS_DIR)/go.mod # Build code-gen from tools folder.
cd $(TOOLS_DIR); GO111MODULE=on GOFLAGS=-mod=vendor GOWORK=off go build -tags=tools -o $(BIN_DIR)/codegen github.com/openshift/api/tools/codegen/cmd
$(STATICCHECK): $(TOOLS_DIR)/go.mod # Build staticcheck from tools folder.
cd $(TOOLS_DIR); GO111MODULE=on GOFLAGS=-mod=vendor GOWORK=off 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 GOWORK=off go build -tags=tools -o $(GENAPIDOCS) github.com/ahmetb/gen-crd-api-reference-docs
# Compile all tests
.PHONY: tests
tests:
$(GO) test -o /dev/null -c ./...
# Build hypershift-operator binary
.PHONY: hypershift-operator
hypershift-operator:
$(GO_BUILD_RECIPE) -o $(OUT_DIR)/hypershift-operator ./hypershift-operator
.PHONY: karpenter-operator
karpenter-operator:
$(GO_BUILD_RECIPE) -o $(OUT_DIR)/karpenter-operator ./karpenter-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_CLI_RECIPE) -o $(OUT_DIR)/hypershift .
.PHONY: product-cli
product-cli:
$(GO_CLI_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 cluster-api-provider-openstack api-docs
.PHONY: hypershift-api
hypershift-api: $(CONTROLLER_GEN) $(CODE_GEN)
# Clean up autogenerated files.
rm -rf ./api/hypershift/v1beta1/zz_generated.featuregated-crd-manifests
rm -rf ./api/hypershift/v1beta1/zz_generated.featuregated-crd-manifests.yaml
rm -rf cmd/install/assets/hypershift-operator/*
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./api/..."
# These consolidate with the 3 steps used to generate CRDs by openshift/api.
$(CODE_GEN) empty-partial-schemas --base-dir ./api/hypershift/v1beta1
$(CODE_GEN) schemapatch --base-dir ./api/hypershift/v1beta1
$(CODE_GEN) crd-manifest-merge --manifest-merge:payload-manifest-path ./api/hypershift/v1beta1/featuregates --base-dir ./api/hypershift/v1beta1
# Move final CRDs to the install folder.
mv ./api/hypershift/v1beta1/zz_generated.crd-manifests cmd/install/assets/hypershift-operator/
# Generate additional CRDs.
$(CONTROLLER_GEN) $(CRD_OPTIONS) paths="./api/scheduling/..." output:crd:artifacts:config=cmd/install/assets/hypershift-operator
$(CONTROLLER_GEN) $(CRD_OPTIONS) paths="./api/certificates/..." output:crd:artifacts:config=cmd/install/assets/hypershift-operator
# TODO: Create a feature gate and install controlplanecomponents in TechPreviewNoUpgrde featureSet.
# TODO: remove when we complete the switch to the new CPO approach.
mv ./cmd/install/assets/hypershift-operator/zz_generated.crd-manifests/controlplanecomponents-CustomNoUpgrade.crd.yaml support/controlplane-component/crds/hypershift.openshift.io_controlplanecomponents.yaml
.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
$(CONTROLLER_GEN) $(CRD_OPTIONS) paths="./vendor/sigs.k8s.io/cluster-api/exp/ipam/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
# remove ROSA CRDs
rm -rf cmd/install/assets/cluster-api-provider-aws/infrastructure.cluster.x-k8s.io_rosa*.yaml
# remove EKS CRDs
rm -rf cmd/install/assets/cluster-api-provider-aws/infrastructure.cluster.x-k8s.io_awsmanaged*.yaml
rm -rf cmd/install/assets/cluster-api-provider-aws/infrastructure.cluster.x-k8s.io_awsfargateprofiles.yaml
.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: cluster-api-provider-openstack
cluster-api-provider-openstack: $(CONTROLLER_GEN)
rm -rf cmd/install/assets/cluster-api-provider-openstack/*.yaml
$(CONTROLLER_GEN) $(CRD_OPTIONS) paths="./vendor/sigs.k8s.io/cluster-api-provider-openstack/api/..." output:crd:artifacts:config=cmd/install/assets/cluster-api-provider-openstack
$(CONTROLLER_GEN) $(CRD_OPTIONS) paths="./vendor/github.com/k-orc/openstack-resource-controller/..." output:crd:artifacts:config=cmd/install/assets/cluster-api-provider-openstack
.PHONY: api-docs
api-docs: $(GENAPIDOCS)
hack/gen-api-docs.sh $(GENAPIDOCS) $(DIR)
.PHONY: clients
clients: delegating_client
GO=GO111MODULE=on GOFLAGS=-mod=readonly hack/update-codegen.sh
.PHONY: release
release:
go run ./hack/tools/release/notes.go --from=${FROM} --to=${TO} --token=${TOKEN}
.PHONY: delegating_client
delegating_client:
go run ./cmd/infra/aws/delegatingclientgenerator/main.go > ./cmd/infra/aws/delegating_client.txt
mv ./cmd/infra/aws/delegating_client.txt ./cmd/infra/aws/delegating_client.go
$(GO) fmt ./cmd/infra/aws/delegating_client.go
# Run tests
.PHONY: test
# Determine the number of CPU cores
NUM_CORES := $(shell uname | grep -q 'Darwin' && sysctl -n hw.ncpu || nproc)
test:
echo "Running tests with $(NUM_CORES) parallel jobs..."
$(GO) test -race -parallel=$(NUM_CORES) -count=1 -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 GOWORK=off 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
.PHONY: workspace-sync
workspace-sync:
cd hack/workspace && \
$(GOWS) work sync
# 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}
# Push the docker image
.PHONY: docker-push
docker-push:
${RUNTIME} push ${IMG}
.PHONY: regenerate-pki
regenerate-pki:
REGENERATE_PKI=1 $(GO) test ./control-plane-pki-operator/...
REGENERATE_PKI=1 $(GO) test ./test/e2e/... -run TestRegeneratePKI
.PHONY: hypershift-install-aws-dev
hypershift-install-aws-dev:
@$(HYPERSHIFT_INSTALL_AWS)
.PHONY: run-operator-locally-aws-dev
run-operator-locally-aws-dev:
@$(RUN_OPERATOR_LOCALLY_AWS)
.PHONY: verify-codespell
verify-codespell: codespell ## Verify codespell.
@$(CODESPELL) --count --ignore-words=./.codespellignore --skip="./hack/tools/bin/codespell_dist,./vendor/*,./api/vendor/*,./hack/tools/vendor/*,./api/hypershift/v1alpha1/*,./support/thirdparty/*,./docs/content/reference/*,./hack/tools/bin/*,./cmd/install/assets/*,./go.sum,./hack/workspace/go.work.sum,./api/hypershift/v1beta1/zz_generated.featuregated-crd-manifests"
## --------------------------------------
## Tooling Binaries
## --------------------------------------
##@ Tooling Binaries:
codespell : $(CODESPELL) ## Build a local copy of codespell.
$(CODESPELL): ## Build codespell from tools folder.
mkdir -p $(TOOLS_BIN_DIR); \
mkdir -p $(TOOLS_BIN_DIR)/$(CODESPELL_DIST_DIR); \
mkdir -p $(TOOLS_BIN_DIR)/$(CODESPELL_DIST_DIR)/bin; \
mkdir -p $(TOOLS_BIN_DIR)/$(CODESPELL_DIST_DIR); \
pip install --target=$(TOOLS_BIN_DIR)/$(CODESPELL_DIST_DIR) $(CODESPELL_BIN)==$(CODESPELL_VER) --upgrade; \
mv $(TOOLS_BIN_DIR)/$(CODESPELL_DIST_DIR)/bin/$(CODESPELL_BIN) $(TOOLS_BIN_DIR)/$(CODESPELL_DIST_DIR); \
rm -r $(TOOLS_BIN_DIR)/$(CODESPELL_DIST_DIR)/bin;