This repository has been archived by the owner on Feb 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
/
Makefile
219 lines (178 loc) · 7.21 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
# Sets GIT_REF to a tag if it's present, otherwise the short git sha will be used.
GIT_REF = $(shell git describe --tags --exact-match 2>/dev/null || git rev-parse --short=8 --verify HEAD)
VERSION ?= $(GIT_REF)
# Used as an argument to prepare a tagged release of the operator.
OLD_VERSION ?= main
NEW_VERSION ?= $(OLD_VERSION)
# Used for syncing Gateway API CRDs
GATEWAY_API_VERSION = $(shell grep "sigs.k8s.io/gateway-api" go.mod | awk '{print $$2}')
# Used as a go test argument for running e2e tests.
TEST ?= .*
# Image URL to use all building/pushing image targets
REGISTRY ?= ghcr.io/projectcontour
IMAGE := ${REGISTRY}/contour-operator
# Need v1 to support defaults in CRDs, unfortunately limiting us to k8s 1.16+
CRD_OPTIONS ?= "crd:crdVersions=v1"
# 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
CONTROLLER_GEN := go run sigs.k8s.io/controller-tools/cmd/controller-gen
# Platforms to build the multi-arch image for.
IMAGE_PLATFORMS ?= linux/amd64,linux/arm64
# Stash the ISO 8601 date. Note that the GMT offset is missing the :
# separator, but there doesn't seem to be a way to do that without
# depending on GNU date.
ISO_8601_DATE = $(shell TZ=GMT date '+%Y-%m-%dT%R:%S%z')
# Sets the current Git sha.
BUILD_SHA = $(shell git rev-parse --verify HEAD)
# Sets the current branch. If we are on a detached header, filter it out so the
# branch will be empty. This is similar to --show-current.
BUILD_BRANCH = $(shell git branch | grep -v detached | awk '$$1=="*"{print $$2}')
# Sets the current tagged git version.
BUILD_VERSION = $(VERSION)
# Docker labels to be applied to the contour-operator image. We don't transform
# this with make because it's not worth pulling the tricks needed to handle
# the embedded whitespace.
#
# See https://github.com/opencontainers/image-spec/blob/master/annotations.md
DOCKER_BUILD_LABELS = \
--label "org.opencontainers.image.created=${ISO_8601_DATE}" \
--label "org.opencontainers.image.url=https://github.com/projectcontour/contour-operator/" \
--label "org.opencontainers.image.documentation=https://github.com/projectcontour/contour-operator/" \
--label "org.opencontainers.image.source=https://github.com/projectcontour/contour-operator/archive/${BUILD_VERSION}.tar.gz" \
--label "org.opencontainers.image.version=${BUILD_VERSION}" \
--label "org.opencontainers.image.revision=${BUILD_SHA}" \
--label "org.opencontainers.image.vendor=Project Contour" \
--label "org.opencontainers.image.licenses=Apache-2.0" \
--label "org.opencontainers.image.title=contour-operator" \
--label "org.opencontainers.image.description=Deploy and manage Contour using an operator."
TAG_LATEST ?= false
ifeq ($(TAG_LATEST), true)
IMAGE_TAGS = \
--tag $(IMAGE):$(VERSION) \
--tag $(IMAGE):latest
else
IMAGE_TAGS = \
--tag $(IMAGE):$(VERSION)
endif
all: manager
# Run tests & validate against linters
.PHONY: check
check: test lint-golint lint-codespell
# Run tests
test: generate fmt vet manifests
go test \
-race \
-mod=readonly \
-covermode=atomic \
-coverprofile coverage.out \
-coverpkg=./cmd/...,./internal/...,./pkg/... \
./...
lint-golint:
@echo Running Go linter ...
@./hack/golangci-lint.sh run --build-tags=e2e,tools
.PHONY: lint-codespell
lint-codespell: CODESPELL_SKIP := $(shell cat .codespell.skip | tr \\n ',')
lint-codespell:
@echo Running Codespell ...
@./hack/codespell.sh --skip $(CODESPELL_SKIP) --ignore-words .codespell.ignorewords --check-filenames --check-hidden -q2
# Build manager binary
manager: generate fmt vet
go build -mod=readonly -o bin/contour-operator cmd/contour-operator.go
# Run against the configured Kubernetes cluster in ~/.kube/config
run: generate fmt vet manifests install
go run ./cmd/contour-operator.go
# Install CRDs into a cluster
install: manifests
kustomize build config/crd | kubectl apply -f -
# Uninstall CRDs from a cluster
uninstall: manifests
kustomize build config/crd | kubectl delete -f -
deploy: ## Deploy the operator to a Kubernetes cluster. This assumes a kubeconfig in ~/.kube/config
deploy: manifests
cd config/manager
kustomize build config/default | kubectl apply -f -
load-image: ## Load the operator image to a kind cluster
load-image: container
./hack/load-image.sh $(IMAGE) $(VERSION)
# Remove the operator deployment. This assumes a kubeconfig in ~/.kube/config
undeploy:
cd config/manager
kustomize build config/default | kubectl delete -f -
example: ## Generate the example operator manifest.
example:
cd config/manager
kustomize build config/default > examples/operator/operator.yaml
test-example: ## Test the example Contour.
.PHONY: test-example
test-example:
go test -mod=readonly -timeout 20m -count 1 -v -tags e2e -run "$(TEST)" ./test/e2e/example
verify-image: ## Verifies operator image references and pull policy.
.PHONY: verify-image
verify-image:
./hack/verify-image.sh $(NEW_VERSION)
reset-image: ## Resets operator image references and pull policy.
.PHONY: reset-image
reset-image:
./hack/reset-image.sh $(IMAGE) $(OLD_VERSION)
# Generate Contour's rendered CRD manifest (i.e. HTTPProxy).
# Remove when https://github.com/projectcontour/contour-operator/issues/42 is fixed.
.PHONY: generate-contour-crds
generate-contour-crds:
@./hack/generate-contour-crds.sh $(NEW_VERSION)
.PHONY: generate-gateway-crds
generate-gateway-crds:
@echo "Generating Gateway API CRD YAML documents..."
@kubectl kustomize "github.com/kubernetes-sigs/gateway-api/config/crd/experimental?ref=${GATEWAY_API_VERSION}" > config/crd/gateway/01-crds.yaml
manifests: ## Generate manifests e.g. CRD, RBAC etc.
manifests: generate-contour-crds generate-gateway-crds
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=contour-operator webhook paths="./..." output:crd:artifacts:config=config/crd/bases
# Run go fmt against code
fmt:
go fmt ./...
go fmt ./test/e2e/
# Run go vet against code
vet:
go vet ./...
# Generate code
generate:
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
multiarch-build-push: ## Build and push a multi-arch contour-operator container image to the Docker registry
docker buildx build \
--platform $(IMAGE_PLATFORMS) \
--build-arg "BUILD_VERSION=$(BUILD_VERSION)" \
--build-arg "BUILD_BRANCH=$(BUILD_BRANCH)" \
--build-arg "BUILD_SHA=$(BUILD_SHA)" \
$(DOCKER_BUILD_LABELS) \
$(IMAGE_TAGS) \
--push \
.
container: ## Build the contour-operator container image
container:
docker build \
--build-arg "BUILD_VERSION=$(BUILD_VERSION)" \
--build-arg "BUILD_BRANCH=$(BUILD_BRANCH)" \
--build-arg "BUILD_SHA=$(BUILD_SHA)" \
$(DOCKER_BUILD_LABELS) \
$(shell pwd) \
--tag $(IMAGE):$(VERSION)
push: ## Push the contour-operator container image to the Docker registry
push: container
docker push $(IMAGE):$(VERSION)
ifeq ($(TAG_LATEST), true)
docker tag $(IMAGE):$(VERSION) $(IMAGE):latest
docker push $(IMAGE):latest
endif
local-cluster: # Create a local kind cluster
./hack/kind-dev-cluster.sh
release: ## Prepares a tagged release of the operator.
.PHONY: release
release:
./hack/release/make-release-tag.sh $(OLD_VERSION) $(NEW_VERSION)
test-e2e: ## Runs e2e tests.
.PHONY: test-e2e
test-e2e: deploy
go test -mod=readonly -timeout 20m -count 1 -v -tags e2e -run "$(TEST)" ./test/e2e