...
1# Copyright 2019 The Kubernetes Authors.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15# We need all the Make variables exported as env vars.
16# Note that the ?= operator works regardless.
17
18# Enable Go modules.
19export GO111MODULE=on
20
21# The registry to push container images to.
22export REGISTRY ?= gcr.io/k8s-staging-gateway-api
23
24# These are overridden by cloudbuild.yaml when run by Prow.
25
26# Prow gives this a value of the form vYYYYMMDD-hash.
27# (It's similar to `git describe` output, and for non-tag
28# builds will give vYYYYMMDD-COMMITS-HASH where COMMITS is the
29# number of commits since the last tag.)
30export GIT_TAG ?= dev
31
32# Prow gives this the reference it's called on.
33# The test-infra config job only allows our cloudbuild to
34# be called on `main` and semver tags, so this will be
35# set to one of those things.
36export BASE_REF ?= main
37
38# The commit hash of the current checkout
39# Used to pass a binary version for main,
40# overridden to semver for tagged versions.
41# Cloudbuild will set this in the environment to the
42# commit SHA, since the Prow does not seem to check out
43# a git repo.
44export COMMIT ?= $(shell git rev-parse --short HEAD)
45
46DOCKER ?= docker
47# TOP is the current directory where this Makefile lives.
48TOP := $(dir $(firstword $(MAKEFILE_LIST)))
49# ROOT is the root of the mkdocs tree.
50ROOT := $(abspath $(TOP))
51
52# Command-line flags passed to "go test" for the conformance
53# test. These are passed after the "-args" flag.
54CONFORMANCE_FLAGS ?=
55GO_TEST_FLAGS ?=
56
57all: generate vet fmt verify test
58
59# Run generators for protos, Deepcopy funcs, CRDs, and docs.
60.PHONY: generate
61generate: update-codegen update-webhook-yaml
62
63.PHONY: update-codegen
64update-codegen:
65 hack/update-codegen.sh
66
67.PHONY: update-webhook-yaml
68update-webhook-yaml:
69 hack/update-webhook-yaml.sh
70
71.PHONY: build-install-yaml
72build-install-yaml:
73 hack/build-install-yaml.sh
74
75# Run go fmt against code
76fmt:
77 go fmt ./...
78
79# Run go vet against code
80vet:
81 go vet ./...
82
83# Run go test against code
84test:
85 go test -race -cover ./pkg/admission/... ./apis/... ./conformance/utils/...
86# Run tests for each submodule.
87 cd "conformance/echo-basic" && go test -race -cover ./...
88 cd "gwctl" && go test -race -cover ./...
89
90# Run conformance tests against controller implementation
91.PHONY: conformance
92conformance:
93 go test ${GO_TEST_FLAGS} -v ./conformance -run TestConformance -args ${CONFORMANCE_FLAGS}
94
95# Run experimental conformance tests against controller implementation
96.PHONY: conformance.experimental
97conformance.experimental:
98 go test ${GO_TEST_FLAGS} -v ./conformance -run TestExperimentalConformance -args ${CONFORMANCE_FLAGS}
99
100# Install CRD's and example resources to a pre-existing cluster.
101.PHONY: install
102install: crd example
103
104# Install the CRD's to a pre-existing cluster.
105.PHONY: crd
106crd:
107 kubectl kustomize config/crd | kubectl apply -f -
108
109# Install the example resources to a pre-existing cluster.
110.PHONY: example
111example:
112 hack/install-examples.sh
113
114# Remove installed CRD's and CR's.
115.PHONY: uninstall
116uninstall:
117 hack/delete-crds.sh
118
119# Run static analysis.
120.PHONY: verify
121verify:
122 hack/verify-all.sh -v
123
124# Build the documentation.
125.PHONY: docs
126docs:
127 hack/make-docs.sh
128
129.PHONY: update-conformance-image-refs
130update-conformance-image-refs:
131 hack/update-conformance-image-refs.sh
132
133# Verify if support Docker Buildx.
134.PHONY: image.buildx.verify
135image.buildx.verify:
136 docker version
137 $(eval PASS := $(shell docker buildx --help | grep "docker buildx" ))
138 @if [ -z "$(PASS)" ]; then \
139 echo "Cannot find docker buildx, please install first."; \
140 exit 1;\
141 else \
142 echo "===========> Support docker buildx"; \
143 docker buildx version; \
144 fi
145
146export BUILDX_CONTEXT = gateway-api-builder
147export BUILDX_PLATFORMS = linux/amd64,linux/arm64
148
149# Setup multi-arch docker buildx environment.
150.PHONY: image.multiarch.setup
151image.multiarch.setup: image.buildx.verify
152# Ensure qemu is in binfmt_misc.
153# Docker desktop already has these in versions recent enough to have buildx,
154# We only need to do this setup on linux hosts.
155 @if [ "$(shell uname)" == "Linux" ]; then \
156 docker run --rm --privileged multiarch/qemu-user-static --reset -p yes; \
157 fi
158# Ensure we use a builder that can leverage it, we need to recreate one.
159 docker buildx rm $(BUILDX_CONTEXT) || :
160 docker buildx create --use --name $(BUILDX_CONTEXT) --platform "${BUILDX_PLATFORMS}"
161
162# Build and Push Multi Arch Images.
163.PHONY: release-staging
164release-staging: image.multiarch.setup
165 hack/build-and-push.sh
166
167# Generate a virtualenv install, which is useful for hacking on the
168# docs since it installs mkdocs and all the right dependencies.
169#
170# On Ubuntu, this requires the python3-venv package.
171virtualenv: .venv
172.venv: requirements.txt
173 @echo Creating a virtualenv in $@"... "
174 @python3 -m venv $@ || (rm -rf $@ && exit 1)
175 @echo Installing packages in $@"... "
176 @$@/bin/python3 -m pip install -q -r requirements.txt || (rm -rf $@ && exit 1)
177 @echo To enter the virtualenv type \"source $@/bin/activate\", to exit type \"deactivate\"
View as plain text