-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathMakefile
More file actions
222 lines (181 loc) · 9.36 KB
/
Copy pathMakefile
File metadata and controls
222 lines (181 loc) · 9.36 KB
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
## Inject the app version into operator.Version
LDFLAGS ?= -ldflags=-X=sigs.k8s.io/karpenter/pkg/operator.Version=$(shell git describe --tags --always | cut -d"v" -f2)
GOFLAGS ?= $(LDFLAGS)
WITH_GOFLAGS = GOFLAGS="$(GOFLAGS)"
## Extra helm options
CLUSTER_ENDPOINT ?= $(shell kubectl config view --minify -o jsonpath='{.clusters[].cluster.server}')
# CR for local builds of Karpenter
KARPENTER_NAMESPACE ?= karpenter-system
KARPENTER_VERSION ?= $(shell git tag --sort=committerdate | tail -1 | cut -d"v" -f2)
# KO_DOCKER_REPO ?= ${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com/dev
KO_DOCKER_REPO ?= ko.local
KOCACHE ?= ~/.ko
# GCP Cluster Context
# PROJECT_ID must be set explicitly — no default (project IDs are always personal/team-specific)
CLUSTER_NAME ?= karpenter-provider-gcp
REGION ?= us-central1
# Common Directories
MOD_DIRS = $(shell find . -path "./website" -prune -o -name go.mod -type f -print | xargs dirname)
KARPENTER_CORE_DIR = $(shell go list -m -f '{{ .Dir }}' sigs.k8s.io/karpenter)
PDCSI_MODULE = sigs.k8s.io/gcp-compute-persistent-disk-csi-driver
PDCSI_DATA_DIR = hack/pdcsi-data
PDCSI_NODE_LABELER_CONFIGMAP = deploy/kubernetes/overlays/node-labeler/configmap.yaml
help: ## Display help
@awk 'BEGIN {FS = ":.*##"; printf "Usage:\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)
presubmit: toolchain verify ci ## Run all steps in the developer loop
ci: verify-codegen verify-deadcode chart-lint verify-crds ut-test docs-lint ## Steps run in CI (toolchain and lint handled by dedicated workflow steps)
toolchain: ## Install developer toolchain
cd hack/tools && go install tool
cd hack/crd-tools && go install tool
run: ## Run Karpenter controller binary against your local cluster
SYSTEM_NAMESPACE=${KARPENTER_NAMESPACE} \
KUBERNETES_MIN_VERSION="v1.26.0" \
DISABLE_LEADER_ELECTION=true \
CLUSTER_NAME=${CLUSTER_NAME} \
PROJECT_ID=${PROJECT_ID} \
CLUSTER_LOCATION=${REGION} \
INTERRUPTION_QUEUE=${CLUSTER_NAME} \
FEATURE_GATES="SpotToSpotConsolidation=true,NodeOverlay=true" \
go run ./cmd/controller/main.go
update: tidy download ## Update go files header, CRD and generated code
$(MAKE) update-pdcsi-compatibility
hack/boilerplate.sh
hack/update-generated.sh
hack/docs-generate.sh
helm-docs -c charts/karpenter
helm-docs -c charts/karpenter-crd
verify-codegen: update ## Verify generated code is up to date
git diff --exit-code || (echo "Generated files are out of date — run 'make update' and commit the changes" && exit 1)
chart-lint: ## Lint the Helm charts (validates values.schema.json and templates)
helm lint charts/karpenter/
helm lint charts/karpenter-crd/
verify-crds: ## Validate generated CRDs with Kubernetes API server validation logic
@tmpdir=$$(mktemp -d); \
trap 'rm -rf "$$tmpdir"' EXIT; \
helm template karpenter-crd charts/karpenter-crd --include-crds > "$$tmpdir/karpenter-crd.yaml"; \
(cd hack/crd-tools && go tool kubectl-validate --version 1.35 ../../charts/karpenter/crds/ "$$tmpdir")
verify: ## Verify code. Includes linting, formatting, etc
@command -v golangci-lint >/dev/null 2>&1 || (echo "golangci-lint not found — install it from https://golangci-lint.run/welcome/install/" && exit 1)
golangci-lint run --timeout=20m
git diff --exit-code || (echo "golangci-lint reformatted files above — stage and commit them" && exit 1)
verify-deadcode: ## Check for dead code using whole-program analysis
@output=$$(deadcode -test ./... 2>&1); if [ -n "$$output" ]; then echo "$$output"; exit 1; fi
DOCS_FILES = $(shell find docs proposals -name "*.md" ! -path "docs/reference/*" 2>/dev/null)
docs-lint: ## Check docs markdown formatting (excludes generated reference docs)
mdox fmt --check $(DOCS_FILES)
docs-fix: ## Auto-fix docs markdown formatting
mdox fmt $(DOCS_FILES)
image: ## Build the Karpenter controller images using ko build
$(eval CONTROLLER_IMG=$(shell $(WITH_GOFLAGS) KOCACHE=$(KOCACHE) KO_DOCKER_REPO="$(KO_DOCKER_REPO)" ko build --bare github.com/cloudpilot-ai/karpenter-provider-gcp/cmd/controller))
$(eval IMG_REPOSITORY=$(shell echo $(CONTROLLER_IMG) | cut -d "@" -f 1 | cut -d ":" -f 1))
$(eval IMG_TAG=$(shell echo $(CONTROLLER_IMG) | cut -d "@" -f 1 | cut -d ":" -f 2 -s))
apply: image ## Deploy the controller from the current state of your git repository into your ~/.kube/config cluster
helm upgrade --install karpenter charts/karpenter \
--create-namespace \
--namespace ${KARPENTER_NAMESPACE} \
$(HELM_OPTS) \
--set logLevel=debug \
--set controller.image.repository=$(IMG_REPOSITORY) \
--set controller.image.tag=$(IMG_TAG) \
delete: ## Delete the controller from your kubeconfig cluster
helm uninstall karpenter --namespace ${KARPENTER_NAMESPACE}
kubectl delete ns ${KARPENTER_NAMESPACE}
ut-test: ## Run unit tests
go test -race ./pkg/... \
-cover -coverprofile=coverage.out -outputdir=.
# E2E configuration — names are derived from E2E_PREFIX to stay consistent
# between the setup script and the test binary.
# E2E_PROJECT_ID and E2E_LOCATION must be set explicitly — no defaults.
# E2E_SA_PATH is optional: if unset, the scripts fall back to an active
# `gcloud auth login` session (and `gcloud auth application-default login`
# for the Go test binary's GCP client calls).
E2E_PROJECT_ID ?=
E2E_SA_PATH ?=
E2E_LOCATION ?=
E2E_PREFIX ?= karpenter-e2e
E2E_REGION ?= us-central1
E2E_CLUSTER_NAME ?= $(E2E_PREFIX)-cluster
E2E_PODS_RANGE ?= $(E2E_PREFIX)-pods
E2E_KARPENTER_NAMESPACE ?=
E2E_KARPENTER_DEPLOYMENT ?=
# Only set GOOGLE_APPLICATION_CREDENTIALS when E2E_SA_PATH is provided.
E2E_GAC_ENV = $(if $(E2E_SA_PATH),GOOGLE_APPLICATION_CREDENTIALS=$(E2E_SA_PATH))
E2E_GAC_ENV_ABS = $(if $(E2E_SA_PATH),GOOGLE_APPLICATION_CREDENTIALS=$(abspath $(E2E_SA_PATH)))
e2e-setup: require-e2e-vars ## Create (or reuse) the e2e GKE cluster and supporting GCP infra
$(E2E_GAC_ENV) \
E2E_PROJECT_ID=$(E2E_PROJECT_ID) \
E2E_PREFIX=$(E2E_PREFIX) \
E2E_REGION=$(E2E_REGION) \
E2E_LOCATION=$(E2E_LOCATION) \
./hack/e2e-setup.sh
RELEASE_VERSION ?=
e2e-deploy: require-e2e-vars ## Build and deploy karpenter; set RELEASE_VERSION=X.Y.Z to install the published chart instead
$(E2E_GAC_ENV) \
E2E_PROJECT_ID=$(E2E_PROJECT_ID) \
E2E_PREFIX=$(E2E_PREFIX) \
E2E_REGION=$(E2E_REGION) \
E2E_LOCATION=$(E2E_LOCATION) \
RELEASE_VERSION=$(RELEASE_VERSION) \
./hack/e2e-deploy.sh
require-e2e-vars: ## Fail fast if required e2e variables are not set
@test -n "$(E2E_PROJECT_ID)" || (echo "ERROR: E2E_PROJECT_ID is not set" >&2 && exit 1)
@test -n "$(E2E_LOCATION)" || (echo "ERROR: E2E_LOCATION is not set" >&2 && exit 1)
GINKGO_PROCS ?= 4
e2e-tests: require-e2e-vars ## Run all e2e test suites in parallel (GINKGO_PROCS=N, default 4)
$(E2E_GAC_ENV_ABS) \
PROJECT_ID=$(E2E_PROJECT_ID) \
CLUSTER_NAME=$(E2E_CLUSTER_NAME) \
CLUSTER_LOCATION=$(E2E_LOCATION) \
PODS_RANGE_NAME=$(E2E_PODS_RANGE) \
KARPENTER_NAMESPACE=$(E2E_KARPENTER_NAMESPACE) \
KARPENTER_DEPLOYMENT=$(E2E_KARPENTER_DEPLOYMENT) \
go run github.com/onsi/ginkgo/v2/ginkgo --procs=$(GINKGO_PROCS) --timeout=2h -v ./test/suites/...
FOCUS ?=
SUITE ?=
e2e-test: require-e2e-vars ## Run a single e2e suite or focused spec (SUITE=<name>, FOCUS="<substring>", GINKGO_PROCS=N)
$(E2E_GAC_ENV_ABS) \
PROJECT_ID=$(E2E_PROJECT_ID) \
CLUSTER_NAME=$(E2E_CLUSTER_NAME) \
CLUSTER_LOCATION=$(E2E_LOCATION) \
PODS_RANGE_NAME=$(E2E_PODS_RANGE) \
KARPENTER_NAMESPACE=$(E2E_KARPENTER_NAMESPACE) \
KARPENTER_DEPLOYMENT=$(E2E_KARPENTER_DEPLOYMENT) \
go run github.com/onsi/ginkgo/v2/ginkgo --procs=$(GINKGO_PROCS) --timeout=30m -v \
$(if $(FOCUS),--focus="$(FOCUS)",) \
$(if $(SUITE),./test/suites/$(SUITE)/,./test/suites/...)
e2e-teardown: ## Delete the e2e GKE cluster and all supporting GCP infra
$(E2E_GAC_ENV) \
E2E_PREFIX=$(E2E_PREFIX) \
E2E_REGION=$(E2E_REGION) \
E2E_LOCATION=$(E2E_LOCATION) \
./hack/e2e-teardown.sh
e2e-check-clean: ## Report any orphaned e2e GCP resources (does not delete)
$(E2E_GAC_ENV) \
E2E_PREFIX=$(E2E_PREFIX) \
E2E_REGION=$(E2E_REGION) \
E2E_LOCATION=$(E2E_LOCATION) \
./hack/e2e-check-clean.sh
coverage:
go tool cover -html coverage.out -o coverage.html
tidy: ## Run "go mod tidy"
go mod tidy
download: ## Run "go mod download"
go mod download
update-pdcsi-compatibility: ## Update vendored PDCSI disk compatibility data from the pinned Go module
@cd $(PDCSI_DATA_DIR) && go mod download $(PDCSI_MODULE)
@src="$$(cd $(PDCSI_DATA_DIR) && go list -mod=mod -m -f '{{ .Dir }}' $(PDCSI_MODULE))/$(PDCSI_NODE_LABELER_CONFIGMAP)"; \
test -f "$$src" || (echo "PDCSI node-labeler ConfigMap not found at $$src" >&2; exit 1); \
cp "$$src" pkg/providers/disktype/pdcsi/node-labeler-configmap.yaml
update-pricing:
@tmpdir=$$(mktemp -d); \
trap "rm -rf $$tmpdir" EXIT; \
go run ./hack/price_validate --work-dir=$$tmpdir && \
cp $$tmpdir/computed.json pkg/providers/pricing/initial-prices.json && \
echo "Updated pkg/providers/pricing/initial-prices.json"
codegen: ## Auto generate files based on GCP APIs
./hack/codegen.sh
crds: ## Apply CRDs
kubectl apply -f charts/karpenter/crds/
.PHONY: help presubmit ci run ut-test require-project-id e2e-setup e2e-tests e2e-test e2e-teardown e2e-check-clean e2e-deploy coverage update update-pdcsi-compatibility update-pricing verify-codegen verify verify-crds verify-deadcode image apply delete toolchain tidy download docs-lint docs-fix
define newline
endef