Source code for airflow.providers.google.cloud.links.kubernetes_engine
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
from __future__ import annotations
import json
from typing import TYPE_CHECKING
from google.cloud.container_v1.types import Cluster
from airflow.providers.google.cloud.links.base import BaseGoogleLink
if TYPE_CHECKING:
from airflow.utils.context import Context
[docs]
KUBERNETES_BASE_LINK = "/kubernetes"
[docs]
KUBERNETES_CLUSTER_LINK = (
KUBERNETES_BASE_LINK + "/clusters/details/{location}/{cluster_name}/details?project={project_id}"
)
[docs]
KUBERNETES_POD_LINK = (
KUBERNETES_BASE_LINK
+ "/pod/{location}/{cluster_name}/{namespace}/{pod_name}/details?project={project_id}"
)
[docs]
KUBERNETES_JOB_LINK = (
KUBERNETES_BASE_LINK
+ "/job/{location}/{cluster_name}/{namespace}/{job_name}/details?project={project_id}"
)
[docs]
KUBERNETES_WORKLOADS_LINK = (
KUBERNETES_BASE_LINK + '/workload/overview?project={project_id}&pageState=("savedViews":'
'("c":%5B"gke%2F{location}%2F{cluster_name}"%5D,"n":%5B"{namespace}"%5D))'
)
[docs]
class KubernetesEngineClusterLink(BaseGoogleLink):
"""Helper class for constructing Kubernetes Engine Cluster Link."""
[docs]
name = "Kubernetes Cluster"
[docs]
key = "kubernetes_cluster_conf"
@classmethod
[docs]
def persist(cls, context: Context, **value):
cluster = value.get("cluster")
if isinstance(cluster, dict):
cluster = Cluster.from_json(json.dumps(cluster))
if not cluster:
raise ValueError("Cluster must be provided for KubernetesEngineClusterLink.")
super().persist(
context=context,
cluster_name=cluster.name,
)
[docs]
class KubernetesEnginePodLink(BaseGoogleLink):
"""Helper class for constructing Kubernetes Engine Pod Link."""
[docs]
name = "Kubernetes Pod"
[docs]
key = "kubernetes_pod_conf"
[docs]
class KubernetesEngineJobLink(BaseGoogleLink):
"""Helper class for constructing Kubernetes Engine Job Link."""
[docs]
name = "Kubernetes Job"
[docs]
key = "kubernetes_job_conf"
[docs]
class KubernetesEngineWorkloadsLink(BaseGoogleLink):
"""Helper class for constructing Kubernetes Engine Workloads Link."""
[docs]
name = "Kubernetes Workloads"
[docs]
key = "kubernetes_workloads_conf"