code: def make_safe_label_value(string):
      """
      Normalize a provided label to be of valid length and characters.
  
      Valid label values must be 63 characters or less and must be empty or begin and
      end with an alphanumeric character ([a-z0-9A-Z]) with dashes (-), underscores (_),
      dots (.), and alphanumerics between.
  
      If the label value is greater than 63 chars once made safe, or differs in any
      way from the original value sent to this function, then we need to truncate to
      53 chars, and append it with a unique hash.
      """
      safe_label = re2.sub(
          r"^[^a-z0-9A-Z]*|[^a-zA-Z0-9_\-\.]|[^a-z0-9A-Z]*$", "", string
      )
  
      if len(safe_label) > MAX_LABEL_LEN or string != safe_label:
          safe_hash = md5(string.encode()).hexdigest()[:9]
          safe_label = (
              safe_label[: MAX_LABEL_LEN - len(safe_hash) - 1]
              + "-"
              + safe_hash
          )
  
      return safe_label
  
file_path: airflow/airflow/kubernetes/pre_7_4_0_compatibility/pod_generator_deprecated.py
imports: from __future__ import annotations
  import copy
  import uuid
  import re2
  from kubernetes.client import models
  from airflow.utils.hashlib_wrapper import md5
label_desc: Use image node_id 1 for calling a global function with example usage: make_safe_label_value(string) and returns: safe_label