-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMakefile
More file actions
226 lines (198 loc) · 9 KB
/
Makefile
File metadata and controls
226 lines (198 loc) · 9 KB
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
SHELL = bash
.SHELLFLAGS = -ec -o pipefail
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
TOOLS_VERSIONS_FILE = $(PROJECT_DIR)/.tools_versions.yaml
MISE := $(shell which mise)
MISE_FILE := .mise/config.toml
.PHONY: mise
mise:
@mise -V >/dev/null || (echo "mise - https://github.com/jdx/mise - not found. Please install it." && exit 1)
.PHONY: mise-install
mise-install: mise
@$(MISE) install -q $(DEP_VER)
OS := $(shell uname | tr '[:upper:]' '[:lower:]')
ARCH := $(shell uname -m | sed 's/x86_64/amd64/' | sed 's/aarch64/arm64/')
# Do not store yq's version in .tools_versions.yaml as it is used to get tool versions.
# renovate: datasource=github-releases depName=mikefarah/yq
YQ_VERSION = 4.49.2
YQ = $(PROJECT_DIR)/bin/installs/github-mikefarah-yq/$(YQ_VERSION)/yq_$(OS)_$(ARCH)
.PHONY: yq
yq: mise
MISE_DATA_DIR=$(PROJECT_DIR)/bin $(MAKE) mise-install DEP_VER=github:mikefarah/yq@$(YQ_VERSION)
CONTROLLER_GEN_VERSION = $(shell $(YQ) -r '.controller-tools' < $(TOOLS_VERSIONS_FILE))
CONTROLLER_GEN = $(PROJECT_DIR)/bin/installs/github-kubernetes-sigs-controller-tools/$(CONTROLLER_GEN_VERSION)/controller-gen
.PHONY: controller-gen
controller-gen: mise yq
MISE_DATA_DIR=$(PROJECT_DIR)/bin $(MAKE) mise-install DEP_VER=github:kubernetes-sigs/controller-tools@$(CONTROLLER_GEN_VERSION)
MOCKERY_VERSION = $(shell $(YQ) -r '.mockery' < $(TOOLS_VERSIONS_FILE))
MOCKERY = $(PROJECT_DIR)/bin/installs/github-vektra-mockery/$(MOCKERY_VERSION)/mockery
.PHONY: mockery
mockery: mise yq
MISE_DATA_DIR=$(PROJECT_DIR)/bin $(MAKE) mise-install DEP_VER=github:vektra/mockery@$(MOCKERY_VERSION)
IFACEMAKER_VERSION = $(shell $(YQ) -r '.ifacemaker' < $(TOOLS_VERSIONS_FILE))
IFACEMAKER = $(PROJECT_DIR)/bin/installs/go-github-com-vburenin-ifacemaker/$(IFACEMAKER_VERSION)/bin/ifacemaker
.PHONY: ifacemaker
ifacemaker: mise yq
MISE_DATA_DIR=$(PROJECT_DIR)/bin $(MAKE) mise-install DEP_VER=go:github.com/vburenin/ifacemaker@$(IFACEMAKER_VERSION)
# NOTE: speakeasy is not placed in $(PROJECT_DIR)/bin as it is being used in
# GitHub workflows outside of this Makefile.
SPEAKEASY_VERSION = $(shell $(YQ) -p toml -o yaml '.tools["github:speakeasy-api/speakeasy"].version' < $(MISE_FILE))
.PHONY: speakeasy
speakeasy: mise yq
$(MAKE) mise-install DEP_VER=github:speakeasy-api/speakeasy@$(SPEAKEASY_VERSION)
# ------------------------------------------------------------------------------
# Code generation
# ------------------------------------------------------------------------------
SED=sed
ifeq (Darwin,$(shell uname -s))
SED=gsed
endif
OPENAPI_FILE = openapi.yaml
SPEAKEASY_DIR = .speakeasy
KUBEBUILDER_GENERATE_CODE_MARKER = +kubebuilder:object:generate=true
# TODO: this works around the fact that speakeasy does not support fields that
# do not have "omitempty" set and are not required.
# Related slack thread: https://kongstrong.slack.com/archives/C05MLAA216D/p1730369303065339
.PHONY: _generate.omitempty
_generate.omitempty:
$(SED) -i 's#Members \[\]Members `json:"members,omitempty"`#Members \[\]Members `json:"members"`#g' \
models/components/groupmembership.go
.PHONY: generate.deepcopy
generate.deepcopy: controller-gen
$(SED) -i 's#\(type CreateControlPlaneRequest struct\)#// $(KUBEBUILDER_GENERATE_CODE_MARKER)\n\1#g' \
models/components/createcontrolplanerequest.go
$(SED) -i 's#\(type CreateNetworkRequest struct\)#// $(KUBEBUILDER_GENERATE_CODE_MARKER)\n\1#g' \
models/components/createnetworkrequest.go
$(SED) -i 's#\(type RouteWithoutParents struct\)#// $(KUBEBUILDER_GENERATE_CODE_MARKER)\n\1#g' \
models/components/routewithoutparents.go
$(SED) -i 's#\(type RouteWithoutParentsDestinations struct\)#// $(KUBEBUILDER_GENERATE_CODE_MARKER)\n\1#g' \
models/components/routewithoutparents.go
$(SED) -i 's#\(type Destinations struct\)#// $(KUBEBUILDER_GENERATE_CODE_MARKER)\n\1#g' \
models/components/route.go
$(SED) -i 's#\(type Sources struct\)#// $(KUBEBUILDER_GENERATE_CODE_MARKER)\n\1#g' \
models/components/route.go
$(SED) -i 's#\(type Route struct\)#// $(KUBEBUILDER_GENERATE_CODE_MARKER)\n\1#g' \
models/components/route.go
$(SED) -i 's#\(type RouteService struct\)#// $(KUBEBUILDER_GENERATE_CODE_MARKER)\n\1#g' \
models/components/route.go
$(SED) -i 's#\(type RouteWithoutParentsSources struct\)#// $(KUBEBUILDER_GENERATE_CODE_MARKER)\n\1#g' \
models/components/routewithoutparents.go
$(SED) -i 's#\(type RouteWithoutParentsService struct\)#// $(KUBEBUILDER_GENERATE_CODE_MARKER)\n\1#g' \
models/components/routewithoutparents.go
$(SED) -i 's#\(type RouteInput struct\)#// $(KUBEBUILDER_GENERATE_CODE_MARKER)\n\1#g' \
models/components/route.go
$(SED) -i 's#\(type Destinations struct\)#// $(KUBEBUILDER_GENERATE_CODE_MARKER)\n\1#g' \
models/components/routejson.go
$(SED) -i 's#\(type RouteJSON struct\)#// $(KUBEBUILDER_GENERATE_CODE_MARKER)\n\1#g' \
models/components/routejson.go
$(SED) -i 's#\(type RouteJSONService struct\)#// $(KUBEBUILDER_GENERATE_CODE_MARKER)\n\1#g' \
models/components/routejson.go
$(SED) -i 's#\(type Sources struct\)#// $(KUBEBUILDER_GENERATE_CODE_MARKER)\n\1#g' \
models/components/routejson.go
$(SED) -i 's#\(type RouteExpression struct\)#// $(KUBEBUILDER_GENERATE_CODE_MARKER)\n\1#g' \
models/components/routeexpression.go
$(SED) -i 's#\(type RouteExpressionService struct\)#// $(KUBEBUILDER_GENERATE_CODE_MARKER)\n\1#g' \
models/components/routeexpression.go
$(SED) -i 's#\(type UpstreamClientCertificate struct\)#// $(KUBEBUILDER_GENERATE_CODE_MARKER)\n\1#g' \
models/components/upstream.go
$(SED) -i 's#\(type Healthchecks struct\)#// $(KUBEBUILDER_GENERATE_CODE_MARKER)\n\1#g' \
models/components/upstream.go
$(SED) -i 's#\(type Active struct\)#// $(KUBEBUILDER_GENERATE_CODE_MARKER)\n\1#g' \
models/components/upstream.go
$(SED) -i 's#\(type Passive struct\)#// $(KUBEBUILDER_GENERATE_CODE_MARKER)\n\1#g' \
models/components/upstream.go
$(SED) -i 's#\(type UpstreamHealthy struct\)#// $(KUBEBUILDER_GENERATE_CODE_MARKER)\n\1#g' \
models/components/upstream.go
$(SED) -i 's#\(type Healthy struct\)#// $(KUBEBUILDER_GENERATE_CODE_MARKER)\n\1#g' \
models/components/upstream.go
$(SED) -i 's#\(type UpstreamUnhealthy struct\)#// $(KUBEBUILDER_GENERATE_CODE_MARKER)\n\1#g' \
models/components/upstream.go
$(SED) -i 's#\(type Unhealthy struct\)#// $(KUBEBUILDER_GENERATE_CODE_MARKER)\n\1#g' \
models/components/upstream.go
$(CONTROLLER_GEN) object paths=./models/components/
go mod tidy
# NOTE: This removes the +kubebuilder:object:generate=true markers after DeepCopy() generation.
# to prevent it from being committed to the codebase.
git checkout -- $(OPENAPI_FILE) \
$(shell git ls-files models/components/route*.go) \
$(shell git ls-files docs/models/components/route*.md) \
$(shell git ls-files models/components/create*.go) \
$(shell git ls-files docs/models/components/create*.md) \
$(shell git ls-files models/components/upstream*.go) \
$(shell git ls-files docs/models/components/upstream*.md) \
$(shell git ls-files docs/models/components/healthchecks*.md)
# NOTE: SDK generation consists of adding the kubebuilder code marker and generating
# DeepCopy() for the types that need it and then using speakeasy to generate
# the final sdk code.
# NOTE: add more types that need to have DeepCopy() generated.
.PHONY: generate.sdk
generate.sdk: speakeasy
speakeasy run --skip-versioning --skip-testing --minimal --skip-upload-spec
git add --update .
$(MAKE) generate.deepcopy
$(MAKE) _generate.omitempty
go mod tidy
.PHONY: test
test: test.unit test.integration
.PHONY: test.unit
test.unit:
go test -v -race $(GOTESTFLAGS) \
./internal/...
.PHONY: test.integration
test.integration:
KONNECT_TEST_RUN_ID=$(shell openssl rand -hex 8) \
go test -v -race $(GOTESTFLAGS) \
./test/integration/...
.PHONY: cleanup.konnect
cleanup.konnect:
go run ./ci/konnect-cleanup
.PHONY: _generate.ifacemaker
_generate.ifacemaker:
@$(eval LOWERCASE_STRUCT := $(shell echo $(STRUCT) | tr 'A-Z' 'a-z'))
$(IFACEMAKER) \
--file $(LOWERCASE_STRUCT).go \
--struct $(STRUCT) \
--iface $(STRUCT)SDK \
--iface-comment "$(STRUCT)SDK is a generated interface." \
--output $(LOWERCASE_STRUCT)_i.go \
-p sdkkonnectgo
# TODO: Update TYPES_TO_MOCK as new types are added that need mocking.
# This can be achived with:
# TYPES_TO_MOCK := $(shell grep -B 20 'rootSDK.*\*SDK' *.go | grep 'type.*struct' | awk '{print $$2}' | sort -u)
# but for now we don't want to mock everything.
TYPES_TO_MOCK := \
ACLs \
APIKeys \
BasicAuthCredentials \
CACertificates \
Certificates \
CloudGateways \
ConsumerGroups \
Consumers \
ControlPlaneGroups \
ControlPlanes \
DPCertificates \
HMACAuthCredentials \
JWTs \
Keys \
KeySets \
Me \
Plugins \
Routes \
Services \
SNIs \
Targets \
Upstreams \
Vaults \
EventGateways
.PHONY: generate.interfaces
generate.interfaces: ifacemaker
@$(foreach s, $(TYPES_TO_MOCK), \
$(MAKE) _generate.ifacemaker STRUCT=$(s);)
# https://github.com/vektra/mockery/issues/803#issuecomment-2287198024
.PHONY: generate.mocks
generate.mocks: mockery
GODEBUG=gotypesalias=0 $(MOCKERY)
.PHONY: verify.diff
verify.diff:
@$(PROJECT_DIR)/scripts/verify-diff.sh $(PROJECT_DIR)