|
| 1 | +#!/usr/bin/env bash |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +# This is a helper script to run E2E tests on the openshift-ci operator. |
| 16 | +# This script assumes to be run inside a container/machine that has |
| 17 | +# python pre-installed and the `oc` command available. Additional tooling, |
| 18 | +# like kustomize and the mc client are installed by the script if not available. |
| 19 | +# The oc CLI is assumed to be configured with the credentials of the |
| 20 | +# target cluster. The target cluster is assumed to be a clean cluster. |
| 21 | +set -o errexit |
| 22 | +set -o nounset |
| 23 | +set -o pipefail |
| 24 | + |
| 25 | +: "${SKLEARN_IMAGE:=kserve/sklearnserver:latest}" |
| 26 | +: "${KSERVE_CONTROLLER_IMAGE:=quay.io/opendatahub/kserve-controller:latest}" |
| 27 | +: "${KSERVE_AGENT_IMAGE:=quay.io/opendatahub/kserve-agent:latest}" |
| 28 | +: "${KSERVE_ROUTER_IMAGE:=quay.io/opendatahub/kserve-router:latest}" |
| 29 | +: "${STORAGE_INITIALIZER_IMAGE:=quay.io/opendatahub/kserve-storage-initializer:latest}" |
| 30 | + |
| 31 | +echo "SKLEARN_IMAGE=$SKLEARN_IMAGE" |
| 32 | +echo "KSERVE_CONTROLLER_IMAGE=$KSERVE_CONTROLLER_IMAGE" |
| 33 | +echo "KSERVE_AGENT_IMAGE=$KSERVE_AGENT_IMAGE" |
| 34 | +echo "KSERVE_ROUTER_IMAGE=$KSERVE_ROUTER_IMAGE" |
| 35 | +echo "STORAGE_INITIALIZER_IMAGE=$STORAGE_INITIALIZER_IMAGE" |
| 36 | + |
| 37 | +# Create directory for installing tooling |
| 38 | +# It is assumed that $HOME/.local/bin is in the $PATH |
| 39 | +mkdir -p $HOME/.local/bin |
| 40 | +MY_PATH=$(dirname "$0") |
| 41 | +PROJECT_ROOT=$MY_PATH/../../../ |
| 42 | + |
| 43 | +# If Kustomize is not installed, install it |
| 44 | +if ! command -v kustomize &>/dev/null; then |
| 45 | + echo "Installing Kustomize" |
| 46 | + curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash -s -- 5.0.1 $HOME/.local/bin |
| 47 | +fi |
| 48 | + |
| 49 | +# If minio CLI is not installed, install it |
| 50 | +if ! command -v mc &>/dev/null; then |
| 51 | + echo "Installing Minio CLI" |
| 52 | + curl https://dl.min.io/client/mc/release/linux-amd64/mc --create-dirs -o $HOME/.local/bin/mc |
| 53 | + chmod +x $HOME/.local/bin/mc |
| 54 | +fi |
| 55 | + |
| 56 | +echo "Installing KServe Python SDK ..." |
| 57 | +pushd $PROJECT_ROOT >/dev/null |
| 58 | + ./test/scripts/gh-actions/setup-poetry.sh |
| 59 | + ./test/scripts/gh-actions/check-poetry-lockfile.sh |
| 60 | +popd |
| 61 | +pushd $PROJECT_ROOT/python/kserve >/dev/null |
| 62 | + poetry install --with=test --no-interaction |
| 63 | +popd |
| 64 | + |
| 65 | +# Install KServe stack |
| 66 | +if [ "$1" != "raw" ]; then |
| 67 | + echo "Installing OSSM" |
| 68 | + $MY_PATH/deploy.ossm.sh |
| 69 | + echo "Installing Serverless" |
| 70 | + $MY_PATH/deploy.serverless.sh |
| 71 | +fi |
| 72 | + |
| 73 | +echo "Installing KServe with Minio" |
| 74 | +kustomize build $PROJECT_ROOT/config/overlays/test | |
| 75 | + sed "s|kserve/storage-initializer:latest|${STORAGE_INITIALIZER_IMAGE}|" | |
| 76 | + sed "s|kserve/agent:latest|${KSERVE_AGENT_IMAGE}|" | |
| 77 | + sed "s|kserve/router:latest|${KSERVE_ROUTER_IMAGE}|" | |
| 78 | + sed "s|kserve/kserve-controller:latest|${KSERVE_CONTROLLER_IMAGE}|" | |
| 79 | + oc apply --server-side=true -f - |
| 80 | + |
| 81 | +# Install DSC/DSCI for test. (sometimes there is timing issue when it is under the same kustomization so it is separated) |
| 82 | +oc create -f config/overlays/test/dsci.yaml |
| 83 | +oc create -f config/overlays/test/dsc.yaml |
| 84 | + |
| 85 | +# Patch the inferenceservice-config ConfigMap, when running RawDeployment tests |
| 86 | +if [ "$1" == "raw" ]; then |
| 87 | + export OPENSHIFT_INGRESS_DOMAIN=$(oc get ingresses.config cluster -o jsonpath='{.spec.domain}') |
| 88 | + oc patch configmap inferenceservice-config -n kserve --patch-file <(cat config/overlays/test/configmap/inferenceservice-openshift-ci-raw.yaml | envsubst) |
| 89 | + oc delete pod -n kserve -l control-plane=kserve-controller-manager |
| 90 | + |
| 91 | + oc patch DataScienceCluster test-dsc --type='json' -p='[{"op": "replace", "path": "/spec/components/kserve/defaultDeploymentMode", "value": "RawDeployment"}]' |
| 92 | +else |
| 93 | + export OPENSHIFT_INGRESS_DOMAIN=$(oc get ingresses.config cluster -o jsonpath='{.spec.domain}') |
| 94 | + oc patch configmap inferenceservice-config -n kserve --patch-file <(cat config/overlays/test/configmap/inferenceservice-openshift-ci-serverless.yaml | envsubst) |
| 95 | +fi |
| 96 | + |
| 97 | +# Wait until KServe starts |
| 98 | +oc wait --for=condition=ready pod -l control-plane=kserve-controller-manager -n kserve --timeout=300s |
| 99 | + |
| 100 | +if [ "$1" != "raw" ]; then |
| 101 | + echo "Installing odh-model-controller" |
| 102 | + # authorino |
| 103 | + curl -sL https://raw.githubusercontent.com/Kuadrant/authorino-operator/main/utils/install.sh | sed "s|kubectl|oc|" | |
| 104 | + bash -s -- -v 0.16.0 |
| 105 | + |
| 106 | + # kserve-local-gateway |
| 107 | + curl https://raw.githubusercontent.com/opendatahub-io/opendatahub-operator/bde4b4e8478b5d03195e2777b9d550922e3cdcbc/components/kserve/resources/servicemesh/routing/istio-kserve-local-gateway.tmpl.yaml | |
| 108 | + sed "s/{{ .ControlPlane.Namespace }}/istio-system/g" | |
| 109 | + oc create -f - |
| 110 | + |
| 111 | + curl https://raw.githubusercontent.com/opendatahub-io/opendatahub-operator/bde4b4e8478b5d03195e2777b9d550922e3cdcbc/components/kserve/resources/servicemesh/routing/kserve-local-gateway-svc.tmpl.yaml | |
| 112 | + sed "s/{{ .ControlPlane.Namespace }}/istio-system/g" | |
| 113 | + oc create -f - |
| 114 | + |
| 115 | + oc apply -k $PROJECT_ROOT/test/scripts/openshift-ci |
| 116 | +fi |
| 117 | + |
| 118 | +echo "Add testing models to minio storage ..." # Reference: config/overlays/test/minio/minio-init-job.yaml |
| 119 | +oc expose service minio-service -n kserve && sleep 5 |
| 120 | +MINIO_ROUTE=$(oc get routes -n kserve minio-service -o jsonpath="{.spec.host}") |
| 121 | +mc alias set storage http://$MINIO_ROUTE minio minio123 |
| 122 | + |
| 123 | +if ! mc ls storage/example-models >/dev/null 2>&1; then |
| 124 | + mc mb storage/example-models |
| 125 | +else |
| 126 | + echo "Bucket 'example-models' already exists." |
| 127 | +fi |
| 128 | + |
| 129 | +if [[ $(mc ls storage/example-models/sklearn/model.joblib |wc -l) == "1" ]]; then |
| 130 | + echo "Test model exists" |
| 131 | +else |
| 132 | + echo "Copy test model" |
| 133 | + curl -L https://storage.googleapis.com/kfserving-examples/models/sklearn/1.0/model/model.joblib -o /tmp/sklearn-model.joblib |
| 134 | + mc cp /tmp/sklearn-model.joblib storage/example-models/sklearn/model.joblib |
| 135 | +fi |
| 136 | + |
| 137 | +oc delete route -n kserve minio-service |
| 138 | + |
| 139 | +echo "Prepare CI namespace and install ServingRuntimes" |
| 140 | +cat <<EOF | oc apply -f - |
| 141 | +apiVersion: v1 |
| 142 | +kind: Namespace |
| 143 | +metadata: |
| 144 | + name: kserve-ci-e2e-test |
| 145 | +EOF |
| 146 | + |
| 147 | +if [ "$1" != "raw" ]; then |
| 148 | + cat <<EOF | oc apply -f - |
| 149 | +apiVersion: maistra.io/v1 |
| 150 | +kind: ServiceMeshMember |
| 151 | +metadata: |
| 152 | + name: default |
| 153 | + namespace: kserve-ci-e2e-test |
| 154 | +spec: |
| 155 | + controlPlaneRef: |
| 156 | + namespace: istio-system |
| 157 | + name: basic |
| 158 | +EOF |
| 159 | +fi |
| 160 | + |
| 161 | +oc apply -f $PROJECT_ROOT/config/overlays/test/minio/minio-user-secret.yaml -n kserve-ci-e2e-test |
| 162 | + |
| 163 | +kustomize build $PROJECT_ROOT/config/overlays/test/clusterresources | |
| 164 | + sed 's/ClusterServingRuntime/ServingRuntime/' | |
| 165 | + sed "s|kserve/sklearnserver:latest|${SKLEARN_IMAGE}|" | |
| 166 | + sed "s|kserve/storage-initializer:latest|${STORAGE_INITIALIZER_IMAGE}|" | |
| 167 | + oc apply -n kserve-ci-e2e-test -f - |
| 168 | + |
| 169 | +# Add the enablePassthrough annotation to the ServingRuntimes, to let Knative to |
| 170 | +# generate passthrough routes. If RawDeployment test are being run, this annotation would have |
| 171 | +# no effect, because of missing Knative |
| 172 | +oc annotate servingruntimes -n kserve-ci-e2e-test --all serving.knative.openshift.io/enablePassthrough=true |
| 173 | + |
| 174 | +echo "Setup complete" |
0 commit comments