Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Shell script openshift-ci make some REST call to MR #295

Merged
merged 2 commits into from
Feb 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions test/scripts/rest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#!/bin/bash
isinyaaa marked this conversation as resolved.
Show resolved Hide resolved

make_post_extract_id() {
local url="$1"
local data="$2"
local id=$(curl -s -X POST "$url" \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d "$data" | jq -r '.id')

if [ -z "$id" ]; then
echo "Error: Failed to extract ID from response"
exit 1
fi

echo "$id"
}

# TODO: finalize using openshift-ci values.
OCP_CLUSTER_NAME="PROVIDE OCP CLUSTER NAME FOR OPENSHIFT-CI"
MR_NAMESPACE="shared-modelregistry-ns"
MR_HOSTNAME="http://modelregistry-sample-http-$MR_NAMESPACE.apps.$OCP_CLUSTER_NAME"

timestamp=$(date +"%Y%m%d%H%M%S")
rm_name="demo-$timestamp"

rm_id=$(make_post_extract_id "$MR_HOSTNAME/api/model_registry/v1alpha1/registered_models" '{
"description": "lorem ipsum registered model",
"name": "'"$rm_name"'"
}')

if [ $? -ne 0 ]; then
exit 1
fi
echo "Registered Model ID: $rm_id"

mv_id=$(make_post_extract_id "$MR_HOSTNAME/api/model_registry/v1alpha1/model_versions" '{
"description": "lorem ipsum model version",
"name": "v1",
"author": "John Doe",
"registeredModelID": "'"$rm_id"'"
}')

if [ $? -ne 0 ]; then
exit 1
fi
echo "Model Version ID: $mv_id"

RAW_ML_MODEL_URI='https://huggingface.co/tarilabs/mnist/resolve/v1.nb20231206162408/mnist.onnx'
ma_id=$(make_post_extract_id "$MR_HOSTNAME/api/model_registry/v1alpha1/model_versions/$mv_id/artifacts" '{
"description": "lorem ipsum model artifact",
"uri": "'"$RAW_ML_MODEL_URI"'",
"name": "mnist",
"modelFormatName": "onnx",
"modelFormatVersion": "1",
"storageKey": "aws-connection-unused",
"storagePath": "unused just demo",
"artifactType": "model-artifact"
}')

if [ $? -ne 0 ]; then
exit 1
fi
echo "Model Artifact ID: $ma_id"

ISVC_TARGET_NS=odh-project-b
MODEL_SERVER_NAME=modelserverb

oc apply -n $ISVC_TARGET_NS -f - <<EOF
apiVersion: "serving.kserve.io/v1beta1"
kind: "InferenceService"
metadata:
name: "$rm_name"
annotations:
"openshift.io/display-name": "$rm_name"
"serving.kserve.io/deploymentMode": "ModelMesh"
labels:
"mr-registered-model-id": "$rm_id"
"mr-model-version-id": "$mv_id"
Comment on lines +78 to +79
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the K8s ISVC is created with the IDs from the MR REST calls

"mr-namespace": "$MR_NAMESPACE"
"opendatahub.io/dashboard": "true"
spec:
predictor:
model:
modelFormat:
name: "onnx"
version: "1"
runtime: "$MODEL_SERVER_NAME"
storageUri: "$RAW_ML_MODEL_URI"
EOF

# TODO this will continue once we have MC PR merged from: https://github.com/opendatahub-io/odh-model-controller/pull/135
iss_mr=$(curl -s -X 'GET' "$MR_HOSTNAME/api/model_registry/v1alpha1/inference_services" \
-H 'accept: application/json')
Comment on lines +92 to +94
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As confirmed to offline review, this will eventually transform into a loop-while, waiting for the condition than some InferenceService entity on MR is valorized with the registeredModelId, modelVersionId as needed.

(once opendatahub-io/odh-model-controller#135 merged)

This described change, I suggest to be done in a subsequent PR, as this covers already for basic REST functionality.


echo "InferenceService entities on MR:"
echo "$iss_mr"
Loading