Skip to content

Commit b525a79

Browse files
authored
Feature/erwan gitops model (rh-aiservices-bu#34)
* gitops for modelmesh/ovms/model * removing extraneous lines from applicationset * pinger pod is not active yet. will need more work.
1 parent 70dff13 commit b525a79

13 files changed

+629
-3
lines changed

.github/.wordlist.txt

+2
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,5 @@ Prasanth
136136
Anbalagan
137137
Erwan
138138
Granger
139+
applicationset
140+
imagesdir

bootstrap/applicationset/applicationset-bootstrap.yaml

+5-3
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,25 @@ spec:
88
- list:
99
elements:
1010
- cluster: in-cluster
11-
url: https://kubernetes.default.svc
1211
name: ic-shared-minio-app
1312
repoURL: https://github.com/rh-aiservices-bu/insurance-claim-processing.git
1413
targetRevision: dev
1514
path: bootstrap/ic-shared-minio
1615
- cluster: in-cluster
17-
url: https://kubernetes.default.svc
1816
name: ic-shared-database-app
1917
repoURL: https://github.com/rh-aiservices-bu/insurance-claim-processing.git
2018
targetRevision: dev
2119
path: bootstrap/ic-shared-database
2220
- cluster: in-cluster
23-
url: https://kubernetes.default.svc
2421
name: ic-shared-llm-app
2522
repoURL: https://github.com/rh-aiservices-bu/insurance-claim-processing.git
2623
targetRevision: dev
2724
path: bootstrap/ic-shared-llm
25+
- cluster: in-cluster
26+
name: ic-shared-img-det
27+
repoURL: https://github.com/rh-aiservices-bu/insurance-claim-processing.git
28+
targetRevision: dev
29+
path: bootstrap/ic-shared-img-det
2830
template:
2931
metadata:
3032
name: '{{name}}'

bootstrap/bootstrap.md

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ CMD=" oc apply -f ${GITEA_INT_URL}${GITEA_REPO}raw/branch/${GITEA_BRANCH}${GITEA
1010

1111
echo ${CMD}
1212

13+
oc apply -f ./bootstrap/applicationset/applicationset-bootstrap.yaml
14+
1315
```
1416

1517
<!--
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
apiVersion: batch/v1
3+
kind: Job
4+
metadata:
5+
name: add-model-job
6+
annotations:
7+
argocd.argoproj.io/sync-wave: "2"
8+
spec:
9+
backoffLimit: 4
10+
template:
11+
spec:
12+
serviceAccount: sa-img-det-gitops-setup
13+
serviceAccountName: sa-img-det-gitops-setup
14+
initContainers:
15+
# - name: wait-for-imagestream
16+
# image: image-registry.openshift-image-registry.svc:5000/openshift/tools:latest
17+
# imagePullPolicy: IfNotPresent
18+
# command: ["/bin/bash"]
19+
# args:
20+
# - -ec
21+
# - |-
22+
# echo -n 'Waiting for RHODS to deploy ImageStreams'
23+
# while ! oc get istag -n redhat-ods-applications 2>/dev/null | grep -qF s2i-generic-data-science-notebook:1.2; do
24+
# echo -n .
25+
# sleep 5
26+
# done; echo
27+
containers:
28+
- name: add-model
29+
image: image-registry.openshift-image-registry.svc:5000/redhat-ods-applications/s2i-generic-data-science-notebook:1.2
30+
imagePullPolicy: IfNotPresent
31+
command: ["/bin/bash"]
32+
args:
33+
- -ec
34+
- |-
35+
# in case we need to add more models, we can do it here too.
36+
echo -n "not doing anything right now"
37+
# curl -LO https://ai-on-openshift.io/odh-rhods/img-triton/card.fraud.detection.onnx
38+
# cat << 'EOF' | python3
39+
# filename = "card.fraud.detection.onnx"
40+
# import boto3, os
41+
# s3 = boto3.client("s3",
42+
# endpoint_url=os.getenv("AWS_S3_ENDPOINT"),
43+
# aws_access_key_id=os.getenv("AWS_ACCESS_KEY_ID"),
44+
# aws_secret_access_key=os.getenv("AWS_SECRET_ACCESS_KEY"))
45+
# bucket = os.getenv("AWS_S3_BUCKET")
46+
# if bucket not in [bu["Name"] for bu in s3.list_buckets()["Buckets"]]:
47+
# s3.create_bucket(Bucket=bucket)
48+
# with open(filename, "rb") as f:
49+
# s3.upload_fileobj(f, bucket, f'fraud/{filename}')
50+
# EOF
51+
envFrom:
52+
- secretRef:
53+
name: aws-connection-minio
54+
restartPolicy: Never
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
apiVersion: batch/v1
3+
kind: Job
4+
metadata:
5+
name: create-data-connection
6+
annotations:
7+
argocd.argoproj.io/sync-wave: "1"
8+
argocd.argoproj.io/hook: Sync
9+
argocd.argoproj.io/hook-delete-policy: BeforeHookCreation
10+
spec:
11+
backoffLimit: 4
12+
template:
13+
spec:
14+
serviceAccount: sa-img-det-gitops-setup
15+
serviceAccountName: sa-img-det-gitops-setup
16+
containers:
17+
- name: create-data-connection
18+
image: image-registry.openshift-image-registry.svc:5000/openshift/tools:latest
19+
imagePullPolicy: IfNotPresent
20+
command: ["/bin/bash"]
21+
args:
22+
- -ec
23+
- |-
24+
echo -n "Waiting for minio-root-user."
25+
while [ -z "$(oc get secret -n ic-shared-minio minio-root-user -oname 2>/dev/null)" ]; do
26+
echo -n '.'
27+
sleep 1
28+
done; echo
29+
id=$(oc get secret -n ic-shared-minio minio-root-user -ogo-template='{{.data.MINIO_ROOT_USER|base64decode}}')
30+
secret=$(oc get secret -n ic-shared-minio minio-root-user -ogo-template='{{.data.MINIO_ROOT_PASSWORD|base64decode}}')
31+
echo "Creating secret for ${id}"
32+
cat << EOF | oc apply -f-
33+
apiVersion: v1
34+
kind: Secret
35+
metadata:
36+
name: aws-connection-minio
37+
labels:
38+
opendatahub.io/dashboard: "true"
39+
opendatahub.io/managed: "true"
40+
annotations:
41+
opendatahub.io/connection-type: s3
42+
openshift.io/display-name: MinIO
43+
type: Opaque
44+
stringData:
45+
AWS_ACCESS_KEY_ID: ${id}
46+
AWS_SECRET_ACCESS_KEY: ${secret}
47+
AWS_DEFAULT_REGION: us
48+
AWS_S3_ENDPOINT: http://minio.ic-shared-minio.svc:9000
49+
AWS_S3_BUCKET: models
50+
EOF
51+
restartPolicy: Never
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
apiVersion: kustomize.config.k8s.io/v1beta1
3+
kind: Kustomization
4+
5+
commonLabels:
6+
component: model
7+
8+
namespace: ic-shared-img-det
9+
10+
resources:
11+
- project.yaml
12+
- setup-serviceaccount.yaml
13+
- create-data-connection.yaml
14+
- add-model-job.yaml
15+
- runtime.yaml
16+
- model.yaml
17+
# pinger is not ready yet
18+
# - pinger.yaml
+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# ---
2+
# apiVersion: serving.kserve.io/v1beta1
3+
# kind: InferenceService
4+
# metadata:
5+
# annotations:
6+
# openshift.io/display-name: accident
7+
# serving.kserve.io/deploymentMode: ModelMesh
8+
# argocd.argoproj.io/sync-wave: "3"
9+
# argocd.argoproj.io/sync-options: SkipDryRunOnMissingResource=true
10+
# labels:
11+
# name: accident
12+
# opendatahub.io/dashboard: "true"
13+
# name: accident
14+
# spec:
15+
# predictor:
16+
# model:
17+
# modelFormat:
18+
# name: onnx
19+
# version: "1"
20+
# runtime: triton
21+
# storage:
22+
# key: aws-connection-minio
23+
# path: accident/
24+
---
25+
apiVersion: serving.kserve.io/v1beta1
26+
kind: InferenceService
27+
metadata:
28+
annotations:
29+
openshift.io/display-name: img-det
30+
serving.kserve.io/deploymentMode: ModelMesh
31+
labels:
32+
name: "img-det"
33+
opendatahub.io/dashboard: 'true'
34+
name: "img-det"
35+
spec:
36+
predictor:
37+
model:
38+
modelFormat:
39+
name: onnx
40+
version: '1'
41+
runtime: ovms
42+
storage:
43+
key: aws-connection-minio
44+
path: accident/
+134
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
---
2+
apiVersion: apps/v1
3+
kind: Deployment
4+
metadata:
5+
name: model-pinger
6+
labels:
7+
app: model-pinger
8+
spec:
9+
replicas: 1
10+
revisionHistoryLimit: 3
11+
selector:
12+
matchLabels:
13+
app: model-pinger
14+
strategy:
15+
type: RollingUpdate
16+
rollingUpdate:
17+
maxSurge: 1
18+
maxUnavailable: 100%
19+
template:
20+
metadata:
21+
labels:
22+
app: model-pinger
23+
spec:
24+
containers:
25+
- name: pinger
26+
image: quay.io/rlundber/sds-small:1.8
27+
command:
28+
- python
29+
- -u
30+
- /ping_model.py
31+
env:
32+
- name: MM_SERVING_HOST
33+
value: modelmesh-serving:8008
34+
- name: MM_MODEL_NAME
35+
# value: fraud-4
36+
value: fraud-latest
37+
- name: SLEEP_TIME
38+
value: "5"
39+
resources:
40+
limits:
41+
cpu: "0.2"
42+
memory: 256Mi
43+
volumeMounts:
44+
- name: pinger-config
45+
subPath: ping_model.py
46+
mountPath: /ping_model.py
47+
volumes:
48+
- name: pinger-config
49+
configMap:
50+
name: model-pinger
51+
52+
---
53+
apiVersion: v1
54+
kind: ConfigMap
55+
metadata:
56+
name: model-pinger
57+
data:
58+
ping_model.py: |
59+
import os
60+
import time
61+
from datetime import datetime
62+
import random
63+
64+
# MM_SERVING_HOST = os.environ.get("MM_SERVING_HOST", "modelmesh-serving:8008")
65+
# MM_MODEL_NAME = os.environ.get("MM_MODEL_NAME", "fraud-latest")
66+
67+
# # deployed_model_name = "fraud-latest"
68+
# # rest_url = "http://modelmesh-serving:8008"
69+
# deployed_model_name = MM_MODEL_NAME
70+
# rest_url = f"http://{MM_SERVING_HOST}"
71+
# infer_url = f"{rest_url}/v2/models/{deployed_model_name}/infer"
72+
# print(infer_url)
73+
74+
# import requests
75+
76+
# def rest_request(data):
77+
# json_data = {
78+
# "inputs": [
79+
# {
80+
# "name": "dense_input",
81+
# "shape": [1, 5],
82+
# "datatype": "FP32",
83+
# "data": data
84+
# }
85+
# ]
86+
# }
87+
88+
# response = requests.post(infer_url, json=json_data)
89+
# response_dict = response.json()
90+
# return response_dict['outputs'][0]['data']
91+
92+
93+
# MM_SERVING_HOST = os.environ.get("MM_SERVING_HOST", "modelmesh-serving:8033")
94+
# MM_MODEL_NAME = os.environ.get("MM_MODEL_NAME", "ansible-model-pinger")
95+
96+
# SLEEP_TIME = os.environ.get("SLEEP_TIME", "3")
97+
# SLEEP_TIME = int(SLEEP_TIME)
98+
99+
100+
# while True:
101+
# now = datetime.now()
102+
# time_string = now.strftime("%Y-%m-%d %H:%M:%S")
103+
104+
# print("--------------------------------------")
105+
# print("Sending Request at",time_string)
106+
107+
# start = time.time()
108+
# try:
109+
# random_dist = round(random.uniform(0, 50), 2)
110+
# data = [random_dist, 1.9459399775518593, 1.0, 0.0, 0.0]
111+
# print("Data sent to model ("+deployed_model_name+"):")
112+
# print(data)
113+
114+
# # Start the timer
115+
# start_time = time.time()
116+
117+
# prediction = rest_request(data)
118+
119+
# # End the timer
120+
# end_time = time.time()
121+
122+
# # Calculate the elapsed time in milliseconds
123+
# response_time_ms = (end_time - start_time) * 1000
124+
125+
# # prediction
126+
# print("Likelyhood of fraud")
127+
# print(str(prediction[0]*100)+"%")
128+
129+
# print("Prediction took ", response_time_ms, "milliseconds")
130+
131+
# except Exception as e:
132+
# print(f"Errored after {time.time() - start}s: {e}")
133+
134+
# time.sleep(SLEEP_TIME)
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
apiVersion: project.openshift.io/v1
3+
kind: Project
4+
metadata:
5+
annotations:
6+
openshift.io/description: Project created to demonstrate custom serving runtime
7+
openshift.io/display-name: Shared Image Detection Model
8+
argocd.argoproj.io/sync-wave: "0"
9+
argocd.argoproj.io/managed-by: openshift-gitops
10+
labels:
11+
kubernetes.io/metadata.name: ic-shared-img-det
12+
modelmesh-enabled: "true"
13+
opendatahub.io/dashboard: "true"
14+
name: ic-shared-img-det

0 commit comments

Comments
 (0)