sigs.k8s.io/kueue@v0.6.2/site/static/examples/python/install-kueue-queues.py (about)

     1  #!/usr/bin/env python3
     2  
     3  from kubernetes import utils, config, client
     4  import tempfile
     5  import requests
     6  import argparse
     7  
     8  # install-kueue-queues.py will:
     9  # 1. install queue from the latest or a specific version on GitHub
    10  # This example will demonstrate installing Kueue and applying a YAML file (local) to install Kueue
    11  
    12  # Make sure your cluster is running!
    13  config.load_kube_config()
    14  crd_api = client.CustomObjectsApi()
    15  api_client = crd_api.api_client
    16  
    17  
    18  def get_parser():
    19      parser = argparse.ArgumentParser(
    20          description="Submit Kueue Job Example",
    21          formatter_class=argparse.RawTextHelpFormatter,
    22      )
    23      parser.add_argument(
    24          "--version",
    25          help="Version of Kueue to install (if undefined, will install from master branch)",
    26          default=None,
    27      )
    28      return parser
    29  
    30  
    31  def main():
    32      """
    33      Install Kueue and the Queue components.
    34  
    35      This will error if they are already installed.
    36      """
    37      parser = get_parser()
    38      args, _ = parser.parse_known_args()
    39      install_kueue(args.version)
    40  
    41  
    42  def get_install_url(version):
    43      """
    44      Get the install version.
    45  
    46      If a version is specified, use it. Otherwise install
    47      from the main branch.
    48      """
    49      if version is not None:
    50          return f"https://github.com/kubernetes-sigs/kueue/releases/download/v{version}/manifests.yaml"
    51      return "https://github.com/kubernetes-sigs/kueue/config/default?ref=main"
    52  
    53  
    54  def install_kueue(version):
    55      """
    56      Install Kueue of a particular version.
    57      """
    58      print("⭐️ Installing Kueue...")
    59      url = get_install_url(version)
    60      with tempfile.NamedTemporaryFile(delete=True) as install_yaml:
    61          res = requests.get(url)
    62          assert res.status_code == 200
    63          install_yaml.write(res.content)
    64          utils.create_from_yaml(api_client, install_yaml.name)
    65  
    66  
    67  if __name__ == "__main__":
    68      main()