-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMakefile
More file actions
201 lines (157 loc) · 6.25 KB
/
Makefile
File metadata and controls
201 lines (157 loc) · 6.25 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
# Image URL to use all building/pushing image targets
# Image configuration
DOCKER_REGISTRY ?= localhost:5001
BASE_IMAGE_REGISTRY ?= ghcr.io
DOCKER_REPO ?= kagent-dev/khook
HELM_REPO ?= oci://ghcr.io/kagent-dev
HELM_DIST_FOLDER ?= dist
BUILD_DATE := $(shell date -u '+%Y-%m-%d')
GIT_COMMIT := $(shell git rev-parse --short HEAD || echo "unknown")
VERSION ?= $(shell git describe --tags --always 2>/dev/null | grep v || echo "v0.0.0-$(GIT_COMMIT)")
# Local architecture detection to build for the current platform
LOCALARCH ?= $(shell uname -m | sed 's/x86_64/amd64/' | sed 's/aarch64/arm64/')
# Docker buildx configuration
BUILDKIT_VERSION = v0.23.0
BUILDX_NO_DEFAULT_ATTESTATIONS=1
BUILDX_BUILDER_NAME ?= kagent-builder-$(BUILDKIT_VERSION)
DOCKER_BUILDER ?= docker buildx
DOCKER_BUILD_ARGS ?= --push --platform linux/$(LOCALARCH)
KIND_CLUSTER_NAME ?= kagent
DOCKER_IMAGE ?= khook
IMG ?= $(DOCKER_REGISTRY)/$(DOCKER_REPO)/$(DOCKER_IMAGE):$(VERSION)
# 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.
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.
.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: fmt
fmt: ## Run go fmt against code.
go fmt ./...
.PHONY: vet
vet: ## Run go vet against code.
go vet ./...
.PHONY: test
test: fmt vet ## Run tests.
go test ./... -coverprofile cover.out
##@ Build
.PHONY: build
build: fmt vet ## Build manager binary.
go build -o bin/manager cmd/main.go
.PHONY: generate
generate: ## Generate code and manifests (CRDs, RBAC, webhooks)
$(shell go env GOPATH)/bin/controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./api/..."
$(shell go env GOPATH)/bin/controller-gen crd:allowDangerousTypes=true paths="./api/..." output:crd:artifacts:config=config/crd/bases
cp config/crd/bases/kagent.dev_hooks.yaml helm/khook-crds/crds/kagent.dev_hooks.yaml
.PHONY: run
run: fmt vet ## Run a controller from your host.
go run ./cmd/main.go
.PHONY: docker-build
docker-build:
$(DOCKER_BUILDER) build --build-arg VERSION=$(VERSION) $(DOCKER_BUILD_ARGS) -t $(IMG) .
##@ Deployment
.PHONY: create-kind-cluster
create-kind-cluster:
bash ./scripts/kind/setup-kind.sh
bash ./scripts/kind/setup-metallb.sh
.PHONY: delete-kind-cluster
delete-kind-cluster:
kind delete cluster --name $(KIND_CLUSTER_NAME)
.PHONY: install
install: ## Install CRDs into the K8s cluster specified in ~/.kube/config.
kubectl apply -f config/crd/bases
.PHONY: uninstall
uninstall: ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config.
kubectl delete -f config/crd/bases
.PHONY: deploy
deploy: ## Deploy controller to the K8s cluster specified in ~/.kube/config.
kubectl apply -k config/default
.PHONY: undeploy
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config.
kubectl delete -k config/default
.PHONY: deploy-samples
deploy-samples: ## Deploy sample Hook resources.
kubectl apply -f config/samples/
.PHONY: undeploy-samples
undeploy-samples: ## Remove sample Hook resources.
kubectl delete -f config/samples/
.PHONY: kustomize-build
kustomize-build: ## Build kustomized manifests.
kubectl kustomize config/default
##@ Helm
.PHONY: helm-cleanup
helm-cleanup:
rm -f ./$(HELM_DIST_FOLDER)/*.tgz
.PHONY: helm-version
helm-version:
VERSION=$(VERSION) envsubst < helm/khook-crds/Chart-template.yaml > helm/khook-crds/Chart.yaml
VERSION=$(VERSION) envsubst < helm/khook/Chart-template.yaml > helm/khook/Chart.yaml
helm dependency update helm/khook
helm dependency update helm/khook-crds
helm package -d $(HELM_DIST_FOLDER) helm/khook-crds
helm package -d $(HELM_DIST_FOLDER) helm/khook
.PHONY: helm-publish
helm-publish: helm-version
helm push ./$(HELM_DIST_FOLDER)/khook-crds-$(VERSION).tgz $(HELM_REPO)/khook/helm
helm push ./$(HELM_DIST_FOLDER)/khook-$(VERSION).tgz $(HELM_REPO)/khook/helm
.PHONY: helm-lint
helm-lint: ## Lint Helm chart.
helm lint helm/khook
.PHONY: helm-template
helm-template: helm-version## Generate Helm templates.
helm template khook helm/khook
.PHONY: helm-install
helm-install: helm-version## Install Helm chart.
helm install khook helm/khook \
--namespace kagent \
--create-namespace \
--set image.registry=$(DOCKER_REGISTRY) \
--set image.repository=$(DOCKER_REPO)/$(DOCKER_IMAGE) \
--set image.tag=$(VERSION)
.PHONY: helm-upgrade
helm-upgrade: helm-version## Upgrade Helm chart.
helm upgrade khook helm/khook \
--namespace kagent \
--set image.registry=$(DOCKER_REGISTRY) \
--set image.repository=$(DOCKER_REPO)/$(DOCKER_IMAGE) \
--set image.tag=$(VERSION)
.PHONY: build-deploy
build-deploy: docker-build helm-deploy ## Build Docker image and deploy via Helm.
@echo "Built and deployed image: $(IMG)"
.PHONY: helm-deploy
helm-deploy: helm-version ## Deploy or upgrade Helm chart.
@if helm status khook --namespace kagent >/dev/null 2>&1; then \
echo "Upgrading existing release..."; \
helm upgrade khook helm/khook \
--namespace kagent \
--set image.registry=$(DOCKER_REGISTRY) \
--set image.repository=$(DOCKER_REPO)/$(DOCKER_IMAGE) \
--set image.tag=$(VERSION); \
else \
echo "Installing new release..."; \
helm install khook helm/khook \
--namespace kagent \
--create-namespace \
--set image.registry=$(DOCKER_REGISTRY) \
--set image.repository=$(DOCKER_REPO)/$(DOCKER_IMAGE) \
--set image.tag=$(VERSION); \
fi
.PHONY: helm-uninstall
helm-uninstall: helm-version## Uninstall Helm chart.
helm uninstall khook --namespace kagent