Skip to content

Commit

Permalink
Merge pull request opendatahub-io#38 from spolti/sync
Browse files Browse the repository at this point in the history
Sync
  • Loading branch information
openshift-merge-bot[bot] authored Nov 24, 2023
2 parents 79592e2 + 9633f2d commit b53c140
Show file tree
Hide file tree
Showing 27 changed files with 635 additions and 201 deletions.
81 changes: 81 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"

on:
push:
branches: ["main"]
pull_request:
# The branches below must be a subset of the branches above
branches: ["main"]
schedule:
- cron: "30 8 * * *"

jobs:
analyze:
name: Analyze
# Runner size impacts CodeQL analysis time. To learn more, please see:
# - https://gh.io/recommended-hardware-resources-for-running-codeql
# - https://gh.io/supported-runners-and-hardware-resources
# - https://gh.io/using-larger-runners
# Consider using larger runners for possible analysis time improvements.
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }}
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: ["go", "python"]
# CodeQL supports [ 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift' ]
# Use only 'java-kotlin' to analyze code written in Java, Kotlin or both
# Use only 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support

steps:
- name: Checkout repository
uses: actions/checkout@v3

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality

# Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun

# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.

# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: "/language:${{matrix.language}}"
16 changes: 11 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,19 @@ USER root
ENV HOME=/root

# Install build and dev tools
# NOTE: Require python38 to install pre-commit
RUN --mount=type=cache,target=/root/.cache/dnf:rw \
dnf install --setopt=cachedir=/root/.cache/dnf -y --nodocs \
python3 \
python3-pip \
nodejs \
python38 \
&& ln -sf /usr/bin/python3 /usr/bin/python \
&& ln -sf /usr/bin/pip3 /usr/bin/pip \
&& true

# Install pre-commit
ENV PIP_CACHE_DIR=/root/.cache/pip
RUN --mount=type=cache,target=/root/.cache/pip \
pip3 install pre-commit
pip install pre-commit

# When using the BuildKit backend, Docker predefines a set of ARG variables with
# information on the platform of the node performing the build (build platform)
Expand Down Expand Up @@ -77,9 +79,13 @@ WORKDIR /opt/app
COPY go.mod go.sum ./

# Install go protoc plugins
# no required module provides package google.golang.org/grpc/cmd/protoc-gen-go-grpc
# to add it run `go get google.golang.org/grpc/cmd/protoc-gen-go-grpc`
ENV PATH $HOME/go/bin:$PATH
RUN go get google.golang.org/protobuf/cmd/protoc-gen-go \
google.golang.org/grpc/cmd/protoc-gen-go-grpc \
RUN true \
&& go get google.golang.org/grpc/cmd/protoc-gen-go-grpc \
&& go install google.golang.org/protobuf/cmd/protoc-gen-go \
google.golang.org/grpc/cmd/protoc-gen-go-grpc \
&& protoc-gen-go --version \
&& true

Expand Down
9 changes: 7 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,19 @@ build:
build.develop:
./scripts/build_docker.sh --target develop

.PHONY: use.develop
## Check if developer image exists, build it if it doesn't
use.develop:
./scripts/build_docker.sh --target develop --use-existing

.PHONY: develop
## Run interactive shell inside developer container
develop: build.develop
develop: use.develop
./scripts/develop.sh

.PHONY: run
## Run make target inside developer container (e.g. `make run fmt`)
run: build.develop
run: use.develop
./scripts/develop.sh make $(RUN_ARGS)

.PHONY: test
Expand Down
185 changes: 181 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
[![Build](https://github.com/kserve/modelmesh-runtime-adapter/actions/workflows/build.yml/badge.svg?branch=main)](https://github.com/kserve/modelmesh-runtime-adapter/actions/workflows/build.yml)

# Modelmesh Runtime Adapter
# ModelMesh Runtime Adapter

This repo contains the unified puller/runtime-adapter image of the sidecar containers which run in the modelmesh-serving model server Pods. See the main [modelmesh-serving](https://github.com/kserve/modelmesh-serving) repo for more details.
This repo contains the unified puller/runtime-adapter image of the sidecar containers
which run in the ModelMesh Serving model server Pods. Take a look at the main
[ModelMesh Serving](https://github.com/kserve/modelmesh-serving) repo for more details.

Logical subcomponents within the image:

Expand All @@ -12,8 +14,183 @@ Logical subcomponents within the image:
- [model-mesh-ovms-adapter](model-mesh-ovms-adapter)
- [model-mesh-torchserve-adapter](model-mesh-torchserve-adapter)

### Build Image
## Generate sources

```bash
The gRPC code stubs, interfaces and data access classes have to be generated by the
[`protoc` compiler](https://protobuf.dev/getting-started/gotutorial/#compiling-protocol-buffers)
from the `.proto` source files under `internal/proto/*`.

If any of the `.proto` files were modified, run the `protoc` compiler to regenerate
the respective Go source code. It's recommended to use the developer image, which
has all the required libraries pre-installed, by running `make run proto.compile`
instead of `make proto.compile`.

```shell
make run proto.compile
```

## Test the code changes

After making code changes, ensure all existing and new functionality still works
properly by running the unit tests.

```shell
make test
```

## Format code

Run the linter to make sure all code style rules are adhered to. The code will
automatically be formatted if any code style violations are found.

It's recommended to use the developer image, which has all the required libraries
pre-installed, by running `make run fmt` instead of `make fmt`.

```shell
make run fmt
```

## Build the Docker image

Once the code changes have been tested and linted, build a new `modelmesh-runtime-adapter`
Docker image.

```shell
make build
```

## Push the image to a container registry

Push the newly built `modelmesh-runtime-adapter` image to a container registry.
Replace the value of the `DOCKER_USER` environment variable to your docker user ID
and change the `IMAGE_TAG` to something meaningful.

```bash
export DOCKER_USER="<your-docker-userid>"
export IMAGE_TAG="dev"

docker tag kserve/modelmesh-runtime-adapter:latest \
${DOCKER_USER}/modelmesh-runtime-adapter:${IMAGE_TAG}

docker push ${DOCKER_USER}/modelmesh-runtime-adapter:${IMAGE_TAG}
```

## Update the ModelMesh Serving deployment

In order to test the code changes in an existing [ModelMesh Serving](https://github.com/kserve/modelmesh-serving)
deployment, the newly built container image needs to be added to the
`model-serving-config` ConfigMap.

### Check existing model serving configuration

First, check if your ModelMesh Serving deployment already has an existing
`model-serving-config` ConfigMap:

```Shell
kubectl get configmap

NAME DATA AGE
kube-root-ca.crt 1 12d
model-serving-config 1 12d
model-serving-config-defaults 1 12d
tc-config 2 12d
```

### Create a new model serving config

If you did not already have a `model-serving-config` ConfigMap on your cluster,
you can create one. Replace the `<your-docker-userid>` placeholder with your
Docker username. Make sure the value of the `IMAGE_TAG` variable matches
the one that was pushed to the container registry.

```shell
export DOCKER_USER="<your-docker-userid>"
export IMAGE_NAME="${DOCKER_USER}/modelmesh-runtime-adapter"
export IMAGE_TAG="dev"

kubectl apply -f - <<EOF
---
apiVersion: v1
kind: ConfigMap
metadata:
name: model-serving-config
data:
config.yaml: |
storageHelperImage:
name: ${IMAGE_NAME}
tag: ${IMAGE_TAG}
EOF
```

### Update an existing model serving config

If the ConfigMap list contains `model-serving-config`, save the contents of your
existing configuration in a local temp file:

```Bash
mkdir -p temp
kubectl get configmap model-serving-config -o yaml > temp/model-serving-config.yaml
```

Add the `storageHelperImage` property to the `config.yaml` string property.

```YAML
storageHelperImage:
name: your-docker-userid/modelmesh-runtime-adapter
tag: latest
```
Replace the `your-docker-userid` placeholder with _your_ Docker username and make
sure the `tag` matches the one that was pushed to the container registry earlier.

The complete ConfigMap YAML file _may_ look like this:

```YAML
apiVersion: v1
kind: ConfigMap
metadata:
name: model-serving-config
namespace: modelmesh-serving
data:
config.yaml: |
podsPerRuntime: 1
restProxy:
enabled: true
scaleToZero:
enabled: false
gracePeriodSeconds: 5
storageHelperImage:
name: your-docker-userid/modelmesh-runtime-adapter
tag: dev
```

Apply the ConfigMap to your cluster:

```Bash
kubectl apply -f temp/model-serving-config.yaml
```

If you are comfortable using `vi`, you can forgo creating a temp file and edit
the ConfigMap directly in the terminal:

```Shell
kubectl edit configmap model-serving-config
```

### Verify the container images used by the model serving runtime

The `modelmesh-controller` watches the ConfigMap and responds to updates by
automatically restarting the serving runtime pods using the newly built
runtime adapter image.

You can check which container images are used by running the following command:

```Shell
kubectl get pods -o jsonpath='{range .items[*]}{"\n"}{.metadata.name}{"\t"}{range .spec.containers[*]}{.image}{", "}{end}{end}' | sort | column -ts $'\t' | sed 's/, *$//g'
etcd-78ff7867d5-45svw quay.io/coreos/etcd:v3.5.4
minio-6ddbfc9665-gtf7x kserve/modelmesh-minio-examples:latest
modelmesh-controller-64f5c8d6d6-k6rzc kserve/modelmesh-controller:latest
modelmesh-serving-mlserver-1.x-84884c6849-s8dw6 kserve/rest-proxy:latest, seldonio/mlserver:1.3.2, your-docker-userid/modelmesh-runtime-adapter:dev, kserve/modelmesh:latest
modelmesh-serving-mlserver-1.x-84884c6849-xpdw4 kserve/rest-proxy:latest, seldonio/mlserver:1.3.2, your-docker-userid/modelmesh-runtime-adapter:dev, kserve/modelmesh:latest
```
8 changes: 7 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ require (
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/oauth2 v0.7.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
Expand All @@ -67,3 +67,9 @@ require (
sigs.k8s.io/json v0.0.0-20211020170558-c049b76a60c6 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
)

// Update to avoid CVE-2022-27191, CVE-2021-43565, CVE-2020-29652
replace golang.org/x/crypto => golang.org/x/crypto v0.14.0

// Update to avoid CVE-2023-3978, CVE-2023-39325, CVE-2023-44487
replace golang.org/x/net => golang.org/x/net v0.17.0
Loading

0 comments on commit b53c140

Please sign in to comment.