Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
277 lines (224 loc) · 10.2 KB
/
Copy pathMakefile
File metadata and controls
277 lines (224 loc) · 10.2 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
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
OCI_REPO ?= registry.k8s.io/kro
HELM_IMAGE ?= ${OCI_REPO}/charts/kro
KO_DOCKER_REPO ?= ${OCI_REPO}/kro
HELM ?= go run helm.sh/helm/v3/cmd/helm@v3.19.0
KOCACHE ?= ~/.ko
KO_PUSH ?= true
export KIND_CLUSTER_NAME ?= kro
GIT_TAG ?= dirty-tag
GIT_VERSION ?= $(shell git describe --tags --always --dirty)
GIT_HASH ?= $(shell git rev-parse HEAD)
DATE_FMT = +%Y-%m-%dT%H:%M:%SZ
SOURCE_DATE_EPOCH ?= $(shell git log -1 --no-show-signature --pretty=%ct)
ifdef SOURCE_DATE_EPOCH
BUILD_DATE ?= $(shell date -u -d "@$(SOURCE_DATE_EPOCH)" "$(DATE_FMT)" 2>/dev/null || date -u -r "$(SOURCE_DATE_EPOCH)" "$(DATE_FMT)" 2>/dev/null || date -u "$(DATE_FMT)")
else
BUILD_DATE ?= $(shell date "$(DATE_FMT)")
endif
GIT_TREESTATE = "clean"
DIFF = $(shell git diff --quiet >/dev/null 2>&1; if [ $$? -eq 1 ]; then echo "1"; fi)
ifeq ($(DIFF), 1)
GIT_TREESTATE = "dirty"
endif
LDFLAGS="-buildid= -X sigs.k8s.io/release-utils/version.gitVersion=$(GIT_VERSION) \
-X sigs.k8s.io/release-utils/version.gitCommit=$(GIT_HASH) \
-X sigs.k8s.io/release-utils/version.gitTreeState=$(GIT_TREESTATE) \
-X sigs.k8s.io/release-utils/version.buildDate=$(BUILD_DATE)"
WITH_GOFLAGS = GOFLAGS="$(GOFLAGS)"
HELM_DIR = ./helm
WHAT ?= unit
# 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
# CONTAINER_TOOL defines the container tool to be used for building images.
# Be aware that the target commands are only tested with Docker which is
# scaffolded by default. However, you might want to replace it to use other
# tools. (i.e. finch)
CONTAINER_TOOL ?= finch
# 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 command 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 ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
cp config/crd/bases/* helm/crds
.PHONY: generate
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
$(CONTROLLER_GEN) object paths="./..."
tt:
$(CONTROLLER_GEN) object paths="./pkg/controller/resourcegraphdefinition"
.PHONY: fmt
fmt: go-generate ## Run go fmt against code and add licenses.
go fmt ./...
.PHONY: go-generate
go-generate: ## Run go generate against code.
go generate
.PHONY: vet
vet: ## Run go vet against code.
go vet ./...
.PHONY: test
test: manifests generate fmt vet envtest ## Run tests. Use WHAT=unit or WHAT=integration
ifeq ($(WHAT),integration)
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_VERSION) --bin-dir $(LOCALBIN) -p path)" go test -v ./test/integration/suites/... -coverprofile integration-cover.out -ginkgo.v
else ifeq ($(WHAT),unit)
go test -v ./pkg/... -coverprofile unit-cover.out
else
@echo "Error: WHAT must be either 'unit' or 'integration'"
@echo "Usage: make test WHAT=unit|integration"
@exit 1
endif
GOLANGCI_LINT = $(shell pwd)/bin/golangci-lint
GOLANGCI_LINT_VERSION ?= v1.64.5
golangci-lint:
@[ -f $(GOLANGCI_LINT) ] || { \
set -e ;\
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell dirname $(GOLANGCI_LINT)) $(GOLANGCI_LINT_VERSION) ;\
}
.PHONY: lint
lint: golangci-lint ## Run golangci-lint linter & yamllint
$(GOLANGCI_LINT) run
.PHONY: lint-fix
lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes
$(GOLANGCI_LINT) run --fix
##@ Build
.PHONY: build
build: manifests generate fmt vet ## Build controller binary.
go build -ldflags=${LDFLAGS} -o bin/controller ./cmd/controller/main.go
.PHONY: run
run: manifests generate fmt vet ## Run a controller from your host.
go run ./cmd/controller/main.go
##@ Build Dependencies
## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)
## Tool Binaries
KUBECTL ?= kubectl
KIND ?= kind
KUSTOMIZE ?= $(LOCALBIN)/kustomize
KO ?= $(LOCALBIN)/ko
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
ENVTEST ?= $(LOCALBIN)/setup-envtest
CHAINSAW ?= $(LOCALBIN)/chainsaw
## Tool Versions
KO_VERSION ?= v0.17.1
KUSTOMIZE_VERSION ?= v5.2.1
CONTROLLER_TOOLS_VERSION ?= v0.16.2
CHAINSAW_VERSION ?= v0.2.12
.PHONY: chainsaw
chainsaw: $(CHAINSAW) ## Download chainsaw locally if necessary. If wrong version is installed, it will be removed before downloading.
$(CHAINSAW): $(LOCALBIN)
@if test -x $(LOCALBIN)/chainsaw && ! $(LOCALBIN)/chainsaw version | grep -q $(CHAINSAW_VERSION); then \
echo "$(LOCALBIN)/chainsaw version is not expected $(CHAINSAW_VERSION). Removing it before installing."; \
rm -rf $(LOCALBIN)/chainsaw; \
fi
test -s $(LOCALBIN)/chainsaw || GOBIN=$(LOCALBIN) GO111MODULE=on go install github.com/kyverno/chainsaw@$(CHAINSAW_VERSION)
ENVTEST_VERSION ?= 1.31.x
.PHONY: ko
ko: $(KO) ## Download ko locally if necessary. If wrong version is installed, it will be removed before downloading.
$(KO): $(LOCALBIN)
@if test -x $(LOCALBIN)/ko && ! $(LOCALBIN)/ko version | grep -q $(KO_VERSION); then \
echo "$(LOCALBIN)/ko version is not expected $(KO_VERSION). Removing it before installing."; \
rm -rf $(LOCALBIN)/ko; \
fi
test -s $(LOCALBIN)/ko || GOBIN=$(LOCALBIN) GO111MODULE=on go install github.com/google/ko@$(KO_VERSION)
.PHONY: kustomize
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. If wrong version is installed, it will be removed before downloading.
$(KUSTOMIZE): $(LOCALBIN)
@if test -x $(LOCALBIN)/kustomize && ! $(LOCALBIN)/kustomize version | grep -q $(KUSTOMIZE_VERSION); then \
echo "$(LOCALBIN)/kustomize version is not expected $(KUSTOMIZE_VERSION). Removing it before installing."; \
rm -rf $(LOCALBIN)/kustomize; \
fi
test -s $(LOCALBIN)/kustomize || GOBIN=$(LOCALBIN) GO111MODULE=on go install sigs.k8s.io/kustomize/kustomize/v5@$(KUSTOMIZE_VERSION)
.PHONY: controller-gen
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary. If wrong version is installed, it will be overwritten.
$(CONTROLLER_GEN): $(LOCALBIN)
test -s $(LOCALBIN)/controller-gen && $(LOCALBIN)/controller-gen --version | grep -q $(CONTROLLER_TOOLS_VERSION) || \
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
.PHONY: envtest
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
$(ENVTEST): $(LOCALBIN)
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) $(GOPREFIX) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
.PHONY: image
build-image: ko ## Build the kro controller images using ko build
echo "Building kro image $(RELEASE_VERSION).."
$(WITH_GOFLAGS) KOCACHE=$(KOCACHE) KO_DOCKER_REPO=$(KO_DOCKER_REPO) \
$(KO) build --bare github.com/kubernetes-sigs/kro/cmd/controller \
--local\
--push=false --tags ${RELEASE_VERSION} --sbom=none
.PHONY: publish
publish-image: ko ## Publish the kro controller images
$(WITH_GOFLAGS) KOCACHE=$(KOCACHE) KO_DOCKER_REPO=$(KO_DOCKER_REPO) \
$(KO) publish --bare github.com/kubernetes-sigs/kro/cmd/controller \
--tags ${RELEASE_VERSION} --sbom=none
.PHONY: package-helm
package-helm: ## Package Helm chart
cp ./config/crd/bases/* helm/crds/
sed -i 's/tag: .*/tag: "$(RELEASE_VERSION)"/' helm/values.yaml
sed -i 's/version: .*/version: $(RELEASE_VERSION)/' helm/Chart.yaml
sed -i 's/appVersion: .*/appVersion: "$(RELEASE_VERSION)"/' helm/Chart.yaml
${HELM} package helm
.PHONY: publish-helm
publish-helm: ## Helm publish
${HELM} push ./kro-${RELEASE_VERSION}.tgz oci://${HELM_IMAGE}
.PHONY:
release: build-image publish-image package-helm publish-helm
##@ Deployment
ifndef ignore-not-found
ignore-not-found = true
endif
.PHONY: install
install: manifests ## Install CRDs into the K8s cluster specified in ~/.kube/config.
$(KUBECTL) apply -f ./helm/crds
.PHONY: uninstall
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config
$(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f ./helm/crds
.PHONY: deploy-kind
deploy-kind: export KO_DOCKER_REPO=kind.local
deploy-kind: ko
$(KIND) delete clusters ${KIND_CLUSTER_NAME} || true
$(KIND) create cluster --name ${KIND_CLUSTER_NAME}
$(KUBECTL) --context kind-$(KIND_CLUSTER_NAME) create namespace kro-system
make install
# This generates deployment with ko://... used in image.
# ko then intercepts it builds image, pushes to kind node, replaces the image in deployment and applies it
${HELM} template kro ./helm --namespace kro-system --set image.pullPolicy=Never --set image.ko=true --set config.allowCRDDeletion=true | $(KO) apply -f -
kubectl wait --for=condition=ready --timeout=1m pod -n kro-system -l app.kubernetes.io/component=controller
$(KUBECTL) --context kind-${KIND_CLUSTER_NAME} get pods -A
.PHONY: ko-apply
ko-apply: ko
${HELM} template kro ./helm --namespace kro-system --set image.pullPolicy=Never --set image.ko=true | $(KO) apply -f -
## CLI
.PHONY: cli
cli:
go build -o bin/kro cmd/kro/main.go
sudo mv bin/kro /usr/loc
3843
al/bin
@echo "CLI built successfully"
##@ E2E Tests
.PHONY: test-e2e
test-e2e: chainsaw ## Run e2e tests
$(CHAINSAW) test ./test/e2e/chainsaw
.PHONY: test-e2e-kind
test-e2e-kind: deploy-kind
make test-e2e