|
| 1 | +# Developer Guide |
| 2 | + |
| 3 | +## Prerequisites |
| 4 | + |
| 5 | +You need [Java](https://openjdk.org/) and [Maven](https://maven.apache.org/guides/getting-started/maven-in-five-minutes.html#running-maven-tools) |
| 6 | +to build ModelMesh from source and [`etcd`](https://etcd.io/) to run the unit tests. |
| 7 | +To build your custom `modelmesh` container image and deploy it to a ModelMesh Serving installation on a Kubernetes cluster, |
| 8 | +you need the [`docker`](https://docs.docker.com/engine/reference/commandline/cli/) and |
| 9 | +[`kubectl`](https://kubectl.docs.kubernetes.io/references/kubectl/) CLIs. |
| 10 | +On `macOS` you can install the required CLIs with [Homebrew](https://brew.sh/): |
| 11 | + |
| 12 | +- Java: `brew install java` |
| 13 | +- Maven: `brew install maven` |
| 14 | +- Etcd: `brew install etcd` |
| 15 | +- Docker: `brew install docker` |
| 16 | +- Kubectl: `brew install kubectl` |
| 17 | + |
| 18 | +## Generating sources |
| 19 | + |
| 20 | +The gRPC stubs like the `ModelMeshGrpc` class have to be generated by the gRPC proto compiler from |
| 21 | +the `.proto` source files under `src/main/proto`. |
| 22 | +The generated sources should be created in the target directory `target/generated-sources/protobuf/grpc-java`. |
| 23 | + |
| 24 | +To generate the sources run either of the following commands: |
| 25 | + |
| 26 | +```shell |
| 27 | +mvn package -DskipTests |
| 28 | +mvn install -DskipTests |
| 29 | +``` |
| 30 | + |
| 31 | +## Project setup using an IDE |
| 32 | + |
| 33 | +If you are using an IDE like [IntelliJ IDEA](https://www.jetbrains.com/idea/) or [Eclipse](https://eclipseide.org/) |
| 34 | +to help with your code development you should set up source and target folders so that the IDE's compiler can find all |
| 35 | +the source code including the generated sources (after running `mvn install -DskipTests`). |
| 36 | + |
| 37 | +For IntelliJ this can be done by going to **File > Project Structure ... > Modules**: |
| 38 | + |
| 39 | +- **Source Folders** |
| 40 | + - src/main/java |
| 41 | + - src/main/proto |
| 42 | + - target/generated-sources/protobuf/grpc-java (generated) |
| 43 | + - target/generated-sources/protobuf/java (generated) |
| 44 | +- **Test Source Folders** |
| 45 | + - src/test/java |
| 46 | + - target/generated-test-sources/protobuf/grpc-java (generated) |
| 47 | + - target/generated-test-sources/protobuf/java (generated) |
| 48 | +- **Resource Folders** |
| 49 | + - src/main/resources |
| 50 | +- **Test Resource Folders** |
| 51 | + - src/test/resources |
| 52 | +- **Excluded Folders** |
| 53 | + - target |
| 54 | + |
| 55 | +You may also want to increase your Java Heap size to at least 1.5 GB. |
| 56 | + |
| 57 | +## Testing code changes |
| 58 | + |
| 59 | +**Note**, before running the test cases, make sure you have `etcd` installed (see #prerequisites): |
| 60 | + |
| 61 | +```Bash |
| 62 | +$ etcd --version |
| 63 | + |
| 64 | +etcd Version: 3.5.5 |
| 65 | +Git SHA: 19002cfc6 |
| 66 | +Go Version: go1.19.1 |
| 67 | +Go OS/Arch: darwin/amd64 |
| 68 | +``` |
| 69 | + |
| 70 | +You can either run all test suites at once. You can use the `-q` flag to reduce noise: |
| 71 | + |
| 72 | +```Bash |
| 73 | +mvn test -q |
| 74 | +``` |
| 75 | + |
| 76 | +Or you can run individual test cases: |
| 77 | + |
| 78 | +```Bash |
| 79 | +mvn test -Dtest=ModelMeshErrorPropagationTest |
| 80 | +mvn test -Dtest=SidecarModelMeshTest,ModelMeshFailureExpiryTest |
| 81 | +``` |
| 82 | + |
| 83 | +It can be handy to use `grep` to reduce output noise: |
| 84 | + |
| 85 | +```Bash |
| 86 | +mvn test -Dtest=SidecarModelMeshTest,ModelMeshFailureExpiryTest | \ |
| 87 | + grep -E " Running |\[ERROR\]|Failures|SUCCESS|Skipp|Total time|Finished" |
| 88 | + |
| 89 | +[INFO] Running com.ibm.watson.modelmesh.ModelMeshFailureExpiryTest |
| 90 | +[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 10.257 s - in com.ibm.watson.modelmesh.ModelMeshFailureExpiryTest |
| 91 | +[INFO] Running com.ibm.watson.modelmesh.SidecarModelMeshTest |
| 92 | +[INFO] Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 17.302 s - in com.ibm.watson.modelmesh.SidecarModelMeshTest |
| 93 | +[INFO] Tests run: 4, Failures: 0, Errors: 0, Skipped: 0 |
| 94 | +[INFO] BUILD SUCCESS |
| 95 | +[INFO] Total time: 39.916 s |
| 96 | +[INFO] Finished at: 2022-11-01T14:33:33-07:00 |
| 97 | +``` |
| 98 | + |
| 99 | +## Building the container image |
| 100 | + |
| 101 | +After testing your code changes locally, it's time to build a new `modelmesh` container image. Replace the value of the |
| 102 | +`DOCKER_USER` environment variable to your DockerHub user ID and change the `IMAGE_TAG` to something meaningful. |
| 103 | + |
| 104 | +```bash |
| 105 | +export DOCKER_USER="<your-docker-userid>" |
| 106 | +export IMAGE_NAME="${DOCKER_USER}/modelmesh" |
| 107 | +export IMAGE_TAG="dev" |
| 108 | +export GIT_COMMIT=$(git rev-parse HEAD) |
| 109 | +export BUILD_ID=$(date '+%Y%m%d')-$(git rev-parse HEAD | cut -c -5) |
| 110 | + |
| 111 | +docker build -t ${IMAGE_NAME}:${IMAGE_TAG} \ |
| 112 | + --build-arg imageVersion=${IMAGE_TAG} \ |
| 113 | + --build-arg buildId=${BUILD_ID} \ |
| 114 | + --build-arg commitSha=${GIT_COMMIT} . |
| 115 | + |
| 116 | +docker push ${IMAGE_NAME}:${IMAGE_TAG} |
| 117 | +``` |
| 118 | + |
| 119 | +## Updating the ModelMesh Serving deployment |
| 120 | + |
| 121 | +In order to test the code changes in an existing [ModelMesh Serving](https://github.com/kserve/modelmesh-serving) deployment, |
| 122 | +the newly built container image needs to be added to the `model-serving-config` ConfigMap. |
| 123 | + |
| 124 | +First, check if your ModelMesh Serving deployment already has an existing `model-serving-config` ConfigMap: |
| 125 | + |
| 126 | +```Shell |
| 127 | +kubectl get configmap |
| 128 | + |
| 129 | +NAME DATA AGE |
| 130 | +kube-root-ca.crt 1 4d2h |
| 131 | +model-serving-config 1 4m14s |
| 132 | +model-serving-config-defaults 1 4d2h |
| 133 | +tc-config 2 4d2h |
| 134 | +``` |
| 135 | + |
| 136 | +If the ConfigMap list contains `model-serving-config`, save the contents of your existing configuration |
| 137 | +in a local temp file: |
| 138 | + |
| 139 | +```Bash |
| 140 | +mkdir -p temp |
| 141 | +kubectl get configmap model-serving-config -o yaml > temp/model-serving-config.yaml |
| 142 | +``` |
| 143 | + |
| 144 | +And add the `modelMeshImage` property to the `config.yaml` string property: |
| 145 | +```YAML |
| 146 | + modelMeshImage: |
| 147 | + name: <your-docker-userid>/modelmesh |
| 148 | + tag: dev |
| 149 | +``` |
| 150 | +
|
| 151 | +Replace the `<your-docker-userid>` placeholder with your Docker username/login. |
| 152 | + |
| 153 | +The complete ConfigMap YAML file might look like this: |
| 154 | + |
| 155 | +```YAML |
| 156 | +apiVersion: v1 |
| 157 | +kind: ConfigMap |
| 158 | +metadata: |
| 159 | + name: model-serving-config |
| 160 | + namespace: modelmesh-serving |
| 161 | +data: |
| 162 | + config.yaml: | |
| 163 | + podsPerRuntime: 1 |
| 164 | + restProxy: |
| 165 | + enabled: true |
| 166 | + scaleToZero: |
| 167 | + enabled: false |
| 168 | + gracePeriodSeconds: 5 |
| 169 | + modelMeshImage: |
| 170 | + name: <your-docker-userid>/modelmesh |
| 171 | + tag: dev |
| 172 | +``` |
| 173 | + |
| 174 | +Apply the ConfigMap to your cluster: |
| 175 | + |
| 176 | +```Bash |
| 177 | +kubectl apply -f temp/model-serving-config.yaml |
| 178 | +``` |
| 179 | + |
| 180 | +If you are comfortable using vi, you can forgo creating a temp file and edit the ConfigMap directly in the terminal: |
| 181 | + |
| 182 | +```Shell |
| 183 | +kubectl edit configmap model-serving-config |
| 184 | +``` |
| 185 | + |
| 186 | +If you did not already have a `model-serving-config` ConfigMap on your cluster, you can create one like this: |
| 187 | + |
| 188 | +```shell |
| 189 | +# export DOCKER_USER="<your-docker-userid>" |
| 190 | +# export IMAGE_NAME="${DOCKER_USER}/modelmesh" |
| 191 | +# export IMAGE_TAG="dev" |
| 192 | +
|
| 193 | +kubectl apply -f - <<EOF |
| 194 | +--- |
| 195 | +apiVersion: v1 |
| 196 | +kind: ConfigMap |
| 197 | +metadata: |
| 198 | + name: model-serving-config |
| 199 | +data: |
| 200 | + config.yaml: | |
| 201 | + modelMeshImage: |
| 202 | + name: ${IMAGE_NAME} |
| 203 | + tag: ${IMAGE_TAG} |
| 204 | +EOF |
| 205 | +``` |
| 206 | + |
| 207 | +The `modelmesh-controller` watches the ConfigMap and responds to updates by automatically restarting the serving runtime |
| 208 | +pods using the newly built `modelmesh` container image. |
| 209 | + |
| 210 | +You can check which container images are used by running the following command: |
| 211 | + |
| 212 | +```Shell |
| 213 | +kubectl get pods -o jsonpath='{range .items[*]}{"\n"}{.metadata.name}{"\t"}{range .spec.containers[*]}{.image}{", "}{end}{end}' | sort | column -ts $'\t' | sed 's/, *$//g' |
| 214 | +
|
| 215 | +etcd-78ff7867d5-45svw quay.io/coreos/etcd:v3.5.4 |
| 216 | +minio-6ddbfc9665-gtf7x kserve/modelmesh-minio-examples:latest |
| 217 | +modelmesh-controller-64f5c8d6d6-k6rzc kserve/modelmesh-controller:latest |
| 218 | +modelmesh-serving-mlserver-1.x-84884c6849-s8dw6 kserve/rest-proxy:latest, seldonio/mlserver:1.3.2, kserve/modelmesh-runtime-adapter:latest, kserve/modelmesh:dev |
| 219 | +modelmesh-serving-mlserver-1.x-84884c6849-xpdw4 kserve/rest-proxy:latest, seldonio/mlserver:1.3.2, kserve/modelmesh-runtime-adapter:latest, kserve/modelmesh:dev |
| 220 | +``` |
0 commit comments