Repository: kserve/kserve

Issue:
Knative KafaSource detects wrong URL to serve events
/kind bug

**What steps did you take and what happened:**
[A clear and concise description of what the bug is.]
- Deployed knative-eventing and kafkasource.
- Added https://github.com/kserve/kserve/blob/master/docs/samples/kafka/addressable-resolver.yaml
- knative eventing is able to read the kafka source.
- The service name created by inferenceservice is \<isvc-name>-predictor-default. However the kafkasource sends the events to http://\<isvc-name>.\<namespace>.svc.cluster.local

**What did you expect to happen:**
- I expected the requests to be sent to http://\<isvc-name>-predictor-default.\<namespace>.svc.cluster.local

**What's the InferenceService yaml:**
```
apiVersion: "serving.kserve.io/v1beta1"
kind: "InferenceService"
metadata:
  name: "<inference-name>"
  namespace: "\<namespace>"
  annotations:
    prometheus.io/scrape: 'true'
    prometheus.io/port: '8082'
  labels:
    name: "\<label>"
spec:
  predictor:
    minReplicas: 3
    maxReplicas: 100
    pytorch:
      name: \<name>
      storageUri: gs://<storage>
      resources:
        limits:
          cpu: 3000m
          memory: 3Gi
        requests:
          cpu: 2000m
          memory: 3Gi
```
**Anything else you would like to add:**
[Miscellaneous information that will assist in solving the issue.]
```
ingress: |-
    {
        "ingressGateway" : "knative-serving/knative-ingress-gateway",
        "ingressService" : "istio-ingressgateway.istio-system.svc.cluster.local",
        "localGateway" : "knative-serving/knative-local-gateway",
        "localGatewayService" : "knative-local-gateway.istio-system.svc.cluster.local",
        "ingressDomain"  : "example.com",
        "ingressClassName" : "kong",
        "domainTemplate": "{{ .Name }}-{{ .Namespace }}.{{ .IngressDomain }}",
        "urlScheme": "http"
    }
```

**Environment:**
 Using Kong
 RawDeployment
Torchserve version : 0.6.1
- Istio Version: Istio not installed
- Knative Version: knative serving not installled. knative eventing v1.8.2
- KServe Version: 0.9.0
- Kubeflow version: N/A
- Cloud Environment: GKE
- Minikube/Kind version:
- Kubernetes version: (use `kubectl version`): 1.23
- OS (e.g. from `/etc/os-release`): GKE



Discussion:
/assign @sivanantha321 

Resolving patch:
diff --git a/docs/samples/kafka/image_transformer/image_transformer.py b/docs/samples/kafka/image_transformer/image_transformer.py
--- a/docs/samples/kafka/image_transformer/image_transformer.py
+++ b/docs/samples/kafka/image_transformer/image_transformer.py
@@ -11,13 +11,14 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-import kserve
-from typing import Dict, Union
 import logging
+from typing import Dict, Union
+
 import boto3
 import cv2
 from cloudevents.http import CloudEvent
 
+import kserve
 from kserve import InferRequest, InferResponse
 from kserve.protocol.grpc.grpc_predict_v2_pb2 import ModelInferResponse
 
@@ -26,6 +27,7 @@
 session = boto3.Session()
 client = session.client('s3', endpoint_url='http://minio-service:9000', aws_access_key_id='minio',
                         aws_secret_access_key='minio123')
+digits_bucket = 'digits'
 
 
 def image_transform(image):
@@ -41,8 +43,9 @@ def __init__(self, name: str, predictor_host: str):
         self.predictor_host = predictor_host
         self._key = None
 
-    def preprocess(self, inputs: Union[Dict, CloudEvent, InferRequest],
-                   headers: Dict[str, str] = None) -> Union[Dict, InferRequest]:
+    async def preprocess(self, inputs: Union[Dict, CloudEvent, InferRequest],
+                         headers: Dict[str, str] = None) -> Union[Dict, InferRequest]:
+        logging.info("Received inputs %s", inputs)
         if inputs['EventName'] == 's3:ObjectCreated:Put':
             bucket = inputs['Records'][0]['s3']['bucket']['name']
             key = inputs['Records'][0]['s3']['object']['key']
@@ -54,8 +57,10 @@ def preprocess(self, inputs: Union[Dict, CloudEvent, InferRequest],
 
     def postprocess(self, response: Union[Dict, InferResponse, ModelInferResponse], headers: Dict[str, str] = None) \
             -> Union[Dict, ModelInferResponse]:
-        logging.info(response)
+        logging.info("response: %s", response)
         index = response["predictions"][0]["classes"]
         logging.info("digit:" + str(index))
-        client.upload_file('/tmp/' + self._key, 'digit-' + str(index), self._key)
+        upload_path = f'digit-{index}/{self._key}'
+        client.upload_file('/tmp/' + self._key, digits_bucket, upload_path)
+        logging.info(f"Image {self._key} successfully uploaded to {upload_path}")
         return response
diff --git a/docs/samples/kafka/setup.py b/docs/samples/kafka/setup.py
--- a/docs/samples/kafka/setup.py
+++ b/docs/samples/kafka/setup.py
@@ -10,22 +10,17 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
-import os
 
 from setuptools import setup, find_packages
 
 tests_require = [
     'pytest',
-    'pytest-tornasync',
     'mypy'
 ]
 
-with open(os.path.join(os.getcwd(), '../../../python/VERSION')) as version_file:
-    version = version_file.read().strip()
-
 setup(
     name='transformer',
-    version='0.1.0',
+    version='0.2.0',
     author_email='dsun20@bloomberg.net',
     license='../../LICENSE.txt',
     url='https://github.com/kserve/kserve/tree/master/docs/samples/kafka',
@@ -34,9 +29,9 @@
     python_requires='>=3.7',
     packages=find_packages("transformer"),
     install_requires=[
-        f"kserve>={version}",
+        "kserve>0.10.0",
         "pandas>=0.24.2",
-        "opencv-python-headless==4.2.0.32",
+        "opencv-python-headless==4.7.0.72",
     ],
     tests_require=tests_require,
     extras_require={'test': tests_require}


Test patch: