airflow.providers.google.cloud.hooks.kubernetes_engine

This module contains a Google Kubernetes Engine Hook.

Module Contents

Classes

GKEClusterConnection

Helper for establishing connection to GKE cluster.

GKEHook

Google Kubernetes Engine cluster APIs.

GKEAsyncHook

Asynchronous client of GKE.

GKEKubernetesHook

GKE authenticated hook for standard Kubernetes API.

GKEKubernetesAsyncHook

Async GKE authenticated hook for standard Kubernetes API.

GKEDeploymentHook

Google Kubernetes Engine Deployment APIs.

GKECustomResourceHook

Google Kubernetes Engine Custom Resource APIs.

GKEPodHook

Google Kubernetes Engine pod APIs.

GKEJobHook

Google Kubernetes Engine Job APIs.

GKEPodAsyncHook

Google Kubernetes Engine pods APIs asynchronously.

Attributes

OPERATIONAL_POLL_INTERVAL

airflow.providers.google.cloud.hooks.kubernetes_engine.OPERATIONAL_POLL_INTERVAL = 15[source]
class airflow.providers.google.cloud.hooks.kubernetes_engine.GKEClusterConnection(cluster_url, ssl_ca_cert, credentials, enable_tcp_keepalive=False)[source]

Helper for establishing connection to GKE cluster.

get_conn()[source]
class airflow.providers.google.cloud.hooks.kubernetes_engine.GKEHook(gcp_conn_id='google_cloud_default', location=None, impersonation_chain=None, **kwargs)[source]

Bases: airflow.providers.google.common.hooks.base_google.GoogleBaseHook

Google Kubernetes Engine cluster APIs.

All the methods in the hook where project_id is used must be called with keyword arguments rather than positional.

get_cluster_manager_client()[source]

Create or get a ClusterManagerClient.

get_conn()[source]

Return connection for the hook.

get_client()[source]
wait_for_operation(operation, project_id=PROVIDE_PROJECT_ID)[source]

Continuously fetch the status from Google Cloud.

This is done until the given operation completes, or raises an error.

Parameters
Returns

A new, updated operation fetched from Google Cloud.

Return type

google.cloud.container_v1.types.Operation

get_operation(operation_name, project_id=PROVIDE_PROJECT_ID)[source]

Get an operation from Google Cloud.

Parameters
  • operation_name (str) – Name of operation to fetch

  • project_id (str) – Google Cloud project ID

Returns

The new, updated operation from Google Cloud

Return type

google.cloud.container_v1.types.Operation

delete_cluster(name, project_id=PROVIDE_PROJECT_ID, wait_to_complete=True, retry=DEFAULT, timeout=None)[source]

Delete the cluster, the Kubernetes endpoint, and all worker nodes.

Firewalls and routes that were configured during cluster creation are also deleted. Other Google Compute Engine resources that might be in use by the cluster (e.g. load balancer resources) will not be deleted if they were not present at the initial create time.

Parameters
  • name (str) – The name of the cluster to delete.

  • project_id (str) – Google Cloud project ID.

  • wait_to_complete (bool) – If True, wait until the deletion is finished before returning.

  • retry (google.api_core.retry.Retry | google.api_core.gapic_v1.method._MethodDefault) – Retry object used to determine when/if to retry requests. If None is specified, requests will not be retried.

  • timeout (float | None) – The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

Returns

The full url to the delete operation if successful, else None.

Return type

google.cloud.container_v1.types.Operation | None

create_cluster(cluster, project_id=PROVIDE_PROJECT_ID, wait_to_complete=True, retry=DEFAULT, timeout=None)[source]

Create a cluster.

This should consist of the specified number, and the type of Google Compute Engine instances.

Parameters
  • cluster (dict | google.cloud.container_v1.types.Cluster) – A Cluster protobuf or dict. If dict is provided, it must be of the same form as the protobuf message google.cloud.container_v1.types.Cluster.

  • project_id (str) – Google Cloud project ID.

  • wait_to_complete (bool) – A boolean value which makes method to sleep while operation of creation is not finished.

  • retry (google.api_core.retry.Retry | google.api_core.gapic_v1.method._MethodDefault) – A retry object (google.api_core.retry.Retry) used to retry requests. If None is specified, requests will not be retried.

  • timeout (float | None) – The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

Returns

The full url to the new, or existing, cluster.

Raises
  • ParseError – On JSON parsing problems when trying to convert dict.

  • AirflowException – cluster is not dict type nor Cluster proto type.

Return type

google.cloud.container_v1.types.Operation | google.cloud.container_v1.types.Cluster

get_cluster(name, project_id=PROVIDE_PROJECT_ID, retry=DEFAULT, timeout=None)[source]

Get details of specified cluster.

Parameters
  • name (str) – The name of the cluster to retrieve.

  • project_id (str) – Google Cloud project ID.

  • retry (google.api_core.retry.Retry | google.api_core.gapic_v1.method._MethodDefault) – A retry object used to retry requests. If None is specified, requests will not be retried.

  • timeout (float | None) – The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

check_cluster_autoscaling_ability(cluster)[source]

Check if the specified Cluster has ability to autoscale.

Cluster should be Autopilot, with Node Auto-provisioning or regular auto-scaled node pools. Returns True if the Cluster supports autoscaling, otherwise returns False.

Parameters

cluster (google.cloud.container_v1.types.Cluster | dict) – The Cluster object.

class airflow.providers.google.cloud.hooks.kubernetes_engine.GKEAsyncHook(gcp_conn_id='google_cloud_default', location=None, impersonation_chain=None)[source]

Bases: airflow.providers.google.common.hooks.base_google.GoogleBaseAsyncHook

Asynchronous client of GKE.

sync_hook_class[source]
async get_operation(operation_name, project_id=PROVIDE_PROJECT_ID)[source]

Fetch an operation from Google Cloud.

Parameters
  • operation_name (str) – Name of operation to fetch.

  • project_id (str) – Google Cloud project ID.

Returns

The new, updated operation from Google Cloud.

Return type

google.cloud.container_v1.types.Operation

class airflow.providers.google.cloud.hooks.kubernetes_engine.GKEKubernetesHook(cluster_url, ssl_ca_cert, enable_tcp_keepalive=False, *args, **kwargs)[source]

Bases: airflow.providers.google.common.hooks.base_google.GoogleBaseHook, airflow.providers.cncf.kubernetes.hooks.kubernetes.KubernetesHook

GKE authenticated hook for standard Kubernetes API.

This hook provides full set of the standard Kubernetes API provided by the KubernetesHook, and at the same time it provides a GKE authentication, so it makes it possible to KubernetesHook functionality against GKE clusters.

get_conn()[source]

Return connection for the hook.

check_kueue_deployment_running(name, namespace)[source]
apply_from_yaml_file(yaml_file=None, yaml_objects=None, verbose=False, namespace='default')[source]

Perform an action from a yaml file.

Parameters
  • yaml_file (str | None) – Contains the path to yaml file.

  • yaml_objects (list[dict] | None) – List of YAML objects; used instead of reading the yaml_file.

  • verbose (bool) – If True, print confirmation from create action. Default is False.

  • namespace (str) – Contains the namespace to create all resources inside. The namespace must preexist otherwise the resource creation will fail.

class airflow.providers.google.cloud.hooks.kubernetes_engine.GKEKubernetesAsyncHook(cluster_url, ssl_ca_cert, gcp_conn_id='google_cloud_default', impersonation_chain=None, enable_tcp_keepalive=True, **kwargs)[source]

Bases: airflow.providers.google.common.hooks.base_google.GoogleBaseAsyncHook, airflow.providers.cncf.kubernetes.hooks.kubernetes.AsyncKubernetesHook

Async GKE authenticated hook for standard Kubernetes API.

This hook provides full set of the standard Kubernetes API provided by the AsyncKubernetesHook, and at the same time it provides a GKE authentication, so it makes it possible to KubernetesHook functionality against GKE clusters.

sync_hook_class[source]
scopes = ['https://www.googleapis.com/auth/cloud-platform'][source]
async get_conn()[source]
class airflow.providers.google.cloud.hooks.kubernetes_engine.GKEDeploymentHook(cluster_url, ssl_ca_cert, enable_tcp_keepalive=False, *args, **kwargs)[source]

Bases: GKEKubernetesHook

Google Kubernetes Engine Deployment APIs.

class airflow.providers.google.cloud.hooks.kubernetes_engine.GKECustomResourceHook(cluster_url, ssl_ca_cert, enable_tcp_keepalive=False, *args, **kwargs)[source]

Bases: GKEKubernetesHook

Google Kubernetes Engine Custom Resource APIs.

class airflow.providers.google.cloud.hooks.kubernetes_engine.GKEPodHook(cluster_url, ssl_ca_cert, disable_tcp_keepalive=None, gcp_conn_id='google_cloud_default', impersonation_chain=None, **kwargs)[source]

Bases: GKEKubernetesHook

Google Kubernetes Engine pod APIs.

class airflow.providers.google.cloud.hooks.kubernetes_engine.GKEJobHook(cluster_url, ssl_ca_cert, enable_tcp_keepalive=False, *args, **kwargs)[source]

Bases: GKEKubernetesHook

Google Kubernetes Engine Job APIs.

class airflow.providers.google.cloud.hooks.kubernetes_engine.GKEPodAsyncHook(cluster_url, ssl_ca_cert, gcp_conn_id='google_cloud_default', impersonation_chain=None, enable_tcp_keepalive=True, **kwargs)[source]

Bases: GKEKubernetesAsyncHook

Google Kubernetes Engine pods APIs asynchronously.

Parameters
  • cluster_url (str) – The URL pointed to the cluster.

  • ssl_ca_cert (str) – SSL certificate used for authentication to the pod.

Was this entry helpful?