forked from openshift/hypershift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
257 lines (206 loc) · 9.87 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
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 GOWORK=off 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
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.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: 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
$(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: 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 cluster-api-provider-openstack 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
$(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
.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
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 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
# 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)