Skip to content

Commit a5f1fea

Browse files
Al-Pragliolapboyd
andauthored
feat(controller): introduce inferenceservice controller (kubeflow#917)
* feat(controller): introduce inferenceservice controller in model registry repo Signed-off-by: Alessio Pragliola <seth.pro@gmail.com> * fix(controller): go.mod version Signed-off-by: Alessio Pragliola <seth.pro@gmail.com> * feat(controller): added controller to devenv Signed-off-by: Alessio Pragliola <seth.pro@gmail.com> * fix(controller): container images Signed-off-by: Alessio Pragliola <seth.pro@gmail.com> * fix: edited Makefile lines by mistake Signed-off-by: Alessio Pragliola <seth.pro@gmail.com> * chore(controller): edit boilerplate files Signed-off-by: Alessio Pragliola <seth.pro@gmail.com> * feat(controller): apply suggestions from code review Co-authored-by: Paul Boyd <paul@camelot.email> Signed-off-by: Alessio Pragliola <83355398+Al-Pragliola@users.noreply.github.com> * chore(controller): remove license banners Signed-off-by: Alessio Pragliola <seth.pro@gmail.com> --------- Signed-off-by: Alessio Pragliola <seth.pro@gmail.com> Signed-off-by: Alessio Pragliola <83355398+Al-Pragliola@users.noreply.github.com> Co-authored-by: Paul Boyd <paul@camelot.email>
1 parent e0afd3b commit a5f1fea

37 files changed

Lines changed: 1453 additions & 5 deletions
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Test Controller
2+
on:
3+
push:
4+
branches:
5+
- "main"
6+
paths-ignore:
7+
- "LICENSE*"
8+
- "**.gitignore"
9+
- "**.md"
10+
- "**.txt"
11+
- ".github/ISSUE_TEMPLATE/**"
12+
- ".github/dependabot.yml"
13+
- "docs/**"
14+
pull_request:
15+
paths:
16+
- "cmd/controller/**"
17+
- "internal/controller/**"
18+
- "internal/server/openapi/api_model_registry_service*"
19+
- "pkg/openapi/**"
20+
- "go.mod"
21+
22+
env:
23+
BRANCH: ${{ github.base_ref }}
24+
jobs:
25+
test:
26+
name: Run on Ubuntu
27+
runs-on: ubuntu-latest
28+
steps:
29+
- name: Clone the code
30+
uses: actions/checkout@v4
31+
32+
- name: Setup Go
33+
uses: actions/setup-go@v5
34+
with:
35+
go-version: '~1.22'
36+
37+
- name: Running Tests
38+
run: |
39+
go mod tidy
40+
make controller/test

Makefile

Lines changed: 134 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ PROJECT_BIN := $(PROJECT_PATH)/bin
55
GO ?= "$(shell which go)"
66
UI_PATH := $(PROJECT_PATH)/clients/ui
77
CSI_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.
1011
ENVTEST_K8S_VERSION = 1.29
@@ -47,6 +48,11 @@ ifeq ($(IMG_REPO),model-registry/storage-initializer)
4748
DOCKERFILE := $(CSI_PATH)/Dockerfile.csi
4849
endif
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+
5056
model-registry: build
5157

5258
# clean the ml-metadata protos and trigger a fresh new build which downloads
@@ -133,7 +139,7 @@ clean-pkg-openapi:
133139
clean-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
137143
clean: 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

310316
all: 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

cmd/controller/.dockerignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
2+
# Ignore build and test binaries.
3+
bin/

cmd/controller/.gitignore

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Binaries for programs and plugins
2+
*.exe
3+
*.exe~
4+
*.dll
5+
*.so
6+
*.dylib
7+
bin/*
8+
Dockerfile.cross
9+
10+
# Test binary, built with `go test -c`
11+
*.test
12+
13+
# Output of the go coverage tool, specifically when used with LiteIDE
14+
*.out
15+
16+
# Go workspace file
17+
go.work
18+
19+
# Kubernetes Generated files - skip generated files, except for vendored files
20+
!vendor/**/zz_generated.*
21+
22+
# editor and IDE paraphernalia
23+
.idea
24+
.vscode
25+
*.swp
26+
*.swo
27+
*~
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Build the manager binary
2+
FROM --platform=$BUILDPLATFORM registry.access.redhat.com/ubi8/go-toolset:1.22 AS builder
3+
ARG TARGETOS
4+
ARG TARGETARCH
5+
6+
WORKDIR /workspace
7+
# Copy the Go Modules manifests
8+
COPY go.mod go.mod
9+
COPY go.sum go.sum
10+
# cache deps before building and copying source so that we don't need to re-download as much
11+
# and so that source changes don't invalidate our downloaded layer
12+
RUN go mod download
13+
14+
# Copy the go source
15+
COPY cmd/controller/*.go cmd/controller/
16+
COPY api/ api/
17+
COPY internal/controller internal/controller
18+
COPY pkg/ pkg/
19+
20+
# Build
21+
22+
USER root
23+
24+
# the GOARCH has not a default value to allow the binary be built according to the host where the command
25+
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
26+
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
27+
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
28+
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/controller/main.go
29+
30+
FROM registry.access.redhat.com/ubi8/ubi-minimal:latest
31+
WORKDIR /
32+
COPY --from=builder /workspace/manager .
33+
USER 65532:65532
34+
35+
ENTRYPOINT ["/manager"]

cmd/controller/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# controller
2+
// TODO(user): Add simple overview of use/purpose
3+
4+
## Description
5+
// TODO(user): An in-depth paragraph about your project and overview of use
6+
7+
## Getting Started
8+
9+
### Prerequisites
10+
- go version v1.22.0+
11+
- kubectl version v1.11.3+.
12+
- Access to a Kubernetes v1.11.3+ cluster.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/*
2+
*/

0 commit comments

Comments
 (0)