-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
249 lines (182 loc) · 9.29 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
include common.mk
include version.mk
include newline.mk
# Image URL to use all building/pushing image targets
IMG ?= kfp-operator-controller
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
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
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
$(CONTROLLER_GEN) crd rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
generate-grpc:
protoc --go_out=. --go_opt=paths=source_relative \
--go-grpc_out=. --go-grpc_opt=paths=source_relative \
triggers/run-completion-event-trigger/proto/run_completion_event_trigger.proto
fmt: ## Run go fmt against code.
go fmt ./...
vet: ## Run go vet against code.
go vet ./...
git-status-check:
@if [ -n "$$(git status -s)" ]; then echo "Uncommitted or untracked files: "; git status -s ; exit 1; fi
decoupled-test: manifests generate ## Run decoupled acceptance tests
$(call envtest-run,go test ./... -tags=decoupled -coverprofile cover.out)
ARGO_VERSION=$(shell sed -n 's/[^ tab]*github.com\/argoproj\/argo-workflows\/v3 \(v[.0-9]*\)[^.0-9]*/\1/p' <go.mod)
integration-test-up:
minikube start -p kfp-operator-tests
# Install Argo
kubectl create namespace argo --dry-run=client -o yaml | kubectl apply -f -
kubectl apply -n argo -f https://github.com/argoproj/argo-workflows/releases/download/${ARGO_VERSION}/quick-start-postgres.yaml
kubectl wait -n argo deployment/workflow-controller --for condition=available --timeout=5m
# Proxy K8s API
kubectl proxy --port=8080 & echo $$! > config/testing/pids
integration-test: manifests generate helm-cmd yq ## Run integration tests
eval $$(minikube -p kfp-operator-tests docker-env) && \
$(MAKE) -C argo/providers/stub docker-build && \
$(HELM) template helm/kfp-operator --values config/testing/integration-test-values.yaml | \
$(YQ) e 'select(.kind == "*WorkflowTemplate")' - | \
kubectl apply -f -
go test ./... -tags=integration --timeout 20m
integration-test-down:
(cat config/testing/pids | xargs kill) || true
minikube stop -p kfp-operator-tests
unit-test: manifests generate ## Run unit tests
go test ./... -tags=unit
test: fmt vet unit-test decoupled-test
test-argo:
$(MAKE) -C argo/common test
$(MAKE) -C argo/status-updater test
$(MAKE) -C argo/kfp-compiler test
$(MAKE) -C argo/providers test
test-triggers:
$(MAKE) -C triggers/run-completion-event-trigger test functional-test
test-all: test helm-test-operator helm-test-provider test-argo test-triggers
integration-test-all: integration-test
$(MAKE) -C argo/kfp-compiler integration-test
##@ Build
build: generate fmt vet ## Build manager binary.
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) go build -o bin/manager main.go
run: manifests generate fmt vet ## Run a controller from your host.
go run ./main.go --zap-devel --config config/manager/controller_manager_config.yaml
##@ Deployment
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/crd | kubectl apply -f -
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/crd | kubectl delete -f -
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
$(KUSTOMIZE) build config/default | kubectl apply -f -
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/default | kubectl delete -f -
##@ Tools
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
DYFF = $(PROJECT_DIR)/bin/dyff
dyff: ## Download dyff locally if necessary.
$(call go-install,$(DYFF),github.com/homeport/dyff/cmd/[email protected])
YQ = $(PROJECT_DIR)/bin/yq
yq: ## Download yq locally if necessary.
$(call go-install,$(YQ),github.com/mikefarah/yq/[email protected])
HELM := $(PROJECT_DIR)/bin/helm
# Can't be named helm because it's already a directory
helm-cmd: ## Download helm locally if necessary.
$(call go-install,$(HELM),helm.sh/helm/v3/cmd/[email protected])
CONTROLLER_GEN = $(PROJECT_DIR)/bin/controller-gen
controller-gen: ## Download controller-gen locally if necessary.
$(call go-install,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/[email protected])
KUSTOMIZE = $(PROJECT_DIR)/bin/kustomize
kustomize: ## Download kustomize locally if necessary.
$(call go-install,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/[email protected])
##@ Package
helm-package-operator: helm-cmd helm-test-operator
$(HELM) package helm/kfp-operator --version $(VERSION) --app-version $(VERSION) -d dist
helm-package-provider: helm-cmd helm-test-provider
$(HELM) package helm/provider --version $(VERSION) --app-version $(VERSION) -d dist
helm-package: helm-package-operator helm-package-provider
helm-install-operator: helm-package-operator values.yaml
$(HELM) install -f values.yaml kfp-operator dist/kfp-operator-$(VERSION).tgz
helm-uninstall-operator:
$(HELM) uninstall kfp-operator
helm-upgrade-operator: helm-package-operator values.yaml
$(HELM) upgrade -f values.yaml kfp-operator dist/kfp-operator-$(VERSION).tgz
# NAME needs to be passed as an argument to the make target to point at the specific values file for the provider being installed
helm-install-provider: helm-package-provider
$(HELM) install -f $(NAME).yaml provider-$(NAME) dist/provider-$(VERSION).tgz
# NAME needs to be passed as an argument to the make target to point at the specific values file for the provider being installed
helm-uninstall-provider:
$(HELM) uninstall provider-$(NAME)
# NAME needs to be passed as an argument to the make target to point at the specific values file for the provider being installed
helm-upgrade-provider: helm-package-provider
$(HELM) upgrade -f $(NAME).yaml provider-$(NAME) dist/provider-$(VERSION).tgz
ifeq ($(HELM_REPOSITORIES)$(OSS_HELM_REPOSITORIES),)
helm-publish:
$(error OSS_HELM_REPOSITORIES or HELM_REPOSITORIES must be provided as space-separated lists of URLs)
else
ifdef NETRC_FILE
helm-publish:: $(NETRC_FILE)
endif
helm-publish:: helm-package
$(foreach url,$(HELM_REPOSITORIES) $(OSS_HELM_REPOSITORIES),$(call helm-upload,$(url)))
define helm-upload
@echo "Publishing Helm chart to $(1)"
@if [[ "$(1)" == "oci://"* ]]; then \
helm push dist/kfp-operator-$(VERSION).tgz $(1)/kfp-operator; \
helm push dist/provider-$(VERSION).tgz $(1)/provider; \
else \
curl --fail --netrc-file $(NETRC_FILE) -T dist/kfp-operator-$(VERSION).tgz $(1); \
curl --fail --netrc-file $(NETRC_FILE) -T dist/provider-$(VERSION).tgz $(1); \
fi
$(NEWLINE)
endef
endif
INDEXED_YAML := $(YQ) e '{([.metadata.name, .kind] | join("-")): .}'
helm-test-operator: manifests helm-cmd kustomize yq dyff
$(eval TMP := $(shell mktemp -d))
# Create yaml files with helm and kustomize.
$(HELM) template helm/kfp-operator -f helm/kfp-operator/test/values.yaml > $(TMP)/helm
$(KUSTOMIZE) build config/default > $(TMP)/kustomize
# Because both tools create multi-document files, we have to convert them into '{name}-{kind}'-indexed objects to help the diff tools
$(INDEXED_YAML) $(TMP)/helm > $(TMP)/helm_indexed
$(INDEXED_YAML) $(TMP)/kustomize > $(TMP)/kustomize_indexed
$(DYFF) between --set-exit-code $(TMP)/helm_indexed $(TMP)/kustomize_indexed
rm -rf $(TMP)
helm-test-provider: helm-cmd
$(eval TMP := $(shell mktemp -d))
$(HELM) template helm/provider -f helm/provider/test/values.yaml > $(TMP)/helm
##@ Containers
include docker-targets.mk
docker-build-argo:
$(MAKE) -C argo/status-updater docker-build
$(MAKE) -C argo/kfp-compiler docker-build
$(MAKE) -C argo/providers docker-build
docker-push-argo:
$(MAKE) -C argo/status-updater docker-push
$(MAKE) -C argo/kfp-compiler docker-push
$(MAKE) -C argo/providers docker-push
docker-build-triggers:
$(MAKE) -C triggers/run-completion-event-trigger docker-build
docker-push-triggers:
$(MAKE) -C triggers/run-completion-event-trigger docker-push
##@ Docs
website:
$(MAKE) -C docs-gen
docker-push-quickstart:
$(MAKE) -C docs-gen/includes/quickstart docker-push
##@ Package
package-all: docker-build docker-build-argo docker-build-triggers helm-package website
publish-all: docker-push docker-push-argo docker-push-triggers helm-publish
##@ CI
prBuild: test-all package-all git-status-check
cdBuild: prBuild publish-all docker-push-quickstart