apache-airflow-providers-cncf-kubernetes 3.1.0__py3-none-any.whl → 10.10.0rc1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- airflow/providers/cncf/kubernetes/__init__.py +18 -23
- airflow/providers/cncf/kubernetes/backcompat/__init__.py +17 -0
- airflow/providers/cncf/kubernetes/backcompat/backwards_compat_converters.py +31 -49
- airflow/providers/cncf/kubernetes/callbacks.py +200 -0
- airflow/providers/cncf/kubernetes/cli/__init__.py +16 -0
- airflow/providers/cncf/kubernetes/cli/kubernetes_command.py +195 -0
- airflow/providers/cncf/kubernetes/decorators/kubernetes.py +163 -0
- airflow/providers/cncf/kubernetes/decorators/kubernetes_cmd.py +118 -0
- airflow/providers/cncf/kubernetes/exceptions.py +37 -0
- airflow/providers/cncf/kubernetes/executors/__init__.py +17 -0
- airflow/providers/cncf/kubernetes/executors/kubernetes_executor.py +831 -0
- airflow/providers/cncf/kubernetes/executors/kubernetes_executor_types.py +91 -0
- airflow/providers/cncf/kubernetes/executors/kubernetes_executor_utils.py +736 -0
- airflow/providers/cncf/kubernetes/executors/local_kubernetes_executor.py +306 -0
- airflow/providers/cncf/kubernetes/get_provider_info.py +249 -50
- airflow/providers/cncf/kubernetes/hooks/kubernetes.py +846 -112
- airflow/providers/cncf/kubernetes/k8s_model.py +62 -0
- airflow/providers/cncf/kubernetes/kube_client.py +156 -0
- airflow/providers/cncf/kubernetes/kube_config.py +125 -0
- airflow/providers/cncf/kubernetes/kubernetes_executor_templates/__init__.py +16 -0
- airflow/providers/cncf/kubernetes/kubernetes_executor_templates/basic_template.yaml +79 -0
- airflow/providers/cncf/kubernetes/kubernetes_helper_functions.py +165 -0
- airflow/providers/cncf/kubernetes/operators/custom_object_launcher.py +368 -0
- airflow/providers/cncf/kubernetes/operators/job.py +646 -0
- airflow/providers/cncf/kubernetes/operators/kueue.py +132 -0
- airflow/providers/cncf/kubernetes/operators/pod.py +1417 -0
- airflow/providers/cncf/kubernetes/operators/resource.py +191 -0
- airflow/providers/cncf/kubernetes/operators/spark_kubernetes.py +336 -35
- airflow/providers/cncf/kubernetes/pod_generator.py +592 -0
- airflow/providers/cncf/kubernetes/pod_template_file_examples/__init__.py +16 -0
- airflow/providers/cncf/kubernetes/pod_template_file_examples/dags_in_image_template.yaml +68 -0
- airflow/providers/cncf/kubernetes/pod_template_file_examples/dags_in_volume_template.yaml +74 -0
- airflow/providers/cncf/kubernetes/pod_template_file_examples/git_sync_template.yaml +95 -0
- airflow/providers/cncf/kubernetes/python_kubernetes_script.jinja2 +51 -0
- airflow/providers/cncf/kubernetes/python_kubernetes_script.py +92 -0
- airflow/providers/cncf/kubernetes/resource_convert/__init__.py +16 -0
- airflow/providers/cncf/kubernetes/resource_convert/configmap.py +52 -0
- airflow/providers/cncf/kubernetes/resource_convert/env_variable.py +39 -0
- airflow/providers/cncf/kubernetes/resource_convert/secret.py +40 -0
- airflow/providers/cncf/kubernetes/secret.py +128 -0
- airflow/providers/cncf/kubernetes/sensors/spark_kubernetes.py +30 -14
- airflow/providers/cncf/kubernetes/template_rendering.py +81 -0
- airflow/providers/cncf/kubernetes/triggers/__init__.py +16 -0
- airflow/providers/cncf/kubernetes/triggers/job.py +176 -0
- airflow/providers/cncf/kubernetes/triggers/pod.py +344 -0
- airflow/providers/cncf/kubernetes/utils/__init__.py +3 -0
- airflow/providers/cncf/kubernetes/utils/container.py +118 -0
- airflow/providers/cncf/kubernetes/utils/delete_from.py +154 -0
- airflow/providers/cncf/kubernetes/utils/k8s_resource_iterator.py +46 -0
- airflow/providers/cncf/kubernetes/utils/pod_manager.py +887 -152
- airflow/providers/cncf/kubernetes/utils/xcom_sidecar.py +25 -16
- airflow/providers/cncf/kubernetes/version_compat.py +38 -0
- apache_airflow_providers_cncf_kubernetes-10.10.0rc1.dist-info/METADATA +125 -0
- apache_airflow_providers_cncf_kubernetes-10.10.0rc1.dist-info/RECORD +62 -0
- {apache_airflow_providers_cncf_kubernetes-3.1.0.dist-info → apache_airflow_providers_cncf_kubernetes-10.10.0rc1.dist-info}/WHEEL +1 -2
- apache_airflow_providers_cncf_kubernetes-10.10.0rc1.dist-info/entry_points.txt +3 -0
- apache_airflow_providers_cncf_kubernetes-10.10.0rc1.dist-info/licenses/NOTICE +5 -0
- airflow/providers/cncf/kubernetes/backcompat/pod.py +0 -119
- airflow/providers/cncf/kubernetes/backcompat/pod_runtime_info_env.py +0 -56
- airflow/providers/cncf/kubernetes/backcompat/volume.py +0 -62
- airflow/providers/cncf/kubernetes/backcompat/volume_mount.py +0 -58
- airflow/providers/cncf/kubernetes/example_dags/example_kubernetes.py +0 -163
- airflow/providers/cncf/kubernetes/example_dags/example_spark_kubernetes.py +0 -66
- airflow/providers/cncf/kubernetes/example_dags/example_spark_kubernetes_spark_pi.yaml +0 -57
- airflow/providers/cncf/kubernetes/operators/kubernetes_pod.py +0 -622
- apache_airflow_providers_cncf_kubernetes-3.1.0.dist-info/METADATA +0 -452
- apache_airflow_providers_cncf_kubernetes-3.1.0.dist-info/NOTICE +0 -6
- apache_airflow_providers_cncf_kubernetes-3.1.0.dist-info/RECORD +0 -29
- apache_airflow_providers_cncf_kubernetes-3.1.0.dist-info/entry_points.txt +0 -3
- apache_airflow_providers_cncf_kubernetes-3.1.0.dist-info/top_level.txt +0 -1
- /airflow/providers/cncf/kubernetes/{example_dags → decorators}/__init__.py +0 -0
- {apache_airflow_providers_cncf_kubernetes-3.1.0.dist-info → apache_airflow_providers_cncf_kubernetes-10.10.0rc1.dist-info/licenses}/LICENSE +0 -0
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
#
|
|
2
|
-
# Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
-
# or more contributor license agreements. See the NOTICE file
|
|
4
|
-
# distributed with this work for additional information
|
|
5
|
-
# regarding copyright ownership. The ASF licenses this file
|
|
6
|
-
# to you under the Apache License, Version 2.0 (the
|
|
7
|
-
# "License"); you may not use this file except in compliance
|
|
8
|
-
# with the License. You may obtain a copy of the License at
|
|
9
|
-
#
|
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
-
#
|
|
12
|
-
# Unless required by applicable law or agreed to in writing,
|
|
13
|
-
# software distributed under the License is distributed on an
|
|
14
|
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
|
-
# KIND, either express or implied. See the License for the
|
|
16
|
-
# specific language governing permissions and limitations
|
|
17
|
-
# under the License.
|
|
18
|
-
"""
|
|
19
|
-
This is an example dag for using the KubernetesPodOperator.
|
|
20
|
-
"""
|
|
21
|
-
|
|
22
|
-
from datetime import datetime
|
|
23
|
-
|
|
24
|
-
from kubernetes.client import models as k8s
|
|
25
|
-
|
|
26
|
-
from airflow import DAG
|
|
27
|
-
from airflow.kubernetes.secret import Secret
|
|
28
|
-
from airflow.operators.bash import BashOperator
|
|
29
|
-
from airflow.providers.cncf.kubernetes.operators.kubernetes_pod import KubernetesPodOperator
|
|
30
|
-
|
|
31
|
-
# [START howto_operator_k8s_cluster_resources]
|
|
32
|
-
secret_file = Secret('volume', '/etc/sql_conn', 'airflow-secrets', 'sql_alchemy_conn')
|
|
33
|
-
secret_env = Secret('env', 'SQL_CONN', 'airflow-secrets', 'sql_alchemy_conn')
|
|
34
|
-
secret_all_keys = Secret('env', None, 'airflow-secrets-2')
|
|
35
|
-
volume_mount = k8s.V1VolumeMount(
|
|
36
|
-
name='test-volume', mount_path='/root/mount_file', sub_path=None, read_only=True
|
|
37
|
-
)
|
|
38
|
-
|
|
39
|
-
configmaps = [
|
|
40
|
-
k8s.V1EnvFromSource(config_map_ref=k8s.V1ConfigMapEnvSource(name='test-configmap-1')),
|
|
41
|
-
k8s.V1EnvFromSource(config_map_ref=k8s.V1ConfigMapEnvSource(name='test-configmap-2')),
|
|
42
|
-
]
|
|
43
|
-
|
|
44
|
-
volume = k8s.V1Volume(
|
|
45
|
-
name='test-volume',
|
|
46
|
-
persistent_volume_claim=k8s.V1PersistentVolumeClaimVolumeSource(claim_name='test-volume'),
|
|
47
|
-
)
|
|
48
|
-
|
|
49
|
-
port = k8s.V1ContainerPort(name='http', container_port=80)
|
|
50
|
-
|
|
51
|
-
init_container_volume_mounts = [
|
|
52
|
-
k8s.V1VolumeMount(mount_path='/etc/foo', name='test-volume', sub_path=None, read_only=True)
|
|
53
|
-
]
|
|
54
|
-
|
|
55
|
-
init_environments = [k8s.V1EnvVar(name='key1', value='value1'), k8s.V1EnvVar(name='key2', value='value2')]
|
|
56
|
-
|
|
57
|
-
init_container = k8s.V1Container(
|
|
58
|
-
name="init-container",
|
|
59
|
-
image="ubuntu:16.04",
|
|
60
|
-
env=init_environments,
|
|
61
|
-
volume_mounts=init_container_volume_mounts,
|
|
62
|
-
command=["bash", "-cx"],
|
|
63
|
-
args=["echo 10"],
|
|
64
|
-
)
|
|
65
|
-
|
|
66
|
-
affinity = k8s.V1Affinity(
|
|
67
|
-
node_affinity=k8s.V1NodeAffinity(
|
|
68
|
-
preferred_during_scheduling_ignored_during_execution=[
|
|
69
|
-
k8s.V1PreferredSchedulingTerm(
|
|
70
|
-
weight=1,
|
|
71
|
-
preference=k8s.V1NodeSelectorTerm(
|
|
72
|
-
match_expressions=[
|
|
73
|
-
k8s.V1NodeSelectorRequirement(key="disktype", operator="In", values=["ssd"])
|
|
74
|
-
]
|
|
75
|
-
),
|
|
76
|
-
)
|
|
77
|
-
]
|
|
78
|
-
),
|
|
79
|
-
pod_affinity=k8s.V1PodAffinity(
|
|
80
|
-
required_during_scheduling_ignored_during_execution=[
|
|
81
|
-
k8s.V1WeightedPodAffinityTerm(
|
|
82
|
-
weight=1,
|
|
83
|
-
pod_affinity_term=k8s.V1PodAffinityTerm(
|
|
84
|
-
label_selector=k8s.V1LabelSelector(
|
|
85
|
-
match_expressions=[
|
|
86
|
-
k8s.V1LabelSelectorRequirement(key="security", operator="In", values="S1")
|
|
87
|
-
]
|
|
88
|
-
),
|
|
89
|
-
topology_key="failure-domain.beta.kubernetes.io/zone",
|
|
90
|
-
),
|
|
91
|
-
)
|
|
92
|
-
]
|
|
93
|
-
),
|
|
94
|
-
)
|
|
95
|
-
|
|
96
|
-
tolerations = [k8s.V1Toleration(key="key", operator="Equal", value="value")]
|
|
97
|
-
|
|
98
|
-
# [END howto_operator_k8s_cluster_resources]
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
with DAG(
|
|
102
|
-
dag_id='example_kubernetes_operator',
|
|
103
|
-
schedule_interval=None,
|
|
104
|
-
start_date=datetime(2021, 1, 1),
|
|
105
|
-
tags=['example'],
|
|
106
|
-
) as dag:
|
|
107
|
-
k = KubernetesPodOperator(
|
|
108
|
-
namespace='default',
|
|
109
|
-
image="ubuntu:16.04",
|
|
110
|
-
cmds=["bash", "-cx"],
|
|
111
|
-
arguments=["echo", "10"],
|
|
112
|
-
labels={"foo": "bar"},
|
|
113
|
-
secrets=[secret_file, secret_env, secret_all_keys],
|
|
114
|
-
ports=[port],
|
|
115
|
-
volumes=[volume],
|
|
116
|
-
volume_mounts=[volume_mount],
|
|
117
|
-
env_from=configmaps,
|
|
118
|
-
name="airflow-test-pod",
|
|
119
|
-
task_id="task",
|
|
120
|
-
affinity=affinity,
|
|
121
|
-
is_delete_operator_pod=True,
|
|
122
|
-
hostnetwork=False,
|
|
123
|
-
tolerations=tolerations,
|
|
124
|
-
init_containers=[init_container],
|
|
125
|
-
priority_class_name="medium",
|
|
126
|
-
)
|
|
127
|
-
|
|
128
|
-
# [START howto_operator_k8s_private_image]
|
|
129
|
-
quay_k8s = KubernetesPodOperator(
|
|
130
|
-
namespace='default',
|
|
131
|
-
image='quay.io/apache/bash',
|
|
132
|
-
image_pull_secrets=[k8s.V1LocalObjectReference('testquay')],
|
|
133
|
-
cmds=["bash", "-cx"],
|
|
134
|
-
arguments=["echo", "10", "echo pwd"],
|
|
135
|
-
labels={"foo": "bar"},
|
|
136
|
-
name="airflow-private-image-pod",
|
|
137
|
-
is_delete_operator_pod=True,
|
|
138
|
-
in_cluster=True,
|
|
139
|
-
task_id="task-two",
|
|
140
|
-
get_logs=True,
|
|
141
|
-
)
|
|
142
|
-
# [END howto_operator_k8s_private_image]
|
|
143
|
-
|
|
144
|
-
# [START howto_operator_k8s_write_xcom]
|
|
145
|
-
write_xcom = KubernetesPodOperator(
|
|
146
|
-
namespace='default',
|
|
147
|
-
image='alpine',
|
|
148
|
-
cmds=["sh", "-c", "mkdir -p /airflow/xcom/;echo '[1,2,3,4]' > /airflow/xcom/return.json"],
|
|
149
|
-
name="write-xcom",
|
|
150
|
-
do_xcom_push=True,
|
|
151
|
-
is_delete_operator_pod=True,
|
|
152
|
-
in_cluster=True,
|
|
153
|
-
task_id="write-xcom",
|
|
154
|
-
get_logs=True,
|
|
155
|
-
)
|
|
156
|
-
|
|
157
|
-
pod_task_xcom_result = BashOperator(
|
|
158
|
-
bash_command="echo \"{{ task_instance.xcom_pull('write-xcom')[0] }}\"",
|
|
159
|
-
task_id="pod_task_xcom_result",
|
|
160
|
-
)
|
|
161
|
-
# [END howto_operator_k8s_write_xcom]
|
|
162
|
-
|
|
163
|
-
write_xcom >> pod_task_xcom_result
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
#
|
|
2
|
-
# Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
-
# or more contributor license agreements. See the NOTICE file
|
|
4
|
-
# distributed with this work for additional information
|
|
5
|
-
# regarding copyright ownership. The ASF licenses this file
|
|
6
|
-
# to you under the Apache License, Version 2.0 (the
|
|
7
|
-
# "License"); you may not use this file except in compliance
|
|
8
|
-
# with the License. You may obtain a copy of the License at
|
|
9
|
-
#
|
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
-
#
|
|
12
|
-
# Unless required by applicable law or agreed to in writing,
|
|
13
|
-
# software distributed under the License is distributed on an
|
|
14
|
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
|
-
# KIND, either express or implied. See the License for the
|
|
16
|
-
# specific language governing permissions and limitations
|
|
17
|
-
# under the License.
|
|
18
|
-
"""
|
|
19
|
-
This is an example DAG which uses SparkKubernetesOperator and SparkKubernetesSensor.
|
|
20
|
-
In this example, we create two tasks which execute sequentially.
|
|
21
|
-
The first task is to submit sparkApplication on Kubernetes cluster(the example uses spark-pi application).
|
|
22
|
-
and the second task is to check the final state of the sparkApplication that submitted in the first state.
|
|
23
|
-
|
|
24
|
-
Spark-on-k8s operator is required to be already installed on Kubernetes
|
|
25
|
-
https://github.com/GoogleCloudPlatform/spark-on-k8s-operator
|
|
26
|
-
"""
|
|
27
|
-
|
|
28
|
-
from datetime import datetime, timedelta
|
|
29
|
-
|
|
30
|
-
# [START import_module]
|
|
31
|
-
# The DAG object; we'll need this to instantiate a DAG
|
|
32
|
-
from airflow import DAG
|
|
33
|
-
|
|
34
|
-
# Operators; we need this to operate!
|
|
35
|
-
from airflow.providers.cncf.kubernetes.operators.spark_kubernetes import SparkKubernetesOperator
|
|
36
|
-
from airflow.providers.cncf.kubernetes.sensors.spark_kubernetes import SparkKubernetesSensor
|
|
37
|
-
|
|
38
|
-
# [END import_module]
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
# [START instantiate_dag]
|
|
42
|
-
|
|
43
|
-
dag = DAG(
|
|
44
|
-
'spark_pi',
|
|
45
|
-
default_args={'max_active_runs': 1},
|
|
46
|
-
description='submit spark-pi as sparkApplication on kubernetes',
|
|
47
|
-
schedule_interval=timedelta(days=1),
|
|
48
|
-
start_date=datetime(2021, 1, 1),
|
|
49
|
-
catchup=False,
|
|
50
|
-
)
|
|
51
|
-
|
|
52
|
-
t1 = SparkKubernetesOperator(
|
|
53
|
-
task_id='spark_pi_submit',
|
|
54
|
-
namespace="default",
|
|
55
|
-
application_file="example_spark_kubernetes_spark_pi.yaml",
|
|
56
|
-
do_xcom_push=True,
|
|
57
|
-
dag=dag,
|
|
58
|
-
)
|
|
59
|
-
|
|
60
|
-
t2 = SparkKubernetesSensor(
|
|
61
|
-
task_id='spark_pi_monitor',
|
|
62
|
-
namespace="default",
|
|
63
|
-
application_name="{{ task_instance.xcom_pull(task_ids='spark_pi_submit')['metadata']['name'] }}",
|
|
64
|
-
dag=dag,
|
|
65
|
-
)
|
|
66
|
-
t1 >> t2
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
#
|
|
2
|
-
# Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
-
# or more contributor license agreements. See the NOTICE file
|
|
4
|
-
# distributed with this work for additional information
|
|
5
|
-
# regarding copyright ownership. The ASF licenses this file
|
|
6
|
-
# to you under the Apache License, Version 2.0 (the
|
|
7
|
-
# "License"); you may not use this file except in compliance
|
|
8
|
-
# with the License. You may obtain a copy of the License at
|
|
9
|
-
#
|
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
-
#
|
|
12
|
-
# Unless required by applicable law or agreed to in writing,
|
|
13
|
-
# software distributed under the License is distributed on an
|
|
14
|
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
|
-
# KIND, either express or implied. See the License for the
|
|
16
|
-
# specific language governing permissions and limitations
|
|
17
|
-
# under the License.
|
|
18
|
-
---
|
|
19
|
-
apiVersion: "sparkoperator.k8s.io/v1beta2"
|
|
20
|
-
kind: SparkApplication
|
|
21
|
-
metadata:
|
|
22
|
-
name: "spark-pi-{{ ds }}-{{ task_instance.try_number }}"
|
|
23
|
-
namespace: default
|
|
24
|
-
spec:
|
|
25
|
-
type: Scala
|
|
26
|
-
mode: cluster
|
|
27
|
-
image: "gcr.io/spark-operator/spark:v2.4.4"
|
|
28
|
-
imagePullPolicy: Always
|
|
29
|
-
mainClass: org.apache.spark.examples.SparkPi
|
|
30
|
-
mainApplicationFile: "local:///opt/spark/examples/jars/spark-examples_2.11-2.4.4.jar"
|
|
31
|
-
sparkVersion: "2.4.4"
|
|
32
|
-
restartPolicy:
|
|
33
|
-
type: Never
|
|
34
|
-
volumes:
|
|
35
|
-
- name: "test-volume"
|
|
36
|
-
hostPath:
|
|
37
|
-
path: "/tmp"
|
|
38
|
-
type: Directory
|
|
39
|
-
driver:
|
|
40
|
-
cores: 1
|
|
41
|
-
coreLimit: "1200m"
|
|
42
|
-
memory: "512m"
|
|
43
|
-
labels:
|
|
44
|
-
version: 2.4.4
|
|
45
|
-
serviceAccount: spark
|
|
46
|
-
volumeMounts:
|
|
47
|
-
- name: "test-volume"
|
|
48
|
-
mountPath: "/tmp"
|
|
49
|
-
executor:
|
|
50
|
-
cores: 1
|
|
51
|
-
instances: 1
|
|
52
|
-
memory: "512m"
|
|
53
|
-
labels:
|
|
54
|
-
version: 2.4.4
|
|
55
|
-
volumeMounts:
|
|
56
|
-
- name: "test-volume"
|
|
57
|
-
mountPath: "/tmp"
|