Repository: kubeflow/pipelines

Issue:
flexible pipeline service (host) path in client SDK 
when creating an SDK `Client()` the path to `ml-pipeline` API service is loaded from a hard coded value (`ml-pipeline.kubeflow.svc.cluster.local:8888`) which indicate a specific k8s namespace. it can be valuable to load that default value from an env variable, i.e. changing the line in `_client.py` from:

`config.host = host if host else Client.IN_CLUSTER_DNS_NAME`

to:

`config.host = host or os.environ.get('ML_PIPELINE_DNS_NAME',Client.IN_CLUSTER_DNS_NAME)`

also note that when a user provide the `host` parameter, the ipython output points to the API server and not to the UI service (see the logic in `_get_url_prefix()`), it seems like a potential bug

if its acceptable i can submit a PR for the line change above
 
allow output artifact store configuration (vs hard coded)
it seems like the output artifacts are always stored in a specific minio service, port, namespace, bucket, secrets, etc (`minio-service.kubeflow:9000`). 

see: https://github.com/kubeflow/pipelines/blob/f40a22a3f4a8e06d20cf3e3f425b5058d5c87e0b/sdk/python/kfp/compiler/_op_to_template.py#L148

it would be great to make it flexible, e.g. allow using S3, or change namespace or bucket names.
i suggest making it configurable, i can do such PR if we agree its needed. 


Discussion:
>it can be valuable to load that default value from an env variable

I'm not sure about the user scenarios, but I guess it might be useful for some cases.

>ML_PIPELINE_DNS_NAME

Maybe, `KF_PIPELINES_ENDPOINT`?

>it seems like a potential bug

It probably is. The Client class can definitely use some improvements, especially for out-of-cluster usage.

> if its acceptable i can submit a PR

We always appreciate PRs.
Fixed in https://github.com/kubeflow/pipelines/pull/1293
There is already a PR for this. But we'd like to solve this in a different way - by having an in-cluster configMap with the storage configuration. Argo already supports that, but we're hesitating to use that mechanism since KF Pipelines might not be the exclusive user of the Argo controller.

Fortunately, the problem will be solved in Argo 2.4 (per-pipeline configMap reference)
Also https://github.com/kubeflow/pipelines/issues/363 https://github.com/kubeflow/pipelines/issues/1195 https://github.com/kubeflow/pipelines/issues/362
@Ark-kun a mechanism like config map sounds better, it will also make the YAMLs cleaner, currently u get the same 27 lines added to every container, see below, would be nice to hide it:

```yaml
    outputs:
      artifacts:
      - name: mlpipeline-ui-metadata
        path: /mlpipeline-ui-metadata.json
        s3:
          accessKeySecret:
            key: accesskey
            name: mlpipeline-minio-artifact
          bucket: mlpipeline
          endpoint: minio-service.kubeflow:9000
          insecure: true
          key: runs/{{workflow.uid}}/{{pod.name}}/mlpipeline-ui-metadata.tgz
          secretKeySecret:
            key: secretkey
            name: mlpipeline-minio-artifact
      - name: mlpipeline-metrics
        path: /mlpipeline-metrics.json
        s3:
          accessKeySecret:
            key: accesskey
            name: mlpipeline-minio-artifact
          bucket: mlpipeline
          endpoint: minio-service.kubeflow:9000
          insecure: true
          key: runs/{{workflow.uid}}/{{pod.name}}/mlpipeline-metrics.tgz
          secretKeySecret:
            key: secretkey
            name: mlpipeline-minio-artifact
```
Fixed by https://github.com/kubeflow/pipelines/pull/1297

Resolving patch:
diff --git a/components/kubeflow/kfserving/src/app.py b/components/kubeflow/kfserving/src/app.py
--- a/components/kubeflow/kfserving/src/app.py
+++ b/components/kubeflow/kfserving/src/app.py
@@ -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"]
         )
     )
 
diff --git a/components/kubeflow/kfserving/src/kfservingdeployer.py b/components/kubeflow/kfserving/src/kfservingdeployer.py
--- a/components/kubeflow/kfserving/src/kfservingdeployer.py
+++ b/components/kubeflow/kfserving/src/kfservingdeployer.py
@@ -18,6 +18,7 @@
 import requests
 import re
 import time
+from distutils.util import strtobool
 
 from kubernetes import client
 
@@ -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
@@ -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()
 
@@ -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 = {
@@ -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
@@ -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"]
@@ -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:


Test patch: