Skip to content

Commit

Permalink
fix(components): add istio inject and ready status to kfserving compo…
Browse files Browse the repository at this point in the history
…nent (#4362)

* fix istio inject and ready status bug

* use strtobool to create python bool type

* update variable name
  • Loading branch information
Tomcli committed Sep 3, 2020
1 parent b1dcedc commit f3a02d1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
4 changes: 3 additions & 1 deletion components/kubeflow/kfserving/component.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ inputs:
- {name: Canary Custom Model Spec, type: String, default: '{}', description: 'Custom runtime canary custom model container spec.'}
- {name: Autoscaling Target, type: String, default: '0', description: 'Autoscaling Target Number'}
- {name: KFServing Endpoint, type: String, default: '', description: 'KFServing remote deployer API endpoint'}
- {name: Service Account, type: String, default: '', description: 'Model Service Account'}
- {name: Service Account, type: String, default: '', description: 'Model Service Account'}
- {name: Enable Istio Sidecar, type: Bool, default: 'True', description: 'Whether to enable istio sidecar injection'}
outputs:
- {name: Service Endpoint URI, type: String, description: 'URI of the deployed prediction service..'}
implementation:
Expand All @@ -33,5 +34,6 @@ implementation:
--kfserving-endpoint, {inputValue: KFServing Endpoint},
--autoscaling-target, {inputValue: Autoscaling Target},
--service-account, {inputValue: Service Account},
--enable-istio-sidecar, {inputValue: Enable Istio Sidecar},
--output-path, {outputPath: Service Endpoint URI}
]
1 change: 1 addition & 0 deletions components/kubeflow/kfserving/src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def deploy_model_post():
canary_custom_model_spec=request.json["canary_custom_model_spec"],
autoscaling_target=request.json["autoscaling_target"],
service_account=request.json["service_account"],
enable_istio_sidecar=request.json["enable_istio_sidecar"]
)
)

Expand Down
26 changes: 24 additions & 2 deletions components/kubeflow/kfserving/src/kfservingdeployer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import requests
import re
import time
from distutils.util import strtobool

from kubernetes import client

Expand Down Expand Up @@ -142,10 +143,15 @@ def deploy_model(
canary_custom_model_spec,
service_account,
autoscaling_target=0,
enable_istio_sidecar=True
):
# Create annotation
annotations = {}
if int(autoscaling_target) != 0:
annotations = {"autoscaling.knative.dev/target": str(autoscaling_target)}
else:
annotations["autoscaling.knative.dev/target"] = str(autoscaling_target)
if not enable_istio_sidecar:
annotations["sidecar.istio.io/inject"] = 'false'
if not annotations:
annotations = None
metadata = client.V1ObjectMeta(
name=model_name, namespace=namespace, annotations=annotations
Expand Down Expand Up @@ -279,6 +285,9 @@ def update(kfsvc, model_name, namespace):
help="Service account containing s3 credentials",
default="",
)
parser.add_argument(
"--enable-istio-sidecar", type=strtobool, help="Whether to inject istio sidecar", default="True"
)
parser.add_argument("--output-path", type=str, help="Path to store URI output")
args = parser.parse_args()

Expand All @@ -297,6 +306,7 @@ def update(kfsvc, model_name, namespace):
kfserving_endpoint = url.sub("", args.kfserving_endpoint)
autoscaling_target = int(args.autoscaling_target)
service_account = args.service_account
enable_istio_sidecar = args.enable_istio_sidecar

if kfserving_endpoint:
formData = {
Expand All @@ -311,6 +321,7 @@ def update(kfsvc, model_name, namespace):
"canary_custom_model_spec": canary_custom_model_spec,
"autoscaling_target": autoscaling_target,
"service_account": service_account,
"enable_istio_sidecar": enable_istio_sidecar
}
response = requests.post(
"http://" + kfserving_endpoint + "/deploy-model", json=formData
Expand All @@ -329,8 +340,18 @@ def update(kfsvc, model_name, namespace):
canary_custom_model_spec=canary_custom_model_spec,
autoscaling_target=autoscaling_target,
service_account=service_account,
enable_istio_sidecar=enable_istio_sidecar
)
print(model_status)
# Check whether the model is ready
for condition in model_status["status"]["conditions"]:
if condition['type'] == 'Ready':
if condition['status'] == 'True':
print('Model is ready')
break
else:
print('Model is timed out, please check the inferenceservice events for more details.')
exit(1)
try:
print(
model_status["status"]["url"]
Expand All @@ -350,6 +371,7 @@ def update(kfsvc, model_name, namespace):
)
except:
print("Model is not ready, check the logs for the Knative URL status.")
exit(1)
if not os.path.exists(os.path.dirname(output_path)):
os.makedirs(os.path.dirname(output_path))
with open(output_path, "w") as report:
Expand Down

0 comments on commit f3a02d1

Please sign in to comment.