-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathMakefile
215 lines (173 loc) · 10.1 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
# Image URL to use all building/pushing image targets
CONTROLLER_IMG ?= kube-egress-gateway-controller
DAEMON_IMG ?= kube-egress-gateway-daemon
CNIMANAGER_IMG ?= kube-egress-gateway-cnimanager
CNI_IMG ?= kube-egress-gateway-cni
CNI_IPAM_IMG ?= kube-egress-gateway-cni-ipam
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.25.0
# 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
# Setting SHELL to bash allows bash commands to be executed by recipes.
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec
.PHONY: all
all: build
##@ General
# The help target prints out all targets with their descriptions organized
# beneath their categories. The categories are represented by '##@' and the
# target descriptions by '##'. The awk commands is responsible for reading the
# entire set of makefiles included in this invocation, looking for lines of the
# file as xyz: ## something, and then pretty-format the target and help. Then,
# if there's a line with ##@ something, that gets pretty-printed as a category.
# More info on the usage of ANSI control characters for terminal formatting:
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
# More info on the awk command:
# http://linuxcommand.org/lc3_adv_awk.php
.PHONY: help
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
##@ Development
.PHONY: manifests
manifests: controller-gen daemon-rbac-manifests manager-rbac-manifests cnimanager-rbac-manifests ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
$(CONTROLLER_GEN) crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases output:webhook:artifacts:config=config/manager/webhook
daemon-rbac-manifests: controller-gen ## Generate RBAC manifests for daemon.
$(CONTROLLER_GEN) rbac:roleName=manager-role paths="./controllers/manager/..." output:rbac:artifacts:config=config/manager/rbac
manager-rbac-manifests: controller-gen ## Generate RBAC manifests for manager.
$(CONTROLLER_GEN) rbac:roleName=daemon-manager-role paths="./controllers/daemon/..." output:rbac:artifacts:config=config/daemon/rbac
cnimanager-rbac-manifests: controller-gen
$(CONTROLLER_GEN) rbac:roleName=cni-manager-role paths="./controllers/cnimanager/..." output:rbac:artifacts:config=config/cnimanager/rbac
.PHONY: generate
generate: generate-apiutils generate-protogo
generate-apiutils: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
generate-protogo: install-dependencies ## Generate code containing golang protobuf implementation.
$(LOCALBIN)/buf generate
$(LOCALBIN)/buf lint
.PHONY: fmt
fmt: goimports ## Run go fmt against code.
${GOIMPORTS} -local github.com/Azure/kube-egress-gateway -w .
.PHONY: vet
vet: golangci-lint ## Run go vet against code.
$(LOCALBIN)/golangci-lint run --timeout 10m ./...
.PHONY: unit-test
unit-test: manifests generate fmt vet envtest ## Run unit tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" ./hack/test_linux.sh
.PHONY: e2e-test
e2e-test: manifests generate fmt vet envtest ## Run e2e tests.
./hack/run_e2e.sh
##@ Build
IMAGE_REGISTRY ?= local
IMAGE_TAG ?= $(shell git rev-parse --short=7 HEAD)
PLATFORMS ?= linux/amd64
PLATFORMS_MULTI_ARCH ?= linux/amd64,linux/arm64,linux/arm
OUTPUT_TYPE ?= registry
.PHONY: build
build: generate fmt vet ## Build manager binary.
CGO_ENABLED=0 go build -o bin/manager ./cmd/kube-egress-gateway-controller/main.go
CGO_ENABLED=0 go build -o bin/daemon ./cmd/kube-egress-gateway-daemon/main.go
CGO_ENABLED=0 go build -o bin/cni ./cmd/kube-egress-cni/main.go
CGO_ENABLED=0 go build -o bin/cni-ipam ./cmd/kube-egress-cni-ipam/main.go
CGO_ENABLED=0 go build -o bin/cnimanager ./cmd/kube-egress-gateway-cnimanager/main.go
AZURE_CONFIG_FILE ?= ./tests/deploy/azure.json
.PHONY: run
run: manifests generate fmt vet ## Run a controller from your host.
go run ./cmd/kube-egress-gateway-controller/main.go --zap-log-level 5 --cloud-config $(AZURE_CONFIG_FILE)
.PHONY: docker-build
docker-build: docker-builder-setup ## Build docker image with the manager.
TAG=$(IMAGE_TAG) IMAGE_REGISTRY=$(IMAGE_REGISTRY) PLATFORMS=$(PLATFORMS) docker buildx bake -f docker/docker-bake.hcl -f docker/docker-localtag-bake.hcl --progress auto --set=*.output=type=$(OUTPUT_TYPE)
.PHONY: docker-build-multi-arch
docker-build-multi-arch: docker-builder-setup ## Build docker image with the manager.
TAG=$(IMAGE_TAG) IMAGE_REGISTRY=$(IMAGE_REGISTRY) PLATFORMS=$(PLATFORMS_MULTI_ARCH) docker buildx bake -f docker/docker-bake.hcl -f docker/docker-localtag-bake.hcl --progress auto --set=*.output=type=$(OUTPUT_TYPE)
.PHONY: docker-builder-setup
docker-builder-setup:
ifndef E2E_PIPELINE
docker run --privileged --rm tonistiigi/binfmt --install all
endif
##@ Deployment
ifndef ignore-not-found
ignore-not-found = false
endif
## Set environment variable EXCEPTION_CIDRS="<pod cidr>,<service cidr>" to exclude traffic from gateway
.PHONY: install
install: manifests kustomize docker-build ## Install CRDs into the K8s cluster specified in ~/.kube/config.
cd config/default && \
$(KUSTOMIZE) edit set image controller=$(IMAGE_REGISTRY)/$(CONTROLLER_IMG):$(IMAGE_TAG) && \
$(KUSTOMIZE) edit set image daemon=$(IMAGE_REGISTRY)/${DAEMON_IMG}:$(IMAGE_TAG) && \
$(KUSTOMIZE) edit set image cnimanager=$(IMAGE_REGISTRY)/${CNIMANAGER_IMG}:$(IMAGE_TAG) && \
$(KUSTOMIZE) edit set image cni=$(IMAGE_REGISTRY)/${CNI_IMG}:$(IMAGE_TAG) && \
$(KUSTOMIZE) edit set image cni-ipam=$(IMAGE_REGISTRY)/${CNI_IPAM_IMG}:$(IMAGE_TAG)
$(KUSTOMIZE) build config/default | kubectl apply -f -
.PHONY: uninstall
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
$(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
##@ Build Dependencies
.PHONY: install-dependencies
install-dependencies: kustomize controller-gen envtest cobra-cli kubebuilder golangci-lint protoc-gen-go protoc-gen-go-grpc protoc buf goimports ## Install all build dependencies.
export PATH=$$PATH:$(LOCALBIN)
## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)
GOIMPORTS ?= $(LOCALBIN)/goimports
.PHONY: goimports
goimports: $(GOIMPORTS) ## Download goimports locally if necessary.
$(GOIMPORTS): $(LOCALBIN)
test -s $(LOCALBIN)/goimports || GOBIN=$(LOCALBIN) go install golang.org/x/tools/cmd/goimports@latest
KUSTOMIZE ?= $(LOCALBIN)/kustomize
KUSTOMIZE_VERSION ?= latest
KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
.PHONY: kustomize
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
$(KUSTOMIZE): $(LOCALBIN)
test -s $(LOCALBIN)/kustomize || { curl -s $(KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $(LOCALBIN); }
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
.PHONY: controller-gen
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
$(CONTROLLER_GEN): $(LOCALBIN)
test -s $(LOCALBIN)/controller-gen || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@latest
ENVTEST ?= $(LOCALBIN)/setup-envtest
.PHONY: envtest
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
$(ENVTEST): $(LOCALBIN)
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
COBRA_CLI ?=$(LOCALBIN)/cobra-CLI
.PHONY: cobra-cli
cobra-cli: $(COBRA_CLI) ## Download cobra cli locally if necessary.
${COBRA_CLI}: $(LOCALBIN)
test -s $(LOCALBIN)/cobra-cli || GOBIN=$(LOCALBIN) go install github.com/spf13/cobra-cli@latest
KUBEBUILDER ?= $(LOCALBIN)/kubebuilder
.PHONY: kubebuilder
kubebuilder: $(KUBEBUILDER) ## Download kubebuilder locally if necessary.
$(KUBEBUILDER): $(LOCALBIN)
test -s $(LOCALBIN)/kubebuilder || { curl -L -o $(LOCALBIN)/kubebuilder https://go.kubebuilder.io/dl/latest/`go env GOOS`/`go env GOARCH` && chmod a+x $(LOCALBIN)/kubebuilder ;}
GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint
.PHONY: golangci-lint
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
$(GOLANGCI_LINT): $(LOCALBIN)
test -s $(LOCALBIN)/golangci-lint || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(LOCALBIN) latest
PROTOC_GEN_GO ?= $(LOCALBIN)/protoc-gen-go
.PHONY: protoc-gen-go
protoc-gen-go: $(PROTOC_GEN_GO) ## Download protoc-gen-go locally if necessary.
$(PROTOC_GEN_GO): $(LOCALBIN)
test -s $(LOCALBIN)/protoc-gen-go || GOBIN=$(LOCALBIN) go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
PROTOC_GEN_GO_GRPC ?= $(LOCALBIN)/protoc-gen-go-grpc
.PHONY: protoc-gen-go-grpc
protoc-gen-go-grpc: $(PROTOC_GEN_GO_GRPC) ## Download protoc-gen-go-grpc locally if necessary.
$(PROTOC_GEN_GO_GRPC): $(LOCALBIN) $(PROTOC)
test -s $(LOCALBIN)/protoc-gen-go-grpc || GOBIN=$(LOCALBIN) go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
PROTOC ?= $(LOCALBIN)/protoc
.PHONY: protoc
protoc: $(PROTOC) ## Download protoc locally if necessary.
$(PROTOC): $(LOCALBIN)
test -s $(LOCALBIN)/protoc || { curl -L -o $(LOCALBIN)/protoc.zip https://github.com/protocolbuffers/protobuf/releases/download/v23.1/protoc-23.1-linux-x86_64.zip && unzip $(LOCALBIN)/protoc.zip -d $(LOCALBIN) && mv $(LOCALBIN)/bin/protoc $(LOCALBIN) && rm -rf $(LOCALBIN)/protoc.zip $(LOCALBIN)/readme.txt $(LOCALBIN)/bin $(LOCALBIN)/include; }
BUF ?= $(LOCALBIN)/buf
.PHONY: buf
buf: $(BUF) ## Download buf locally if necessary.
$(BUF): $(LOCALBIN)
test -s $(LOCALBIN)/buf || GOBIN=$(LOCALBIN) go install github.com/bufbuild/buf/cmd/buf@latest