airflow.providers.google.cloud.hooks.kubernetes_engine

This module contains a Google Kubernetes Engine Hook.

Module Contents

Classes

GKEHook

Hook for managing Google Kubernetes Engine cluster APIs.

GKEAsyncHook

Hook implemented with usage of asynchronous client of GKE.

GKEPodHook

Hook for managing Google Kubernetes Engine pod APIs.

GKEPodAsyncHook

Hook for managing Google Kubernetes Engine pods APIs in asynchronous way.

Attributes

OPERATIONAL_POLL_INTERVAL

airflow.providers.google.cloud.hooks.kubernetes_engine.OPERATIONAL_POLL_INTERVAL = 15[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

Hook for managing 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]

Returns ClusterManagerClient.

get_conn()[source]

Returns connection for the hook.

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

Given an operation, continuously fetches the status from Google Cloud until either completion or an error occurring.

Parameters
Returns

A new, updated operation fetched from Google Cloud

Return type

google.cloud.container_v1.types.Operation

get_operation(operation_name, project_id=None)[source]

Fetches the operation from Google Cloud.

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

  • project_id (str | None) – 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]

Deletes the cluster, including 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) – A boolean value which makes method to sleep while operation of deletion is not finished.

  • 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]

Creates a cluster, consisting of the specified number and 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]

Gets 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.

Returns

google.cloud.container_v1.types.Cluster

Return type

google.cloud.container_v1.types.Cluster

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

Hook implemented with usage of asynchronous client of GKE.

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

Fetches the 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.GKEPodHook(cluster_url, ssl_ca_cert, *args, **kwargs)[source]

Bases: airflow.providers.google.common.hooks.base_google.GoogleBaseHook, airflow.providers.cncf.kubernetes.utils.pod_manager.PodOperatorHookProtocol

Hook for managing Google Kubernetes Engine pod APIs.

property is_in_cluster: bool[source]

Expose whether the hook is configured with load_incluster_config or not.

api_client()[source]
core_v1_client()[source]

Get authenticated CoreV1Api object.

get_namespace()[source]

Get the namespace configured by the Airflow connection.

get_xcom_sidecar_container_image()[source]

Returns the xcom sidecar image defined in the connection.

Implemented for compatibility with KubernetesHook.

get_xcom_sidecar_container_resources()[source]

Returns the xcom sidecar resources defined in the connection.

Implemented for compatibility with KubernetesHook.

get_conn()[source]

Returns connection for the hook.

get_pod(name, namespace)[source]

Gets pod’s object.

Parameters
  • name (str) – Name of the pod.

  • namespace (str) – Name of the pod’s namespace.

class airflow.providers.google.cloud.hooks.kubernetes_engine.GKEPodAsyncHook(cluster_url, ssl_ca_cert, **kwargs)[source]

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

Hook for managing Google Kubernetes Engine pods APIs in asynchronous way.

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

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

sync_hook_class[source]
scopes = ['https://www.googleapis.com/auth/cloud-platform'][source]
async get_conn(token)[source]
async get_pod(name, namespace)[source]

Gets pod’s object.

Parameters
  • name (str) – Name of the pod.

  • namespace (str) – Name of the pod’s namespace.

async delete_pod(name, namespace)[source]

Deletes pod’s object.

Parameters
  • name (str) – Name of the pod.

  • namespace (str) – Name of the pod’s namespace.

async read_logs(name, namespace)[source]

Reads logs inside the pod while starting containers inside. All the logs will be outputted with its timestamp to track the logs after the execution of the pod is completed. The method is used for async output of the logs only in the pod failed it execution or the task was cancelled by the user.

Parameters
  • name (str) – Name of the pod.

  • namespace (str) – Name of the pod’s namespace.

Was this entry helpful?