class_docstr: cluster
  
  This is meant as a thin wrapper around GKE clusters and the raw kubernetes
  python api, mainly to provide a simple interface for the most common
  cluster tasks.
class_docstr_tok: ["cluster","This","is","meant","as","a","thin","wrapper","around","GKE","clusters","and","the","raw","kubernetes","python","api",",","mainly","to","provide","a","simple","interface","for","the","most","common","cluster","tasks","."]
docstr: connects to cluster instance
  
  Returns:
  True on success, False otherwise
docstr_tok: ["connects","to","cluster","instance","Returns",":","True","on","success",",","False","otherwise"]
code: def connect(self) -> bool:
      """connects to cluster instance
  
      Returns:
      True on success, False otherwise
      """
  
      self.connected = False
  
      # if gke cluster info already populated, then noop
      # otherwise uses cluster api to get cluster info
      if not self._set_gke_cluster():
          return False
  
      if self._gke_cluster is None:
          return False
  
      # resolve our zone in case the wildcard '-' was passed
      self.zone = self._gke_cluster.zone
  
      # set our name in case None was passed
      self.name = self._gke_cluster.name
  
      # ok, now we set up the kubernetes api using our cluster info and
      # credentials
      cfg = kubernetes.client.Configuration()
      cfg.host = "https://{}:443".format(self._gke_cluster.endpoint)
      cfg.verify_ssl = (
          False  # True #todo: figure out how to do this properly
      )
      # cfg.ssl_ca_cert = c.master_auth.cluster_ca_certificate
      cfg.api_key = {
          "authorization": "Bearer " + self.credentials.token
      }
  
      api_client = kubernetes.client.ApiClient(cfg)
  
      self._core_api = kubernetes.client.CoreV1Api(api_client)
      self._batch_api = kubernetes.client.BatchV1Api(api_client)
      self._apps_api = kubernetes.client.AppsV1Api(api_client)
  
      self._tpu_api = googleapiclient.discovery.build(
          "tpu",
          "v1",
          credentials=self.credentials,
          cache_discovery=False,
      )
  
      # using this as a connection test
      # todo: is there a better way to verify connectivity?
      self.connected = (
          self._core_api.get_api_resources(async_req=False) is not None
      )
  
      return self.connected
  
imports: import json
  import logging
  import re
  from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple
  import googleapiclient
  import kubernetes
  import requests
  import urllib3
  import yaml
  from google.auth.credentials import Credentials
  from google.cloud.container_v1 import ClusterManagerClient
  from google.cloud.container_v1.types import NodePool, Cluster
  from googleapiclient import discovery
  from googleapiclient.http import HttpRequest
  from kubernetes.client import V1Container, V1DaemonSet, V1EnvVar, V1Job, V1JobSpec, V1ObjectMeta, V1Pod, V1PodSpec, V1PodTemplateSpec, V1ResourceRequirements, V1Toleration
  from kubernetes.client.api_client import ApiClient
  import caliban.config.experiment
  import caliban.platform.gke.constants
  import caliban.platform.gke.util
  from caliban.history.types import Experiment, Job, JobSpec, JobStatus, Platform
  from caliban.platform.cloud.types import GPU, TPU, Accelerator, GPUSpec, MachineType, TPUSpec
  from caliban.platform.gke.types import NodeImage, OpStatus, ReleaseChannel
  from caliban.platform.gke.util import trap
  import caliban.util.metrics
label_desc: Use image node_id 2 for calling the Cluster obj's underlying member method code with example usage: obj.connect() and returns: self, False, False