This repository has been archived by the owner on Dec 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathMakefile
343 lines (263 loc) · 12 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
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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
export # Used to let all sub-make use the initialized value of variables whose names consist solely of alphanumerics and underscores
# Image URL to use all building/pushing image targets
PREFIX?=projects.registry.vmware.com/tanzu_observability
DOCKER_IMAGE?=kubernetes-operator-snapshot
GO_IMPORTS_BIN:=$(if $(which goimports),$(which goimports),$(GOPATH)/bin/goimports)
SEMVER_CLI_BIN:=$(if $(which semver-cli),$(which semver-cli),$(GOPATH)/bin/semver-cli)
OS := $(shell uname -s | tr A-Z a-z)
ifeq ($(OS), darwin)
DARWIN_GOLANGCI_LINT_BIN:=$(or $(shell which golangci-lint),"/usr/local/bin/golangci-lint")
else
LINUX_GOLANGCI_LINT_BIN:=$(or $(shell which golangci-lint),$(GOPATH)/bin/golangci-lint)
endif
ifeq ($(origin VERSION_POSTFIX), undefined)
VERSION_POSTFIX:=-alpha-$(shell whoami)-$(shell date +"%y%m%d%H%M%S")
endif
RELEASE_VERSION?=$(shell cat ./release/OPERATOR_VERSION)
VERSION?=$(shell semver-cli inc patch $(RELEASE_VERSION))$(VERSION_POSTFIX)
IMG?=$(PREFIX)/$(DOCKER_IMAGE):$(VERSION)
NS?=observability-system
LDFLAGS=-X main.version=$(VERSION)
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.23
REPO_DIR=$(shell git rev-parse --show-toplevel)
# 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
GOOS?=$(shell go env GOOS)
GOARCH?=$(shell go env GOARCH)
# Setting SHELL to bash allows bash commands to be executed by recipes.
# This is a requirement for 'setup-envtest.sh' in the test target.
# 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
$(GO_IMPORTS_BIN):
@(cd $(REPO_DIR)/..; CGO_ENABLED=0 go install golang.org/x/tools/cmd/goimports@latest)
.PHONY: semver-cli
semver-cli: $(SEMVER_CLI_BIN)
$(SEMVER_CLI_BIN):
@(cd $(REPO_DIR)/..; CGO_ENABLED=0 go install github.com/davidrjonas/semver-cli@latest)
.PHONY: manifests
manifests: controller-gen config/crd/bases/wavefront.com_wavefronts.yaml
config/crd/bases/wavefront.com_wavefronts.yaml: api/v1alpha1/wavefront_types.go controllers/wavefront_controller.go
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
.PHONY: generate
generate: controller-gen api/v1alpha1/zz_generated.deepcopy.go
api/v1alpha1/zz_generated.deepcopy.go: hack/boilerplate.go.txt api/v1alpha1/wavefront_types.go
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
.PHONY: fmt
fmt: $(GO_IMPORTS_BIN)
find . -type f -name "*.go" | grep -v "./vendor*" | xargs goimports -w
.PHONY: checkfmt
checkfmt: $(GO_IMPORTS_BIN)
@if [ $$(goimports -d $$(find . -type f -name '*.go' -not -path "./vendor/*") | wc -l) -gt 0 ]; then \
echo $$'\e[31mgoimports FAILED!!!\e[0m'; \
goimports -d $$(find . -type f -name '*.go' -not -path "./vendor/*"); \
exit 1; \
fi
.PHONY: vet
vet: ## Run go vet against code.
go vet ./...
.PHONY: golangci-lint
golangci-lint: $(OS)-golangci-lint
golangci-lint run
.PHONY: darwin-golangci-lint
darwin-golangci-lint: $(DARWIN_GOLANGCI_LINT_BIN)
$(DARWIN_GOLANGCI_LINT_BIN):
brew install golangci-lint
.PHONY: linux-golangci-lint
linux-golangci-lint: $(LINUX_GOLANGCI_LINT_BIN)
$(LINUX_GOLANGCI_LINT_BIN):
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sudo sh -s -- -b $(go env GOPATH)/bin v1.50.1
.PHONY: test
test: manifests generate fmt vet envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test ./... -coverprofile cover.out
##@ Build
.PHONY: build
build: generate fmt vet ## Build manager binary.
go build -ldflags "$(LDFLAGS)" -o build/$(GOOS)/$(GOARCH)/manager main.go
rm -rf build/$(GOOS)/$(GOARCH)/deploy
cp -r deploy build/$(GOOS)/$(GOARCH)
cp open_source_licenses.txt build/
.PHONY: clean
clean:
rm -rf bin
rm -rf build
.PHONY: docker-build
docker-build: $(SEMVER_CLI_BIN) ## Build docker image with the manager.
CGO_ENABLED=0 GOOS=linux GOARCH=$(GOARCH) make build -o fmt -o vet
docker build -t ${IMG} -f Dockerfile build
BUILDER_SUFFIX=$(shell echo $(PREFIX) | cut -d '/' -f1)
.PHONY: docker-xplatform-build
docker-xplatform-build:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 make build -o fmt -o vet
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 make build -o fmt -o vet
docker buildx create --use --node wavefront_operator_builder_$(BUILDER_SUFFIX)
docker buildx build --platform linux/amd64,linux/arm64 --push --pull -t ${IMG} -f Dockerfile build
.PHONY: docker-push
docker-push: ## Push docker image with the manager.
docker push ${IMG}
docker-copy-images:
@test $${SOURCE_PREFIX?Please set variable SOURCE_PREFIX}
docker buildx create --use --node wavefront_operator_copier_$(BUILDER_SUFFIX)
./hack/component-image-refs.sh | ./hack/docker/copy-image-refs.sh -d $(PREFIX) -s $(SOURCE_PREFIX)
echo "$(DOCKER_IMAGE):$(VERSION)" | ./hack/docker/copy-image-refs.sh -d $(PREFIX) -s $(SOURCE_PREFIX)
##@ Deployment
ifndef ignore-not-found
ignore-not-found = true
endif
.PHONY: copy-base-patches
copy-base-patches:
cp config/manager/patches-base.yaml config/manager/patches.yaml
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
.PHONY: controller-gen
controller-gen:
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/[email protected])
KUSTOMIZE = $(shell pwd)/bin/kustomize
.PHONY: kustomize
kustomize: ## Download kustomize locally if necessary.
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/[email protected])
IMGPKG = $(REPO_DIR)/bin/imgpkg
$(IMGPKG):
curl --create-dirs --output $(IMGPKG) -L https://github.com/vmware-tanzu/carvel-imgpkg/releases/download/v0.33.0/imgpkg-$(shell go env GOOS)-$(shell go env GOARCH)
chmod +x $(IMGPKG)
.PHONY: imgpkg
imgpkg: $(IMGPKG)
KUBE_LINTER = $(shell pwd)/bin/kube-linter
.PHONY: install-kube-linter
install-kube-linter: ## Download kube-linter locally if necessary.
$(call go-get-tool,$(KUBE_LINTER),golang.stackrox.io/kube-linter/cmd/[email protected])
KUBE_SCORE = $(shell pwd)/bin/kube-score
.PHONY: install-kube-score
install-kube-score: ## Download kustomize locally if necessary.
$(call go-get-tool,$(KUBE_SCORE),github.com/zegl/kube-score/cmd/[email protected])
ENVTEST = $(shell pwd)/bin/setup-envtest
.PHONY: envtest
envtest: ## Download envtest-setup locally if necessary.
$(call go-get-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest)
# go-get-tool will 'go get' any package $2 and install it to $1.
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
define go-get-tool
@[ -f $(1) ] || { \
set -e ;\
echo "Downloading $(2)" ;\
GOOS= GOARCH= GOBIN=$(PROJECT_DIR)/bin go install $(2) ;\
}
endef
OPERATOR_BUILD_DIR:=$(REPO_DIR)/build/operator
OPERATOR_YAML_TYPE?=kind
KUBERNETES_YAML:=$(OPERATOR_BUILD_DIR)/wavefront-operator.yaml
KUSTOMIZATION_TYPE?=base
KUSTOMIZATION_YAML:=$(OPERATOR_BUILD_DIR)/kustomization.yaml
$(OPERATOR_BUILD_DIR):
mkdir -p $(OPERATOR_BUILD_DIR)
.PHONY: base-kustomization-yaml
base-kustomization-yaml: $(OPERATOR_BUILD_DIR)
cp $(REPO_DIR)/hack/build/kustomization.yaml $(OPERATOR_BUILD_DIR)
.PHONY: custom-kustomization-yaml
custom-kustomization-yaml: $(OPERATOR_BUILD_DIR)
sed "s%YOUR_IMAGE_REGISTRY%$(PREFIX)%g" $(REPO_DIR)/deploy/kubernetes/kustomization.yaml | \
sed "s%YOUR_NAMESPACE%$(NS)%g" > $(KUSTOMIZATION_YAML)
.PHONY: kubernetes-yaml
kubernetes-yaml: manifests kustomize $(OPERATOR_BUILD_DIR)
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
$(KUSTOMIZE) build config/default > $(KUBERNETES_YAML)
.PHONY: rc-kubernetes-yaml
rc-kubernetes-yaml: $(OPERATOR_BUILD_DIR)
curl https://raw.githubusercontent.com/wavefrontHQ/wavefront-operator-for-kubernetes/$(OPERATOR_YAML_RC_SHA)/wavefront-operator-$(GIT_BRANCH).yaml \
-o $(KUBERNETES_YAML)
.PHONY: xplatform-kubernetes-yaml
xplatform-kubernetes-yaml: docker-xplatform-build copy-base-patches kubernetes-yaml
.PHONY: released-kubernetes-yaml
released-kubernetes-yaml: copy-base-patches kubernetes-yaml
cp $(KUBERNETES_YAML) $(REPO_DIR)/deploy/kubernetes/wavefront-operator.yaml
.PHONY: kind-kubernetes-yaml
kind-kubernetes-yaml: docker-build copy-kind-patches kubernetes-yaml
kind load docker-image $(IMG)
.PHONY: copy-kind-patches
copy-kind-patches:
cp config/manager/patches-kind.yaml config/manager/patches.yaml
.PHONY: operator-yaml
operator-yaml: $(OPERATOR_YAML_TYPE)-kubernetes-yaml $(KUSTOMIZATION_TYPE)-kustomization-yaml
.PHONY: deploy
deploy: operator-yaml
kubectl apply -k $(OPERATOR_BUILD_DIR)
kubectl create -n $(NS) secret generic wavefront-secret --from-literal token=$(WAVEFRONT_TOKEN) || true
.PHONY: undeploy
undeploy: operator-yaml
kubectl delete --ignore-not-found=$(ignore-not-found) -n $(NS) secret wavefront-secret || true
kubectl delete --ignore-not-found=$(ignore-not-found) -k $(OPERATOR_BUILD_DIR) || true
.PHONY: integration-test
integration-test: install-kube-score install-kube-linter undeploy deploy
(cd $(REPO_DIR)/hack/test && ./run-e2e-tests.sh -t $(WAVEFRONT_TOKEN) -d $(NS) -v $(VERSION) $(INTEGRATION_TEST_ARGS))
.PHONY: clean-cluster
clean-cluster:
(cd $(REPO_DIR)/hack/test && ./clean-cluster.sh)
#----- KIND ----#
.PHONY: nuke-kind
nuke-kind:
kind delete cluster
kind create cluster --image kindest/node:v1.24.7 #setting to 1.24.* to avoid floating to 1.25 which we currently don't support
#----- GKE -----#
GCP_PROJECT?=wavefront-gcp-dev
GCP_REGION=us-central1
GCP_ZONE?=c
gke-connect-to-cluster: gke-cluster-name-check
gcloud container clusters get-credentials $(GKE_CLUSTER_NAME) --zone $(GCP_REGION)-$(GCP_ZONE) --project $(GCP_PROJECT)
gke-cluster-name-check:
@if [ -z ${GKE_CLUSTER_NAME} ]; then echo "Need to set GKE_CLUSTER_NAME" && exit 1; fi
#----- AKS -----#
aks-subscription-id-check:
@if [ -z ${AKS_SUBSCRIPTION_ID} ]; then echo "Need to set AKS_SUBSCRIPTION_ID" && exit 1; fi
aks-connect-to-cluster: aks-subscription-id-check
az account set --subscription
#----- EKS -----#
ECR_REPO_PREFIX=tobs/k8s/saas
WAVEFRONT_DEV_AWS_ACC_ID=095415062695
AWS_PROFILE=wavefront-dev
AWS_REGION=us-west-2
ECR_ENDPOINT=$(WAVEFRONT_DEV_AWS_ACC_ID).dkr.ecr.$(AWS_REGION).amazonaws.com
COLLECTOR_ECR_REPO=$(ECR_REPO_PREFIX)/wavefront-kubernetes-collector
TEST_PROXY_ECR_REPO=$(ECR_REPO_PREFIX)/test-proxy
ecr-host:
echo $(ECR_ENDPOINT)/$(ECR_REPO_PREFIX)/wavefront-kubernetes-collector
docker-login-eks:
@aws ecr get-login-password --region $(AWS_REGION) --profile $(AWS_PROFILE) | docker login --username AWS --password-stdin $(ECR_ENDPOINT)
target-eks: docker-login-eks
@aws eks --region $(AWS_REGION) update-kubeconfig --name k8s-saas-team-dev --profile $(AWS_PROFILE)
# create a new branch from main
# usage: make branch JIRA=XXXX OR make branch NAME=YYYY
branch:
$(eval NAME := $(if $(JIRA),K8SAAS-$(JIRA),$(NAME)))
@if [ -z "$(NAME)" ]; then \
echo "usage: make branch JIRA=XXXX OR make branch NAME=YYYY"; \
exit 1; \
fi
git stash
git checkout main
git pull
git checkout -b $(NAME)
git-rebase:
git fetch origin
git rebase origin/main
git log --oneline -n 10