You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by di...@apache.org on 2020/09/04 02:38:22 UTC
[airflow] branch v1-10-test updated: Add generate_yaml command to
easily test KubernetesExecutor before deploying pods (#10677)
This is an automated email from the ASF dual-hosted git repository.
dimberman pushed a commit to branch v1-10-test
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/v1-10-test by this push:
new c01c6b7 Add generate_yaml command to easily test KubernetesExecutor before deploying pods (#10677)
c01c6b7 is described below
commit c01c6b79bf4fbe512ed3e969a68a28ab75c66355
Author: Daniel Imberman <da...@gmail.com>
AuthorDate: Thu Sep 3 19:37:11 2020 -0700
Add generate_yaml command to easily test KubernetesExecutor before deploying pods (#10677)
---
airflow/bin/cli.py | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 51 insertions(+)
diff --git a/airflow/bin/cli.py b/airflow/bin/cli.py
index c621a3a..302ab55 100644
--- a/airflow/bin/cli.py
+++ b/airflow/bin/cli.py
@@ -31,6 +31,7 @@ import subprocess
import textwrap
import random
import string
+import yaml
from collections import OrderedDict
from importlib import import_module
@@ -1249,6 +1250,41 @@ def _serve_logs(env, skip_serve_logs=False):
@cli_utils.action_logging
+def kubernetes_generate_dag_yaml(args):
+ from airflow.executors.kubernetes_executor import AirflowKubernetesScheduler, KubeConfig
+ from airflow.kubernetes.pod_generator import PodGenerator
+ from airflow.kubernetes.worker_configuration import WorkerConfiguration
+ from kubernetes.client.api_client import ApiClient
+ dag = get_dag(args)
+ yaml_output_path = args.output_path
+ kube_config = KubeConfig()
+ for task in dag.tasks:
+ ti = TaskInstance(task, args.execution_date)
+ pod = PodGenerator.construct_pod(
+ dag_id=args.dag_id,
+ task_id=ti.task_id,
+ pod_id=AirflowKubernetesScheduler._create_pod_id( # pylint: disable=W0212
+ args.dag_id, ti.task_id),
+ try_number=ti.try_number,
+ date=ti.execution_date,
+ command=ti.command_as_list(),
+ kube_executor_config=PodGenerator.from_obj(ti.executor_config),
+ worker_uuid="worker-config",
+ namespace=kube_config.executor_namespace,
+ worker_config=WorkerConfiguration(kube_config=kube_config).as_pod()
+ )
+ api_client = ApiClient()
+ date_string = AirflowKubernetesScheduler._datetime_to_label_safe_datestring( # pylint: disable=W0212
+ args.execution_date)
+ yaml_file_name = "{}_{}_{}.yml".format(args.dag_id, ti.task_id, date_string)
+ os.makedirs(os.path.dirname(yaml_output_path + "/airflow_yaml_output/"), exist_ok=True)
+ with open(yaml_output_path + "/airflow_yaml_output/" + yaml_file_name, "w") as output:
+ sanitized_pod = api_client.sanitize_for_serialization(pod)
+ output.write(yaml.dump(sanitized_pod))
+ print("YAML output can be found at {}/airflow_yaml_output/".format(yaml_output_path))
+
+
+@cli_utils.action_logging
def worker(args):
env = os.environ.copy()
env['AIRFLOW_HOME'] = settings.AIRFLOW_HOME
@@ -2172,6 +2208,11 @@ class CLIFactory(object):
'execution_date': Arg(
("execution_date",), help="The execution date of the DAG",
type=parsedate),
+ 'output_path': Arg(
+ ('-o', '--output-path'),
+ help="output path for yaml file",
+ default=os.getcwd()
+ ),
'task_regex': Arg(
("-t", "--task_regex"),
"The regex to filter specific task_ids to backfill (optional)"),
@@ -2695,6 +2736,16 @@ class CLIFactory(object):
'help': "List the tasks within a DAG",
'args': ('dag_id', 'tree', 'subdir'),
}, {
+ 'func': kubernetes_generate_dag_yaml,
+ 'help': "List dag runs given a DAG id. If state option is given, it will only"
+ "search for all the dagruns with the given state. "
+ "If no_backfill option is given, it will filter out"
+ "all backfill dagruns for given dag id.",
+ 'args': (
+ 'dag_id', 'output_path', 'subdir', 'execution_date'
+ )
+
+ }, {
'func': clear,
'help': "Clear a set of task instance, as if they never ran",
'args': (