prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Kserve defaulting causing duplicates of environment variable 
  /kind bug
  
  **What steps did you take and what happened:**
  Create example xgboost isvc and enable gRPC
  ```
  apiVersion: "serving.kserve.io/v1beta1"
  kind: "InferenceService"
  metadata:
    name: "xgboost-iris"
  spec:
    predictor:
      xgboost:
        protocolVersion: "v2"
        storageUri: "gs://kfserving-examples/models/xgboost/iris"
        ports:
        - containerPort: 9000
          name: h2c
          protocol: TCP
  ```
  
  The pod spec has duplicated environment variable
  ```
      Environment:
        MLSERVER_MODEL_NAME:            xgboost-iris
        MLSERVER_MODEL_URI:             /mnt/models
        MLSERVER_MODEL_NAME:            xgboost-iris
        MLSERVER_MODEL_URI:             /mnt/models
  ```
  
  Additionally, attempt to override the defaults leads to duplicated environment variable with different values
  
  ```
  apiVersion: "serving.kserve.io/v1beta1"
  kind: "InferenceService"
  metadata:
    name: "xgboost-iris"
  spec:
    predictor:
      xgboost:
        protocolVersion: "v2"
        storageUri: "gs://kfserving-examples/models/xgboost/iris"
        ports:
        - containerPort: 9000
          name: h2c
          protocol: TCP
        env:
        - name: MLSERVER_MODEL_NAME
          value: my-model
  ```
  
  The pod spec:
  ```
      Environment:
        MLSERVER_MODEL_NAME:            my-model
        MLSERVER_MODEL_NAME:            xgboost-iris
        MLSERVER_MODEL_URI:                /mnt/models
  ```
  
  **What did you expect to happen:**
  - Defaulting should not duplicate environment variable and should prioritise user's defined environment variable
  
  **Anything else you would like to add:**
  I believe it's because the defaulter always append `.Env` without checking the presence of existing environment variable. (https://github.com/kserve/kserve/blob/a6ed8e4b006e27433de2336e0e8b7cec11137dc1/pkg/apis/serving/v1beta1/inference_service_defaults.go#L264)
  
  
  **Environment:**
  
  - Kserve: 0.8.0
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `python/custom_transformer/model_grpc.py`
  Content:
  ```
  1 # Copyright 2022 The KServe Authors.
  2 #
  3 # Licensed under the Apache License, Version 2.0 (the "License");
  4 # you may not use this file except in compliance with the License.
  5 # You may obtain a copy of the License at
  6 #
  7 #    http://www.apache.org/licenses/LICENSE-2.0
  8 #
  9 # Unless required by applicable law or agreed to in writing, software
  10 # distributed under the License is distributed on an "AS IS" BASIS,
  11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12 # See the License for the specific language governing permissions and
  13 # limitations under the License.
  14 
  15 import argparse
  16 import base64
  17 from typing import Dict, Union
  18 
  19 from kserve import Model, ModelServer, model_server
  20 from kserve.grpc.grpc_predict_v2_pb2 import ModelInferRequest
  21 from kserve.handlers.v2_datamodels import InferenceRequest
  22 
  23 
  24 class ImageTransformer(Model):
  25     def __init__(self, name: str, predictor_host: str, protocol: str):
  26         super().__init__(name)
  27         self.predictor_host = predictor_host
  28         self.protocol = protocol
  29         self.model_name = name
  30 
  31     def preprocess(self, request: Union[Dict, ModelInferRequest, InferenceRequest], headers=None) -> ModelInferRequest:
  32         if isinstance(request, ModelInferRequest):
  33             return request
  34         else:
  35             payload = [
  36                 {
  37                     "name": "input-0",
  38                     "shape": [],
  39                     "datatype": "BYTES",
  40                     "contents": {
  41                         "bytes_contents": [base64.b64decode(request["inputs"][0]["data"][0])]
  42                     }
  43                 }
  44             ]
  45             return ModelInferRequest(model_name=self.model_name, inputs=payload)
  46 
  47 
  48 parser = argparse.ArgumentParser(parents=[model_server.parser])
  49 parser.add_argument(
  50     "--predictor_host", help="The URL for the model predict function", required=True
  51 )
  52 parser.add_argument(
  53     "--protocol", help="The protocol for the predictor", default="v1"
  54 )
  55 parser.add_argument(
  56     "--model_name", help="The name that the model is served under."
  57 )
  58 args, _ = parser.parse_known_args()
  59 
  60 if __name__ == "__main__":
  61     model = ImageTransformer(args.model_name, predictor_host=args.predictor_host,
  62                              protocol=args.protocol)
  63     ModelServer(workers=1).start([model])
  64
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/python/custom_transformer/model_grpc.py b/python/custom_transformer/model_grpc.py
  --- a/python/custom_transformer/model_grpc.py
  +++ b/python/custom_transformer/model_grpc.py
  @@ -18,7 +18,6 @@
   
   from kserve import Model, ModelServer, model_server
   from kserve.grpc.grpc_predict_v2_pb2 import ModelInferRequest
  -from kserve.handlers.v2_datamodels import InferenceRequest
   
   
   class ImageTransformer(Model):
  @@ -28,7 +27,7 @@
           self.protocol = protocol
           self.model_name = name
   
  -    def preprocess(self, request: Union[Dict, ModelInferRequest, InferenceRequest], headers=None) -> ModelInferRequest:
  +    def preprocess(self, request: Union[Dict, ModelInferRequest], headers=None) -> ModelInferRequest:
           if isinstance(request, ModelInferRequest):
               return request
           else:
  
verification_info: {"golden_diff": "diff --git a/python/custom_transformer/model_grpc.py b/python/custom_transformer/model_grpc.py\n--- a/python/custom_transformer/model_grpc.py\n+++ b/python/custom_transformer/model_grpc.py\n@@ -18,7 +18,6 @@\n \n from kserve import Model, ModelServer, model_server\n from kserve.grpc.grpc_predict_v2_pb2 import ModelInferRequest\n-from kserve.handlers.v2_datamodels import InferenceRequest\n \n \n class ImageTransformer(Model):\n@@ -28,7 +27,7 @@\n         self.protocol = protocol\n         self.model_name = name\n \n-    def preprocess(self, request: Union[Dict, ModelInferRequest, InferenceRequest], headers=None) -> ModelInferRequest:\n+    def preprocess(self, request: Union[Dict, ModelInferRequest], headers=None) -> ModelInferRequest:\n         if isinstance(request, ModelInferRequest):\n             return request\n         else:\n", "issue": "Kserve defaulting causing duplicates of environment variable \n/kind bug\r\n\r\n**What steps did you take and what happened:**\r\nCreate example xgboost isvc and enable gRPC\r\n```\r\napiVersion: \"serving.kserve.io/v1beta1\"\r\nkind: \"InferenceService\"\r\nmetadata:\r\n  name: \"xgboost-iris\"\r\nspec:\r\n  predictor:\r\n    xgboost:\r\n      protocolVersion: \"v2\"\r\n      storageUri: \"gs://kfserving-examples/models/xgboost/iris\"\r\n      ports:\r\n      - containerPort: 9000\r\n        name: h2c\r\n        protocol: TCP\r\n```\r\n\r\nThe pod spec has duplicated environment variable\r\n```\r\n    Environment:\r\n      MLSERVER_MODEL_NAME:            xgboost-iris\r\n      MLSERVER_MODEL_URI:             /mnt/models\r\n      MLSERVER_MODEL_NAME:            xgboost-iris\r\n      MLSERVER_MODEL_URI:             /mnt/models\r\n```\r\n\r\nAdditionally, attempt to override the defaults leads to duplicated environment variable with different values\r\n\r\n```\r\napiVersion: \"serving.kserve.io/v1beta1\"\r\nkind: \"InferenceService\"\r\nmetadata:\r\n  name: \"xgboost-iris\"\r\nspec:\r\n  predictor:\r\n    xgboost:\r\n      protocolVersion: \"v2\"\r\n      storageUri: \"gs://kfserving-examples/models/xgboost/iris\"\r\n      ports:\r\n      - containerPort: 9000\r\n        name: h2c\r\n        protocol: TCP\r\n      env:\r\n      - name: MLSERVER_MODEL_NAME\r\n        value: my-model\r\n```\r\n\r\nThe pod spec:\r\n```\r\n    Environment:\r\n      MLSERVER_MODEL_NAME:            my-model\r\n      MLSERVER_MODEL_NAME:            xgboost-iris\r\n      MLSERVER_MODEL_URI:                /mnt/models\r\n```\r\n\r\n**What did you expect to happen:**\r\n- Defaulting should not duplicate environment variable and should prioritise user's defined environment variable\r\n\r\n**Anything else you would like to add:**\r\nI believe it's because the defaulter always append `.Env` without checking the presence of existing environment variable. (https://github.com/kserve/kserve/blob/a6ed8e4b006e27433de2336e0e8b7cec11137dc1/pkg/apis/serving/v1beta1/inference_service_defaults.go#L264)\r\n\r\n\r\n**Environment:**\r\n\r\n- Kserve: 0.8.0\n", "before_files": [{"content": "# Copyright 2022 The KServe Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#    http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport argparse\nimport base64\nfrom typing import Dict, Union\n\nfrom kserve import Model, ModelServer, model_server\nfrom kserve.grpc.grpc_predict_v2_pb2 import ModelInferRequest\nfrom kserve.handlers.v2_datamodels import InferenceRequest\n\n\nclass ImageTransformer(Model):\n    def __init__(self, name: str, predictor_host: str, protocol: str):\n        super().__init__(name)\n        self.predictor_host = predictor_host\n        self.protocol = protocol\n        self.model_name = name\n\n    def preprocess(self, request: Union[Dict, ModelInferRequest, InferenceRequest], headers=None) -> ModelInferRequest:\n        if isinstance(request, ModelInferRequest):\n            return request\n        else:\n            payload = [\n                {\n                    \"name\": \"input-0\",\n                    \"shape\": [],\n                    \"datatype\": \"BYTES\",\n                    \"contents\": {\n                        \"bytes_contents\": [base64.b64decode(request[\"inputs\"][0][\"data\"][0])]\n                    }\n                }\n            ]\n            return ModelInferRequest(model_name=self.model_name, inputs=payload)\n\n\nparser = argparse.ArgumentParser(parents=[model_server.parser])\nparser.add_argument(\n    \"--predictor_host\", help=\"The URL for the model predict function\", required=True\n)\nparser.add_argument(\n    \"--protocol\", help=\"The protocol for the predictor\", default=\"v1\"\n)\nparser.add_argument(\n    \"--model_name\", help=\"The name that the model is served under.\"\n)\nargs, _ = parser.parse_known_args()\n\nif __name__ == \"__main__\":\n    model = ImageTransformer(args.model_name, predictor_host=args.predictor_host,\n                             protocol=args.protocol)\n    ModelServer(workers=1).start([model])\n", "path": "python/custom_transformer/model_grpc.py"}], "after_files": [{"content": "# Copyright 2022 The KServe Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#    http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport argparse\nimport base64\nfrom typing import Dict, Union\n\nfrom kserve import Model, ModelServer, model_server\nfrom kserve.grpc.grpc_predict_v2_pb2 import ModelInferRequest\n\n\nclass ImageTransformer(Model):\n    def __init__(self, name: str, predictor_host: str, protocol: str):\n        super().__init__(name)\n        self.predictor_host = predictor_host\n        self.protocol = protocol\n        self.model_name = name\n\n    def preprocess(self, request: Union[Dict, ModelInferRequest], headers=None) -> ModelInferRequest:\n        if isinstance(request, ModelInferRequest):\n            return request\n        else:\n            payload = [\n                {\n                    \"name\": \"input-0\",\n                    \"shape\": [],\n                    \"datatype\": \"BYTES\",\n                    \"contents\": {\n                        \"bytes_contents\": [base64.b64decode(request[\"inputs\"][0][\"data\"][0])]\n                    }\n                }\n            ]\n            return ModelInferRequest(model_name=self.model_name, inputs=payload)\n\n\nparser = argparse.ArgumentParser(parents=[model_server.parser])\nparser.add_argument(\n    \"--predictor_host\", help=\"The URL for the model predict function\", required=True\n)\nparser.add_argument(\n    \"--protocol\", help=\"The protocol for the predictor\", default=\"v1\"\n)\nparser.add_argument(\n    \"--model_name\", help=\"The name that the model is served under.\"\n)\nargs, _ = parser.parse_known_args()\n\nif __name__ == \"__main__\":\n    model = ImageTransformer(args.model_name, predictor_host=args.predictor_host,\n                             protocol=args.protocol)\n    ModelServer(workers=1).start([model])\n", "path": "python/custom_transformer/model_grpc.py"}]}