forked from GoogleContainerTools/kpt-config-sync
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
454 lines (362 loc) · 13.7 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
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
#!/usr/bin/make
#
# Copyright 2018 CSP Config Management 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.
######################################################################
##### CONFIG #####
REPO := kpt.dev/configsync
# Some of our recipes use bash syntax, so explicitly set the shell to bash.
SHELL := /bin/bash
# List of dirs containing go code owned by Nomos
NOMOS_CODE_DIRS := pkg cmd e2e
NOMOS_GO_PKG := $(foreach dir,$(NOMOS_CODE_DIRS),./$(dir)/...)
# Directory containing all build artifacts. We need abspath here since
# mounting a directory as a docker volume requires an abspath. This should
# eventually be pushed down into where docker commands are run rather than
# requiring all our paths to be absolute.
OUTPUT_DIR := $(abspath .output)
# Self-contained GOPATH dir.
GO_DIR := $(OUTPUT_DIR)/go
# Base image used for all golang containers
GOLANG_IMAGE := golang:1.21.5-bookworm
# Base image used for debian containers
DEBIAN_BASE_IMAGE := gcr.io/gke-release/debian-base:bookworm-v1.0.0-gke.4
# Base image used for gcloud install, primarily for test images.
# We use -slim for a smaller base image where we can choose which components to install.
# https://cloud.google.com/sdk/docs/downloads-docker#docker_image_options
GCLOUD_IMAGE := gcr.io/google.com/cloudsdktool/google-cloud-cli:449.0.0-slim
# Base image used for docker cli install, primarily used for test images.
DOCKER_CLI_IMAGE := gcr.io/cloud-builders/docker:20.10.14
# Directory containing installed go binaries.
BIN_DIR := $(GO_DIR)/bin
ADDLICENSE_VERSION := v1.1.1
ADDLICENSE := $(BIN_DIR)/addlicense
GOLANGCI_LINT_VERSION := v1.52.0
GOLANGCI_LINT := $(BIN_DIR)/golangci-lint
KUSTOMIZE_VERSION := v5.3.0-gke.0
KUSTOMIZE := $(BIN_DIR)/kustomize
KUSTOMIZE_STAGING_DIR := $(OUTPUT_DIR)/third_party/kustomize
HELM_VERSION := v3.13.3-gke.2
HELM := $(BIN_DIR)/helm
HELM_STAGING_DIR := $(OUTPUT_DIR)/third_party/helm
# Keep KIND_VERSION in sync with the version defined in go.mod
# When upgrading, update the node image versions at e2e/nomostest/clusters/kind.go
KIND_VERSION := v0.20.0
KIND := $(BIN_DIR)/kind
# crane cli version used for publishing OCI images
# used by tests or local make targets
CRANE_VERSION := v0.16.1
CRANE := $(BIN_DIR)/crane
# Directory used for staging Docker contexts.
STAGING_DIR := $(OUTPUT_DIR)/staging
# Directory used for staging the manifest primitives.
NOMOS_MANIFEST_STAGING_DIR := $(STAGING_DIR)/operator
OSS_MANIFEST_STAGING_DIR := $(STAGING_DIR)/oss
# Directory that gets mounted into /tmp for build and test containers.
TEMP_OUTPUT_DIR := $(OUTPUT_DIR)/tmp
# Directory containing Deployment yamls with image paths spliced in
GEN_DEPLOYMENT_DIR := $(OUTPUT_DIR)/deployment
# Directory containing generated test yamls
TEST_GEN_YAML_DIR := $(OUTPUT_DIR)/test/yaml
# Use git tags to set version string.
ifeq ($(origin VERSION), undefined)
VERSION := $(shell git describe --tags --always --dirty --long)
endif
# UID of current user
UID := $(shell id -u)
# GID of current user
GID := $(shell id -g)
# GCP project that owns container registry for local dev build.
ifeq ($(origin GCP_PROJECT), undefined)
GCP_PROJECT := $(shell gcloud config get-value project)
endif
# Use BUILD_ID as a unique identifier for prow jobs, otherwise default to USER
BUILD_ID ?= $(USER)
GCR_PREFIX ?= $(GCP_PROJECT)/$(BUILD_ID)
GCS_PREFIX ?= gs://$(GCP_PROJECT)/config-sync
GCS_BUCKET ?= $(GCS_PREFIX)/$(shell git rev-parse HEAD)
LOCATION ?= us
# Allow arbitrary registry name, but default to GCR with prefix if not provided
REGISTRY ?= gcr.io/$(GCR_PREFIX)
# Registry used for retagging previously built images
OLD_REGISTRY ?= $(REGISTRY)
# Registry which hosts images related to test infrastructure
TEST_INFRA_PROJECT ?= kpt-config-sync-ci-artifacts
TEST_INFRA_REGISTRY ?= $(LOCATION)-docker.pkg.dev/$(TEST_INFRA_PROJECT)/test-infra
# Docker image used for build and test. This image does not support CGO.
# When upgrading this tag, the image will be rebuilt locally during presubmits.
# After the change is submitted, a postsubmit job will publish the new tag.
# There is no need to manually publish this image.
BUILDENV_IMAGE ?= $(TEST_INFRA_REGISTRY)/buildenv:v0.3.2
# Nomos docker images containing all binaries.
RECONCILER_IMAGE := reconciler
RECONCILER_MANAGER_IMAGE := reconciler-manager
ADMISSION_WEBHOOK_IMAGE := admission-webhook
HYDRATION_CONTROLLER_IMAGE := hydration-controller
HYDRATION_CONTROLLER_WITH_SHELL_IMAGE := $(HYDRATION_CONTROLLER_IMAGE)-with-shell
OCI_SYNC_IMAGE := oci-sync
HELM_SYNC_IMAGE := helm-sync
NOMOS_IMAGE := nomos
ASKPASS_IMAGE := gcenode-askpass-sidecar
RESOURCE_GROUP_IMAGE := resource-group-controller
# List of Config Sync images. Used to generate image-related variables/targets.
IMAGES := \
$(RECONCILER_IMAGE) \
$(RECONCILER_MANAGER_IMAGE) \
$(ADMISSION_WEBHOOK_IMAGE) \
$(HYDRATION_CONTROLLER_IMAGE) \
$(HYDRATION_CONTROLLER_WITH_SHELL_IMAGE) \
$(OCI_SYNC_IMAGE) \
$(HELM_SYNC_IMAGE) \
$(NOMOS_IMAGE) \
$(ASKPASS_IMAGE) \
$(RESOURCE_GROUP_IMAGE)
# nomos binary for local run.
NOMOS_LOCAL := $(BIN_DIR)/linux_amd64/nomos
# Allows an interactive docker build or test session to be interrupted
# by Ctrl-C. This must be turned off in case of non-interactive runs,
# like in CI/CD.
DOCKER_INTERACTIVE := --interactive
HAVE_TTY := $(shell [ -t 0 ] && echo 1 || echo 0)
ifeq ($(HAVE_TTY), 1)
DOCKER_INTERACTIVE += --tty
endif
# Suppresses docker output on build.
#
# To turn off, for example:
# make DOCKER_BUILD_QUIET="" deploy
DOCKER_BUILD_QUIET ?= --quiet
# Suppresses gcloud output.
GCLOUD_QUIET := --quiet
# Developer focused docker image tag.
ifeq ($(origin IMAGE_TAG), undefined)
IMAGE_TAG := $(shell git describe --tags --always --dirty --long)
endif
# Tag used for retagging previously built images
OLD_IMAGE_TAG ?= $(IMAGE_TAG)
# define a function for dynamically evaluating image tags
# e.g. $(call gen_image_tag,reconciler) => $(REGISTRY)/reconciler:$(IMAGE_TAG)
gen_image_tag = $(REGISTRY)/$(1):$(IMAGE_TAG)
DOCKER_RUN_ARGS = \
$(DOCKER_INTERACTIVE) \
-u $(UID):$(GID) \
-v $(GO_DIR):/go \
-v $$(pwd):/go/src/$(REPO) \
-v $(GO_DIR)/std/linux_amd64_static:/usr/local/go/pkg/linux_amd64_static \
-v $(GO_DIR)/std/linux_arm64_static:/usr/local/go/pkg/linux_arm64_static \
-v $(GO_DIR)/std/darwin_amd64_static:/usr/local/go/pkg/darwin_amd64_static \
-v $(GO_DIR)/std/darwin_arm64_static:/usr/local/go/pkg/darwin_arm64_static \
-v $(GO_DIR)/std/windows_amd64_static:/usr/local/go/pkg/windows_amd64_static \
-v $(TEMP_OUTPUT_DIR):/tmp \
-v $${HOME}/.config:/.config \
-v $${HOME}/.gsutil:/.gsutil \
-w /go/src/$(REPO) \
--rm \
$(BUILDENV_IMAGE) \
# Common build-arg defaults to define in one place
DOCKER_BUILD_ARGS = \
--build-arg VERSION=$(VERSION) \
--build-arg KIND_VERSION=$(KIND_VERSION) \
--build-arg GOLANG_IMAGE=$(GOLANG_IMAGE) \
--build-arg DEBIAN_BASE_IMAGE=$(DEBIAN_BASE_IMAGE) \
--build-arg GCLOUD_IMAGE=$(GCLOUD_IMAGE) \
--build-arg DOCKER_CLI_IMAGE=$(DOCKER_CLI_IMAGE)
# 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
# Add binary directories to PATH (prioritize .output/go/bin -> $GOPATH/bin -> $PATH)
PATH := $(BIN_DIR):$(GOBIN):$(PATH)
##### SETUP #####
.DEFAULT_GOAL := all
.PHONY: $(OUTPUT_DIR)
$(OUTPUT_DIR):
@echo "+++ Creating the local build output directory: $(OUTPUT_DIR)"
@mkdir -p \
$(STAGING_DIR) \
$(TEMP_OUTPUT_DIR) \
$(TEST_GEN_YAML_DIR) \
$(NOMOS_MANIFEST_STAGING_DIR) \
$(OSS_MANIFEST_STAGING_DIR) \
$(GEN_DEPLOYMENT_DIR)
# These directories get mounted by DOCKER_RUN_ARGS, so we have to create them
# before invoking docker.
.PHONY: buildenv-dirs
buildenv-dirs:
@mkdir -p \
$(BIN_DIR) \
$(GO_DIR)/src/$(REPO) \
$(GO_DIR)/std/linux_amd64_static \
$(GO_DIR)/std/linux_arm64_static \
$(GO_DIR)/std/darwin_amd64_static \
$(GO_DIR)/std/darwin_arm64_static \
$(GO_DIR)/std/windows_amd64_static \
$(TEMP_OUTPUT_DIR)
##### TARGETS #####
include Makefile.build
-include Makefile.docs
include Makefile.e2e
-include Makefile.prow
include Makefile.gen
include Makefile.oss
include Makefile.oss.prow
include Makefile.reconcilermanager
-include Makefile.release
.PHONY: all
all: test deps configsync-crds
# Cleans all artifacts.
.PHONY: clean
clean:
@echo "+++ Cleaning $(OUTPUT_DIR)"
@rm -rf $(OUTPUT_DIR)
.PHONY: build-status
build-status:
@./scripts/build-status.sh
.PHONY: test-unit
test-unit: buildenv-dirs "$(KUSTOMIZE)"
@echo "+++ Running unit tests in a docker container"
@./scripts/test-unit.sh $(NOMOS_GO_PKG)
# Runs unit tests and linter.
.PHONY: test
test: test-unit lint
# The presubmits have made side-effects in the past, which makes their
# validation suspect (as the repository they are validating is different
# than what is checked in). Run `test` but verify that repository is clean.
.PHONY: __test-presubmit
__test-presubmit: all
@./scripts/fail-if-dirty-repo.sh
# This is the entrypoint used by the ProwJob - runs using docker-in-docker.
.PHONY: test-presubmit
test-presubmit: pull-buildenv
@docker run $(DOCKER_RUN_ARGS) make __test-presubmit
# Runs all tests.
# This only runs on local dev environment not CI environment.
.PHONY: test-all-local
test-all-local: test test-e2e
# Runs gofmt and goimports.
# Even though goimports runs gofmt, it runs it without the -s (simplify) flag
# and offers no option to turn it on. So we run them in sequence.
.PHONY: fmt-go
fmt-go: pull-buildenv buildenv-dirs
@docker run $(DOCKER_RUN_ARGS) gofmt -s -w $(NOMOS_CODE_DIRS)
@docker run $(DOCKER_RUN_ARGS) goimports -w $(NOMOS_CODE_DIRS)
# Runs shfmt.
.PHONY: fmt-sh
fmt-sh:
@./scripts/fmt-bash.sh
.PHONY: tidy
tidy:
go mod tidy
.PHONY: vendor
vendor:
go mod vendor
.PHONY: deps
deps: tidy vendor
.PHONY: lint
lint: lint-go lint-bash lint-yaml lint-license lint-license-headers
.PHONY: lint-go
lint-go: "$(GOLANGCI_LINT)"
./scripts/lint-go.sh $(NOMOS_GO_PKG)
.PHONY: lint-bash
lint-bash:
@./scripts/lint-bash.sh
.PHONY: lint-license
lint-license: buildenv-dirs
./scripts/lint-license.sh
"$(ADDLICENSE)": buildenv-dirs
GOPATH="$(GO_DIR)" go install github.com/google/addlicense@$(ADDLICENSE_VERSION)
.PHONY: install-addlicense
# install addlicense (user-friendly target alias)
install-addlicense: "$(ADDLICENSE)"
.PHONY: clean-addlicense
clean-addlicense:
@rm -rf $(ADDLICENSE)
"$(GOLANGCI_LINT)": buildenv-dirs
GOPATH="$(GO_DIR)" go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)
.PHONY: install-golangci-lint
# install golangci-lint (user-friendly target alias)
install-golangci-lint: "$(GOLANGCI_LINT)"
.PHONY: clean-golangci-lint
clean-golangci-lint:
@rm -rf $(GOLANGCI_LINT)
"$(KUSTOMIZE)": buildenv-dirs
@KUSTOMIZE_VERSION="$(KUSTOMIZE_VERSION)" \
INSTALL_DIR="$(BIN_DIR)" \
TMPDIR="/tmp" \
OUTPUT_DIR="$(OUTPUT_DIR)" \
STAGING_DIR="$(KUSTOMIZE_STAGING_DIR)" \
./scripts/install-kustomize.sh
.PHONY: install-kustomize
# install kustomize (user-friendly target alias)
install-kustomize: "$(KUSTOMIZE)"
.PHONY: clean-kustomize
clean-kustomize:
@rm -rf $(KUSTOMIZE_STAGING_DIR)
@rm -rf $(KUSTOMIZE)
"$(HELM)": buildenv-dirs
@HELM_VERSION="$(HELM_VERSION)" \
INSTALL_DIR="$(BIN_DIR)" \
TMPDIR="/tmp" \
OUTPUT_DIR="$(OUTPUT_DIR)" \
STAGING_DIR="$(HELM_STAGING_DIR)" \
./scripts/install-helm.sh
.PHONY: install-helm
# install helm (user-friendly target alias)
install-helm: "$(HELM)"
.PHONY: clean-helm
clean-helm:
@rm -rf $(HELM_STAGING_DIR)
@rm -rf $(HELM)
"$(GOBIN)/kind":
go install sigs.k8s.io/kind@$(KIND_VERSION)
"$(KIND)": "$(GOBIN)/kind" buildenv-dirs
cp $(GOBIN)/kind $(KIND)
.PHONY: install-kind
# install kind (user-friendly target alias)
install-kind: "$(KIND)"
# Set CGO_ENABLED=0 for compatibility with containers missing glibc
"$(GOBIN)/crane":
CGO_ENABLED=0 go install github.com/google/go-containerregistry/cmd/crane@$(CRANE_VERSION)
"$(CRANE)": "$(GOBIN)/crane" buildenv-dirs
cp $(GOBIN)/crane $(CRANE)
.PHONY: install-crane
# install crane (user-friendly target alias)
install-crane: "$(CRANE)"
.PHONY: clean-crane
clean-crane:
@rm -rf $(CRANE)
.PHONY: license-headers
license-headers: "$(ADDLICENSE)"
./scripts/license-headers.sh add
.PHONY: lint-license-headers
lint-license-headers: "$(ADDLICENSE)"
./scripts/license-headers.sh lint
.PHONY: lint-yaml
lint-yaml:
@./scripts/lint-yaml.sh
.PHONY: test-loggers
test-loggers:
./scripts/generate-test-loggers.sh
# Print the value of a variable
print-%:
@echo $($*)
####################################################################################################
# MANUAL TESTING COMMANDS
# Reapply the resources, including a new image. Use this to update with your code changes.
.PHONY: manual-test-refresh
manual-test-refresh: config-sync-manifest
kubectl apply -f ${NOMOS_MANIFEST_STAGING_DIR}/config-sync-manifest.yaml
####################################################################################################