@@ -5,6 +5,7 @@ PROJECT_BIN := $(PROJECT_PATH)/bin
55GO ?= "$(shell which go) "
66UI_PATH := $(PROJECT_PATH ) /clients/ui
77CSI_PATH := $(PROJECT_PATH ) /cmd/csi
8+ CONTROLLER_PATH := $(PROJECT_PATH ) /cmd/controller
89
910# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
1011ENVTEST_K8S_VERSION = 1.29
@@ -47,6 +48,11 @@ ifeq ($(IMG_REPO),model-registry/storage-initializer)
4748 DOCKERFILE := $(CSI_PATH ) /Dockerfile.csi
4849endif
4950
51+ # The BUILD_PATH is still the root
52+ ifeq ($(IMG_REPO ) ,model-registry/controller)
53+ DOCKERFILE := $(CONTROLLER_PATH ) /Dockerfile.controller
54+ endif
55+
5056model-registry : build
5157
5258# clean the ml-metadata protos and trigger a fresh new build which downloads
@@ -133,7 +139,7 @@ clean-pkg-openapi:
133139clean-internal-server-openapi :
134140 while IFS= read -r file; do rm -f " internal/server/openapi/$$ file" ; done < internal/server/openapi/.openapi-generator/FILES
135141
136- .PHONY : clean
142+ .PHONY : clean
137143clean : clean-pkg-openapi clean-internal-server-openapi clean/csi
138144 rm -Rf ./model-registry internal/ml_metadata/proto/* .go internal/converter/generated/* .go
139145
@@ -308,3 +314,130 @@ image/push:
308314 ${DOCKER} push ${IMG} :$(IMG_VERSION )
309315
310316all : model-registry
317+
318+ # # ------------------------------- ##
319+ # # ---- Controller Targets ---- ##
320+ # # ------------------------------- ##
321+
322+ # #@ Development
323+
324+ .PHONY : controller/manifests
325+ controller/manifests : bin/controller-gen # # Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
326+ $(CONTROLLER_GEN ) rbac:roleName=model-registry-manager-role crd webhook paths=" {./cmd/controller/..., ./internal/controller/...}" output:crd:artifacts:config=manifests/options/controller/crd/bases output:rbac:dir=manifests/kustomize/options/controller/rbac
327+
328+ .PHONY : controller/generate
329+ controller/generate : bin/controller-gen # # Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
330+ $(CONTROLLER_GEN ) object:headerFile=" ./cmd/controller/hack/boilerplate.go.txt" paths=" {./cmd/controller/..., ./internal/controller/...}"
331+
332+ .PHONY : controller/fmt
333+ controller/fmt : # # Run go fmt against code.
334+ go fmt ./cmd/controller/... ./internal/controller/...
335+
336+ .PHONY : controller/vet
337+ controller/vet : # # Run go vet against code.
338+ go vet ./cmd/controller/... ./internal/controller/...
339+
340+ .PHONY : controller/test
341+ controller/test : controller/manifests controller/generate controller/fmt controller/vet bin/envtest # # Run tests.
342+ KUBEBUILDER_ASSETS=" $( shell $( ENVTEST) use $( ENVTEST_K8S_VERSION) --bin-dir $( PROJECT_BIN) -p path) " go test $$(go list ./internal/controller/... | grep -v /e2e ) -coverprofile cover.out
343+
344+ # #@ Build
345+
346+ .PHONY : controller/build
347+ controller/build : controller/manifests controller/generate controller/fmt controller/vet # # Build manager binary.
348+ go build -o bin/manager cmd/controller/main.go
349+
350+ .PHONY : controller/run
351+ controller/run : controller/manifests controller/generate controller/fmt controller/vet # # Run a controller from your host.
352+ go run ./cmd/controller/main.go
353+
354+ # If you wish to build the manager image targeting other platforms you can use the --platform flag.
355+ # (i.e. docker build --platform linux/arm64). However, you must enable docker buildKit for it.
356+ # More info: https://docs.docker.com/develop/develop-images/build_enhancements/
357+ .PHONY : controller/docker-build
358+ controller/docker-build : # # Build docker image with the manager.
359+ $(DOCKER ) build -t ${IMG} -f ./cmd/controller/Dockerfile.controller .
360+
361+ .PHONY : controller/docker-push
362+ controller/docker-push : # # Push docker image with the manager.
363+ $(DOCKER ) push ${IMG}
364+
365+ # PLATFORMS defines the target platforms for the manager image be built to provide support to multiple
366+ # architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
367+ # - be able to use docker buildx. More info: https://docs.docker.com/build/buildx/
368+ # - have enabled BuildKit. More info: https://docs.docker.com/develop/develop-images/build_enhancements/
369+ # - be able to push the image to your registry (i.e. if you do not set a valid value via IMG=<myregistry/image:<tag>> then the export will fail)
370+ # To adequately provide solutions that are compatible with multiple platforms, you should consider using this option.
371+ PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
372+ .PHONY : controller/docker-buildx
373+ controller/docker-buildx : # # Build and push docker image for the manager for cross-platform support
374+ # copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
375+ sed -e ' 1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' ./cmd/controller/Dockerfile.controller > Dockerfile.cross
376+ - $(DOCKER ) buildx create --name controller-builder
377+ $(DOCKER ) buildx use controller-builder
378+ - $(DOCKER ) buildx build --push --platform=$(PLATFORMS ) --tag ${IMG} -f Dockerfile.cross .
379+ - $(DOCKER ) buildx rm controller-builder
380+ rm Dockerfile.cross
381+
382+ .PHONY : controller/build-installer
383+ controller/build-installer : controller/manifests controller/generate bin/kustomize # # Generate a consolidated YAML with CRDs and deployment.
384+ mkdir -p dist
385+ cd manifests/kustomize/options/controller/manager && $(KUSTOMIZE ) edit set image controller=${IMG}
386+ $(KUSTOMIZE ) build manifests/kustomize/options/controller/default > dist/install.yaml
387+
388+ # #@ Deployment
389+
390+ ifndef ignore-not-found
391+ ignore-not-found = false
392+ endif
393+
394+ .PHONY : controller/install
395+ controller/install : controller/manifests bin/kustomize # # Install CRDs into the K8s cluster specified in ~/.kube/config.
396+ $(KUSTOMIZE ) build manifests/kustomize/options/controller/crd | $(KUBECTL ) apply -f -
397+
398+ .PHONY : controller/uninstall
399+ controller/uninstall : controller/manifests bin/kustomize # # Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
400+ $(KUSTOMIZE ) build manifests/kustomize/options/controller/crd | $(KUBECTL ) delete --ignore-not-found=$(ignore-not-found ) -f -
401+
402+ .PHONY : controller/deploy
403+ controller/deploy : controller/manifests bin/kustomize # # Deploy controller to the K8s cluster specified in ~/.kube/config.
404+ cd manifests/kustomize/options/controller/manager && $(KUSTOMIZE ) edit set image ghcr.io/kubeflow/model-registry/controller=${IMG} :${IMG_VERSION}
405+ $(KUSTOMIZE ) build manifests/kustomize/options/controller/overlays/base | $(KUBECTL ) apply -f -
406+
407+ .PHONY : controller/undeploy
408+ controller/undeploy : bin/kustomize # # Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
409+ $(KUSTOMIZE ) build manifests/kustomize/options/controller/overlays/base | $(KUBECTL ) delete --ignore-not-found=$(ignore-not-found ) -f -
410+
411+ # #@ Tools
412+
413+ KUBECTL ?= kubectl
414+ CONTROLLER_GEN ?= $(PROJECT_BIN ) /controller-gen
415+ KUSTOMIZE ?= $(PROJECT_BIN ) /kustomize
416+ CONTROLLER_TOOLS_VERSION ?= v0.16.4
417+ KUSTOMIZE_VERSION ?= v5.5.0
418+
419+ .PHONY : bin/kustomize
420+ bin/kustomize : $(KUSTOMIZE ) # # Download kustomize locally if necessary.
421+ $(KUSTOMIZE ) : $(PROJECT_BIN )
422+ $(call go-install-tool,$(KUSTOMIZE ) ,sigs.k8s.io/kustomize/kustomize/v5,$(KUSTOMIZE_VERSION ) )
423+
424+ .PHONY : bin/controller-gen
425+ bin/controller-gen : $(CONTROLLER_GEN ) # # Download controller-gen locally if necessary.
426+ $(CONTROLLER_GEN ) : $(PROJECT_BIN )
427+ $(call go-install-tool,$(CONTROLLER_GEN ) ,sigs.k8s.io/controller-tools/cmd/controller-gen,$(CONTROLLER_TOOLS_VERSION ) )
428+
429+ # go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
430+ # $1 - target path with name of binary
431+ # $2 - package url which can be installed
432+ # $3 - specific version of package
433+ define go-install-tool
434+ @[ -f "$(1 ) -$(3 ) " ] || { \
435+ set -e; \
436+ package=$(2 ) @$(3 ) ;\
437+ echo "Downloading $${package}" ;\
438+ rm -f $(1 ) || true ;\
439+ GOBIN=$(PROJECT_BIN ) go install $${package} ;\
440+ mv $(1 ) $(1 ) -$(3 ) ;\
441+ } ;\
442+ ln -sf $(1 ) -$(3 ) $(1 )
443+ endef
0 commit comments