Skip to content

Commit

Permalink
Restructure the CSI as different executable
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Lamparelli <a.lamparelli95@gmail.com>
  • Loading branch information
lampajr committed Nov 29, 2024
1 parent 4099d46 commit 14f9f2b
Show file tree
Hide file tree
Showing 24 changed files with 113 additions and 615 deletions.
1 change: 0 additions & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ updates:
directories:
- "/"
- "/clients/ui/bff/"
- "/csi"
schedule:
interval: "weekly"
- package-ecosystem: "pip"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,13 @@ jobs:
run: make docker/login
# build & push
- name: Build CSI Image
working-directory: ./csi
shell: bash
env:
IMG_ORG: ${{ env.IMG_ORG }}
IMG_REPO: ${{ env.IMG_REPO }}
IMG_VERSION: ${{ env.VERSION }}
run: |
make docker-build-dev
make image/build
- name: Push CSI Image
if: env.PUSH_IMAGE == 'true'
shell: bash
Expand Down
10 changes: 4 additions & 6 deletions .github/workflows/csi-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on:
- "docs/**"
pull_request:
paths:
- "csi/**"
- "clients/csi/**"
- "internal/server/openapi/api_model_registry_service*"
- "pkg/openapi/**"
# csi build depends on base go.mod https://github.com/kubeflow/model-registry/issues/311
Expand Down Expand Up @@ -51,26 +51,24 @@ jobs:
run: ./scripts/build_deploy.sh

- name: Build local custom storage initializer
working-directory: ./csi
shell: bash
env:
IMG_REPO: ${{ env.MODEL_REGISTRY_CSI_IMG }}
IMG_VERSION: ${{ steps.tags.outputs.tag }}
run: make docker-build-dev
run: make image/build

- name: Start KinD cluster
uses: helm/kind-action@v1.10.0
with:
node_image: "kindest/node:v1.27.11"

- name: Install kustomize
run: ./csi/scripts/install_kustomize.sh
run: ./test/scripts/install_kustomize.sh

- name: Run tests
working-directory: ./csi
shell: bash
env:
MR_IMG: "${{ env.IMG_ORG }}/${{ env.MODEL_REGISTRY_IMG }}:${{ steps.tags.outputs.tag }}"
MR_CSI_IMG: "${{ env.IMG_ORG }}/${{ env.MODEL_REGISTRY_CSI_IMG }}:${{ steps.tags.outputs.tag }}"
CLUSTER: chart-testing
run: ./test/e2e_test.sh
run: ./test/csi/e2e_test.sh
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,9 @@ readme.txt

#OSX files
**/.DS_Store

# CSI executable
mr-storage-initializer

# KServe manifests
istio-*
56 changes: 56 additions & 0 deletions Dockerfile.csi
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Build the model-registry CSI binary
FROM --platform=$BUILDPLATFORM registry.access.redhat.com/ubi8/go-toolset:1.22 AS builder
ARG TARGETOS
ARG TARGETARCH

WORKDIR /workspace
# Copy the Go Modules manifests
COPY ["go.mod", "go.sum", "./"]
# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
RUN go mod download

USER root
# default NodeJS 14 is not enough for openapi-generator-cli, switch to Node JS currently supported
RUN yum remove -y nodejs npm
RUN yum module -y reset nodejs
RUN yum module -y enable nodejs:18
# install npm and java for openapi-generator-cli
RUN yum install -y nodejs npm java-11 python3

# Copy the go source
COPY ["Makefile", "main.go", ".openapi-generator-ignore", "openapitools.json", "./"]

# Copy rest of the source
COPY cmd/ cmd/
COPY api/ api/
COPY internal/ internal/
COPY scripts/ scripts/
COPY pkg/ pkg/
COPY patches/ patches/
COPY templates/ templates/
# csi specific source code
COPY clients/csi/main.go clients/csi/
COPY clients/csi/pkg/ clients/csi/pkg/

# Download tools
RUN make deps

# NOTE: The two instructions below are effectively equivalent to 'make clean build'
# DO NOT REMOVE THE 'build/prepare' TARGET!!!
# It ensures consitent repeatable Dockerfile builds

# prepare the build in a separate layer
RUN make clean build/prepare/csi
# compile separately to optimize multi-platform builds
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} make build/compile/csi

# Use distroless as minimal base image to package the model-registry binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM registry.access.redhat.com/ubi8/ubi-minimal:latest
WORKDIR /
# copy the storage initializer binary
COPY --from=builder /workspace/mr-storage-initializer .
USER 65532:65532

ENTRYPOINT ["/mr-storage-initializer"]
30 changes: 27 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ PROJECT_BIN := $(PROJECT_PATH)/bin
GO ?= "$(shell which go)"
BFF_PATH := $(PROJECT_PATH)/clients/ui/bff
UI_PATH := $(PROJECT_PATH)/clients/ui/frontend
CSI_PATH := $(PROJECT_PATH)/clients/csi

# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.29
Expand Down Expand Up @@ -47,6 +48,11 @@ ifeq ($(IMG_REPO),model-registry-bff)
BUILD_PATH := $(BFF_PATH)
endif

# The BUILD_PATH is still the root
ifeq ($(IMG_REPO),model-registry-storage-initializer)
DOCKERFILE := Dockerfile.csi
endif

model-registry: build

# clean the ml-metadata protos and trigger a fresh new build which downloads
Expand Down Expand Up @@ -114,11 +120,15 @@ pkg/openapi/client.go: bin/openapi-generator-cli api/openapi/model-registry.yaml
vet:
${GO} vet ./...

.PHONY: clean/csi
clean/csi:
rm -Rf ./mr-storage-initializer

.PHONY: clean-pkg-openapi
while IFS= read -r file; do rm -f "pkg/openapi/$file"; done < pkg/openapi/.openapi-generator/FILES

.PHONY: clean clean-pkg-openapi
clean:
.PHONY: clean
clean: clean-pkg-openapi clean/csi
rm -Rf ./model-registry internal/ml_metadata/proto/*.go internal/converter/generated/*.go internal/server/openapi/api_model_registry_service.go

.PHONY: clean/odh
Expand Down Expand Up @@ -197,6 +207,16 @@ build: build/prepare build/compile
build/odh: vet
${GO} build -buildvcs=false

.PHONY: build/prepare/csi
build/prepare/csi: build/prepare lint/csi

.PHONY: build/compile/csi
build/compile/csi:
${GO} build -buildvcs=false -o mr-storage-initializer ${CSI_PATH}/main.go

.PHONY: build/csi
build/csi: build/prepare/csi build/compile/csi

.PHONY: gen
gen: deps gen/grpc gen/openapi gen/openapi-server gen/converter
${GO} generate ./...
Expand All @@ -206,6 +226,11 @@ lint:
${GOLANGCI_LINT} run main.go
${GOLANGCI_LINT} run cmd/... internal/... ./pkg/...

.PHONY: lint/csi
lint/csi:
${GOLANGCI_LINT} run ${CSI_PATH}/main.go
${GOLANGCI_LINT} run ${CSI_PATH}/pkg/...

.PHONY: test
test: gen bin/envtest
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" ${GO} test ./internal/... ./pkg/...
Expand Down Expand Up @@ -236,7 +261,6 @@ else
$(DOCKER) login -u "${DOCKER_USER}" -p "${DOCKER_PWD}"
endif


# build docker image
.PHONY: image/build
image/build:
Expand Down
27 changes: 9 additions & 18 deletions csi/GET_STARTED.md → clients/csi/GET_STARTED.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Embark on your journey with this custom storage initializer by exploring a simpl

We assume all [prerequisites](#prerequisites) are satisfied at this point.

All the following instructions should be performed from the model-registry root directory.

### Create the environment

1. After having kind installed, create a kind cluster with:
Expand All @@ -35,38 +37,27 @@ We assume all [prerequisites](#prerequisites) are satisfied at this point.

```bash
TAG=$(git rev-parse HEAD) && \
MR_IMG=quay.io/$USER/model-registry:$TAG && \
make -C ../ IMG_ORG=$USER IMG_VERSION=$TAG image/build && \
MR_IMG=kubeflow/model-registry:$TAG && \
make IMG_VERSION=$TAG image/build && \
kind load docker-image $MR_IMG
```
or
```bash
TAG=... && \
MR_IMG=kubeflow/model-registry:$TAG
```

then:

```bash
bash ./scripts/install_modelregistry.sh -i $MR_IMG
bash ./test/scripts/install_modelregistry.sh -i $MR_IMG
```

> [!NOTE]
> The `./scripts/install_modelregistry.sh` will make some change to [base/kustomization.yaml](../manifests/kustomize/base/kustomization.yaml) that you DON'T need to commit!!
> The `./test/scripts/install_modelregistry.sh` will make some change to [base/kustomization.yaml](../manifests/kustomize/base/kustomization.yaml) that you DON'T need to commit!!
5. [Optional] Use local CSI container image
Either, using the local model-registry library as dependency:
```bash
IMG=$USER/model-registry-storage-initializer:$(git rev-parse HEAD) && \
make IMG=$IMG docker-build-dev && \
kind load docker-image $IMG
```
Or using a fixed version of model-registry library:
```bash
IMG=$USER/model-registry-storage-initializer:$(git rev-parse HEAD) && \
make IMG=$IMG docker-build && \
TAG=$(git rev-parse HEAD)
IMG=kubeflow/model-registry-storage-initializer:$TAG && \
make IMG_VERSION=$TAG IMG_REPO=model-registry-storage-initializer image/build && \
kind load docker-image $IMG
```
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions csi/main.go → clients/csi/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"log"
"os"

"github.com/kubeflow/model-registry/csi/pkg/modelregistry"
"github.com/kubeflow/model-registry/csi/pkg/storage"
"github.com/kubeflow/model-registry/clients/csi/pkg/modelregistry"
"github.com/kubeflow/model-registry/clients/csi/pkg/storage"
"github.com/kubeflow/model-registry/pkg/openapi"
)

Expand Down Expand Up @@ -48,6 +48,6 @@ func main() {
}

if err := provider.DownloadModel(destPath, "", sourceUri); err != nil {
log.Fatalf(err.Error())
log.Fatalf("Error downloading the model: %s", err.Error())
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"log"
"strings"

"github.com/kubeflow/model-registry/csi/pkg/constants"
"github.com/kubeflow/model-registry/clients/csi/pkg/constants"
"github.com/kubeflow/model-registry/pkg/openapi"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"strings"

kserve "github.com/kserve/kserve/pkg/agent/storage"
"github.com/kubeflow/model-registry/csi/pkg/constants"
"github.com/kubeflow/model-registry/clients/csi/pkg/constants"
"github.com/kubeflow/model-registry/pkg/openapi"
)

Expand Down
22 changes: 0 additions & 22 deletions csi/.gitignore

This file was deleted.

35 changes: 0 additions & 35 deletions csi/Dockerfile

This file was deleted.

Loading

0 comments on commit 14f9f2b

Please sign in to comment.