-
Notifications
You must be signed in to change notification settings - Fork 743
Expand file tree
/
Copy pathMakefile
More file actions
275 lines (222 loc) · 8.95 KB
/
Copy pathMakefile
File metadata and controls
275 lines (222 loc) · 8.95 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
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
# Copyright 2019 The Kubernetes 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.
# We need all the Make variables exported as env vars.
# Note that the ?= operator works regardless.
# Enable Go modules.
export GO111MODULE=on
# The registry to push container images to.
export REGISTRY ?= us-central1-docker.pkg.dev/k8s-staging-images/gateway-api
# These are overridden by cloudbuild.yaml when run by Prow.
# Prow gives this a value of the form vYYYYMMDD-hash.
# (It's similar to `git describe` output, and for non-tag
# builds will give vYYYYMMDD-COMMITS-HASH where COMMITS is the
# number of commits since the last tag.)
export GIT_TAG ?= dev
# Prow gives this the reference it's called on.
# The test-infra config job only allows our cloudbuild to
# be called on `main` and semver tags, so this will be
# set to one of those things.
export BASE_REF ?= main
# The commit hash of the current checkout
# Used to pass a binary version for main,
# overridden to semver for tagged versions.
# Cloudbuild will set this in the environment to the
# commit SHA, since the Prow does not seem to check out
# a git repo.
export COMMIT ?= $(shell git rev-parse --short HEAD)
DOCKER ?= docker
# TOP is the current directory where this Makefile lives.
TOP := $(dir $(firstword $(MAKEFILE_LIST)))
# ROOT is the root of the documentation tree.
ROOT := $(abspath $(TOP))
# Command-line flags passed to "go test" for the conformance
# test. These are passed after the "-args" flag.
CONFORMANCE_FLAGS ?=
GO_TEST_FLAGS ?=
# Flags for CRD validation tests
CEL_TEST_K8S_VERSION ?=
CEL_TEST_CRD_CHANNEL ?= standard
# Flags for docs validation
# Use this to add extra flags like --offline or --include "github.com/kubernetes"
# Github is intentionally removed from the checks due to rate limits and because the
# anchor validation does not work when pointing to a github code
VALIDATE_DOCS_EXTRA_FLAGS ?=
# Compilation flags for binaries
GOARCH ?= $(shell go env GOARCH)
GOOS ?= $(shell go env GOOS)
all: generate vet fmt verify test conformance-bin
.PHONY: clean-generated
clean-generated:
rm -rf pkg/client/clientset
rm -rf pkg/client/listers
rm -rf pkg/client/informers
# Run generators for protos, Deepcopy funcs, CRDs, and docs.
.PHONY: generate
generate: clean-generated update-codegen tidy
.PHONY: update-codegen
update-codegen:
hack/update-codegen.sh
.PHONY: build-install-yaml
build-install-yaml:
hack/build-install-yaml.sh
.PHONY: build-monthly-yaml
build-monthly-yaml:
hack/build-monthly-yaml.sh
# Run go fmt against code
fmt:
go fmt ./...
# Run go vet against code
vet:
go vet ./...
# Run go test against code
test:
go test -race -cover ./apis/... ./conformance/utils/...
# Run tests for each submodule.
cd "conformance/echo-basic" && go test -race -cover ./...
.PHONY: tidy
tidy:
go work sync
find . -name go.mod -not -path "./site/*" -exec sh -c 'cd "$$(dirname "{}")" && go mod tidy' \;
# Run tests for CRDs validation
.PHONY: test.crds-validation
test.crds-validation:
K8S_VERSION=$(CEL_TEST_K8S_VERSION) CRD_CHANNEL=$(CEL_TEST_CRD_CHANNEL) go test ${GO_TEST_FLAGS} -count=1 -timeout=120s --tags=$(CEL_TEST_CRD_CHANNEL) -v ./tests/cel
K8S_VERSION=$(CEL_TEST_K8S_VERSION) CRD_CHANNEL=$(CEL_TEST_CRD_CHANNEL) go test ${GO_TEST_FLAGS} -count=1 -timeout=120s -v ./tests/crd
K8S_VERSION=$(CEL_TEST_K8S_VERSION) CRD_CHANNEL=$(CEL_TEST_CRD_CHANNEL) go test ${GO_TEST_FLAGS} -count=1 -timeout=120s -v ./tests/vap
# Run conformance tests against controller implementation
.PHONY: conformance
conformance:
go test ${GO_TEST_FLAGS} -v ./conformance -run TestConformance -args ${CONFORMANCE_FLAGS}
# Build a conformance.test binary that can be used as a standalone binary to run conformance test
.PHONY: conformance-bin
conformance-bin:
GOOS=$(GOOS) GOARCH=$(GOARCH) go test -c -v ./conformance
# Install CRD's and example resources to a preexisting cluster.
.PHONY: install
install: crd example
# Install the CRD's to a preexisting cluster.
.PHONY: crd
crd:
kubectl kustomize config/crd | kubectl apply -f -
# Install the example resources to a preexisting cluster.
.PHONY: example
example:
hack/install-examples.sh
# Remove installed CRD's and CR's.
.PHONY: uninstall
uninstall:
hack/delete-crds.sh
# Run static analysis.
.PHONY: verify
verify:
hack/verify-all.sh -v
.PHONY: update-conformance-image-refs
update-conformance-image-refs:
hack/update-conformance-image-refs.sh
# Verify if support Docker Buildx.
.PHONY: image.buildx.verify
image.buildx.verify:
docker version
$(eval PASS := $(shell docker buildx --help | grep "docker buildx" ))
@if [ -z "$(PASS)" ]; then \
echo "Cannot find docker buildx, please install first."; \
exit 1;\
else \
echo "===========> Support docker buildx"; \
docker buildx version; \
fi
export BUILDX_CONTEXT = gateway-api-builder
export BUILDX_PLATFORMS = linux/amd64,linux/arm64
# Setup multi-arch docker buildx environment.
.PHONY: image.multiarch.setup
image.multiarch.setup: image.buildx.verify
# Ensure qemu is in binfmt_misc.
# Docker desktop already has these in versions recent enough to have buildx,
# We only need to do this setup on linux hosts.
@if [ "$(shell uname)" == "Linux" ]; then \
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes; \
fi
# Ensure we use a builder that can leverage it, we need to recreate one.
docker buildx rm $(BUILDX_CONTEXT) || :
docker buildx create --use --name $(BUILDX_CONTEXT) --platform "${BUILDX_PLATFORMS}"
# Build and Push Multi Arch Images.
.PHONY: release-staging
release-staging: image.multiarch.setup
hack/build-and-push.sh
# Docs
PYTHON ?= $(shell if [ -x .venv/bin/python3 ]; then echo "./.venv/bin/python3"; else echo "python3"; fi)
DOCS_VERIFY_CONTAINER_IMAGE ?= registry.hub.docker.com/lycheeverse/lychee:0.23
HUGO_VERSION ?= 0.160.1
HUGO_IMAGE ?= ghcr.io/gohugoio/hugo:v$(HUGO_VERSION)
# Use Docker for Hugo by default for local development, but not on Netlify
USE_DOCKER_HUGO ?= true
ifeq ($(NETLIFY),true)
USE_DOCKER_HUGO = false
endif
ifeq ($(USE_DOCKER_HUGO),true)
HUGO = docker run --rm -u $(shell id -u):$(shell id -g) -v $(PWD):/src -w /src -e GOMODCACHE=/src/.gocache -e HUGO_CACHEDIR=/src/.hugocache $(HUGO_IMAGE)
HUGO_SERVER = docker run --rm -u $(shell id -u):$(shell id -g) -v $(PWD):/src -w /src -e GOMODCACHE=/src/.gocache -e HUGO_CACHEDIR=/src/.hugocache -p 1313:1313 $(HUGO_IMAGE) server --bind 0.0.0.0
else
HUGO = hugo
HUGO_SERVER = hugo server
endif
# Build the documentation.
.PHONY: install-deps
install-deps:
cd site && npm install
if [ ! -d .venv ]; then python3 -m venv .venv; fi
.venv/bin/pip install --index-url https://pypi.org/simple pandas PyYAML semver python-frontmatter tabulate
.PHONY: docs
docs: install-deps
hack/docsy/generate.sh
$(HUGO) --source site
.PHONY: build-docs
build-docs: install-deps update-geps api-ref-docs wizard-wasm wizard-data conformance-data
$(HUGO) --source site
.PHONY: verify-docs
verify-docs: build-docs
docker run --init --rm -w /input -v ${PWD}:/input $(DOCS_VERIFY_CONTAINER_IMAGE) --root-dir /input/site/public --include "sigs.k8s.io" --accept 200 --max-concurrency 10 --include-fragments --cache $(VALIDATE_DOCS_EXTRA_FLAGS) /input/site/public/**/*.html
.PHONY: build-docs-netlify
build-docs-netlify: install-deps update-geps api-ref-docs wizard-wasm wizard-data conformance-data
$(HUGO) --source site
.PHONY: live-docs
live-docs: update-geps api-ref-docs
$(HUGO_SERVER) --source site
.PHONY: update-geps
update-geps:
hack/update-geps.sh
.PHONY: api-ref-docs
api-ref-docs:
hack/docsy/generate.sh
.PHONY: wizard-wasm
wizard-wasm:
@mkdir -p site/static/wizard
@GOROOT=$$(go env GOROOT); \
if [ -f "$$GOROOT/misc/wasm/wasm_exec.js" ]; then cp -f "$$GOROOT/misc/wasm/wasm_exec.js" site/static/wizard/; \
elif [ -f "$$GOROOT/lib/wasm/wasm_exec.js" ]; then cp -f "$$GOROOT/lib/wasm/wasm_exec.js" site/static/wizard/; \
else echo "ERROR: wasm_exec.js not found in GOROOT"; exit 1; fi
GOOS=js GOARCH=wasm go build -o site/static/wizard/main.wasm ./wasm/
# Generate controller wizard data (multi-version). Requires conformance/reports/ with version dirs.
# Run manually if make serve is used without conformance reports.
.PHONY: wizard-data
wizard-data:
@mkdir -p site/static/wizard/data
$(PYTHON) hack/generate-controller-wizard-data.py --all -o site/static/wizard/data/controller-wizard-data.json
.PHONY: conformance-data
conformance-data:
$(PYTHON) hack/docsy-generate-conformance.py
.PHONY: serve
serve: wizard-wasm update-geps api-ref-docs
@echo "Tip: Run 'make wizard-data' first if you have conformance/reports/ to load implementation data."
$(HUGO_SERVER) --source site