code: def update(
      cls,
      deployment_name: str,
      bento: Tag | str | None = None,
      description: str | None = None,
      expose_endpoint: bool | None = None,
      cluster_name: str | None = None,
      kube_namespace: str | None = None,
      resource_instance: str | None = None,
      hpa_conf: DeploymentTargetHPAConf | None = None,
      runners_config: dict[str, DeploymentTargetRunnerConfig]
      | None = None,
      api_server_config: DeploymentTargetConfig | None = None,
      mode: DeploymentMode | None = None,
      type: DeploymentTargetType | None = None,
      context: str | None = None,
      labels: dict[str, str] | None = None,
      canary_rules: t.List[DeploymentTargetCanaryRule] | None = None,
      latest_bento: bool = False,
  ) -> DeploymentSchema:
      from bentoml import get as get_bento
  
      if mode is None:
          mode = DeploymentMode.Function
      if type is None:
          type = DeploymentTargetType.STABLE
  
      if cluster_name is None:
          cluster_name = cls._get_default_cluster(context)
      if kube_namespace is None:
          kube_namespace = cls._get_default_kube_namespace(
              cluster_name, context
          )
  
      base_schema = cls.get(
          deployment_name, context, cluster_name, kube_namespace
      )
      # Deployment target always has length of 1
      if base_schema.latest_revision is None:
          raise BentoMLException(
              f"Deployment {deployment_name} has no latest revision"
          )
      deployment_target = base_schema.latest_revision.targets[0]
  
      if bento is None:
          # NOTE: bento.repository.name is the bento.name, and bento.name is the bento.version
          # from bentocloud to bentoml.Tag concept
          bento = deployment_target.bento.repository.name
      bento = Tag.from_taglike(bento)
      if (
          latest_bento
          and bento.version is None
          or bento.version == "latest"
      ):
          bento = get_bento(bento).tag
      elif bento.version is None:
          bento.version = deployment_target.bento.name
  
      updated_config = bentoml_cattr.unstructure(
          deployment_target.config
      )
      if hpa_conf is not None:
          hpa_conf_dct = bentoml_cattr.unstructure(hpa_conf)
          if "hpa_conf" in updated_config:
              if updated_config["hpa_conf"] is None:
                  updated_config["hpa_conf"] = {}
              config_merger.merge(
                  updated_config["hpa_conf"], hpa_conf_dct
              )
          if (
              "runners" in updated_config
              and updated_config["runners"] is not None
          ):
              for _, runner in updated_config["runners"].items():
                  if runner["hpa_conf"] is None:
                      runner["hpa_conf"] = {}
                  config_merger.merge(runner["hpa_conf"], hpa_conf_dct)
      if resource_instance is not None:
          updated_config["resource_instance"] = resource_instance
          if updated_config.get("runners") is not None:
              for runner in updated_config["runners"].values():
                  runner["resource_instance"] = resource_instance
      if expose_endpoint is not None:
          updated_config["enable_ingress"] = expose_endpoint
  
      if api_server_config is not None:
          if runners_config is not None:
              api_server_config.runners = runners_config
          config_merger.merge(
              updated_config,
              bentoml_cattr.unstructure(api_server_config),
          )
      elif runners_config is not None:
          config_merger.merge(
              updated_config,
              {
                  "runners": {
                      k: bentoml_cattr.unstructure(v)
                      for k, v in runners_config.items()
                  }
              },
          )
  
      dct_update: dict[str, t.Any] = {
          "mode": first_not_none(mode, base_schema.mode),
          "labels": first_not_none(
              [
                  {"key": key, "value": value}
                  for key, value in labels.items()
              ]
              if labels
              else None,
              [
                  bentoml_cattr.unstructure(i)
                  for i in base_schema.labels
              ],
          ),
          "description": description,
      }
      update_target = {
          "type": first_not_none(type, deployment_target.type),
          "bento": first_not_none(
              bento.version, deployment_target.bento.name
          ),
          "bento_repository": first_not_none(
              bento.name, deployment_target.bento.repository.name
          ),
          "config": updated_config,
      }
  
      rules = first_not_none(
          [bentoml_cattr.unstructure(i) for i in canary_rules]
          if canary_rules
          else None,
          [
              bentoml_cattr.unstructure(i)
              for i in deployment_target.canary_rules
          ]
          if deployment_target.canary_rules
          else None,
      )
      if rules:
          update_target["canary_rules"] = rules
  
      # update the target
      dct_update["targets"] = [update_target]
  
      return cls._update_deployment(
          deployment_name=deployment_name,
          update_deployment_schema=bentoml_cattr.structure(
              dct_update, UpdateDeploymentSchema
          ),
          context=context,
          cluster_name=cluster_name,
          kube_namespace=kube_namespace,
      )
  
imports: from __future__ import annotations
  import json
  import logging
  import typing
  import attr
  from deepmerge.merger import Merger
  from ...exceptions import BentoMLException
  from ..tag import Tag
  from ..utils import bentoml_cattr
  from ..utils import first_not_none
  from ..utils import resolve_user_filepath
  from .config import get_rest_api_client
  from .schemas import CreateDeploymentSchema
  from .schemas import DeploymentListSchema
  from .schemas import DeploymentMode
  from .schemas import DeploymentSchema
  from .schemas import DeploymentTargetCanaryRule
  from .schemas import DeploymentTargetConfig
  from .schemas import DeploymentTargetHPAConf
  from .schemas import DeploymentTargetRunnerConfig
  from .schemas import DeploymentTargetType
  from .schemas import FullDeploymentSchema
  from .schemas import UpdateDeploymentSchema
label_desc: Use image node_id 5 for calling the Deployment obj's underlying member method code with example usage: obj.update(cls, deployment_name, bento, description, expose_endpoint, cluster_name, kube_namespace, resource_instance, hpa_conf, runners_config, api_server_config, mode, type, context, labels, canary_rules, latest_bento) and returns: cls