Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Airflow kubernetes cli command for generating pod templates #8009

Closed
wants to merge 14 commits into from

Conversation

Javier162380
Copy link

@Javier162380 Javier162380 commented Mar 30, 2020

Adding a new command to the Airflow CLI.

airflow kubernetes pod-preview dag-id --sub-dir

The idea is to be able to generate pod templates from KubernetesPodOperator, so given a target dag it can generate all the k8s pod templates and printing in the CLI.

Example.

image
image

Just one consideration I am not connecting to any Kubernetes client so I am generating a default service account which means that you can not launch this pod in a Kubernetes cluster with a command like this.

kubectl apply -f file.yaml

Any feedback here is appreciated.

Also to be able to test this feature I need to add a new example-dag,

example_kubernetes_pod_operator.py

It is the same example given by Google in their composer tutorial (https://cloud.google.com/composer/docs/how-to/using/using-kubernetes-pod-operator), but adapting the imports to the new Kubernetes module import system.


Issue link: WILL BE INSERTED BY boring-cyborg

Make sure to mark the boxes below before creating PR: [x]


In the case of fundamental code change, Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backward incompatible changes please leave a note in UPDATING.md.
Read the Pull Request Guidelines for more information.

@boring-cyborg
Copy link

boring-cyborg bot commented Mar 30, 2020

Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/airflow/blob/master/CONTRIBUTING.rst)
Here are some useful points:

  • Pay attention to the quality of your code (flake8, pylint and type annotations). Our pre-commits will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example DAG that shows how users should use it.
  • Consider using Breeze environment for testing locally, it’s a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Be sure to read the Airflow Coding style.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: dev@airflow.apache.org
    Slack: https://apache-airflow-slack.herokuapp.com/

@Javier162380 Javier162380 changed the title Cli/kubernetes Airflow kubernetes cli command for generating pod templates Mar 30, 2020
@potiuk potiuk requested a review from mik-laj March 30, 2020 10:36
@potiuk
Copy link
Member

potiuk commented Mar 31, 2020

I think you will need to rebase it, we had some fixes in master!

@Javier162380
Copy link
Author

I think you will need to rebase it, we had some fixes in master!

ok this can explain why the travis test are failing?

@potiuk
Copy link
Member

potiuk commented Mar 31, 2020

Some yes. Possibly not all.

@Javier162380
Copy link
Author

Some yes. Possibly not all.

ok I already rebase it let's hope this time tests pass

@Javier162380
Copy link
Author

the integration tests are still failing any clue @potiuk ?

@mik-laj
Copy link
Member

mik-laj commented Apr 20, 2020

@Javier162380 There seems to be a serialization error not related to this patch. I have prepared a small change that bypasses this problem.

curl https://termbin.com/9q5d | git am
From a9c150fe70b57e013d4bb106638caaf92a2e214b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Kamil=20Bregu=C5=82a?= <kamil.bregula@polidea.com>
Date: Mon, 20 Apr 2020 18:55:28 +0200
Subject: Fix serialization

---
 airflow/example_dags/example_kubernetes_pod_operator.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/airflow/example_dags/example_kubernetes_pod_operator.py b/airflow/example_dags/example_kubernetes_pod_operator.py
index f3b18cc13..74a7c4cab 100644
--- a/airflow/example_dags/example_kubernetes_pod_operator.py
+++ b/airflow/example_dags/example_kubernetes_pod_operator.py
@@ -20,8 +20,9 @@ import datetime
 from airflow import models
 from airflow.kubernetes import secret
 from airflow.providers.cncf.kubernetes.operators.kubernetes_pod import KubernetesPodOperator
+from airflow.utils.dates import days_ago
 
-YESTERDAY = datetime.datetime.now() - datetime.timedelta(days=1)
+YESTERDAY = days_ago(1)
 secret_env = [secret.Secret(
     deploy_type='env',
     deploy_target='SQL_CONN',
-- 
2.20.1

@Javier162380
Copy link
Author

@Javier162380 There seems to be a serialization error not related to this patch. I have prepared a small change that bypasses this problem.

curl https://termbin.com/9q5d | git am
From a9c150fe70b57e013d4bb106638caaf92a2e214b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Kamil=20Bregu=C5=82a?= <kamil.bregula@polidea.com>
Date: Mon, 20 Apr 2020 18:55:28 +0200
Subject: Fix serialization

---
 airflow/example_dags/example_kubernetes_pod_operator.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/airflow/example_dags/example_kubernetes_pod_operator.py b/airflow/example_dags/example_kubernetes_pod_operator.py
index f3b18cc13..74a7c4cab 100644
--- a/airflow/example_dags/example_kubernetes_pod_operator.py
+++ b/airflow/example_dags/example_kubernetes_pod_operator.py
@@ -20,8 +20,9 @@ import datetime
 from airflow import models
 from airflow.kubernetes import secret
 from airflow.providers.cncf.kubernetes.operators.kubernetes_pod import KubernetesPodOperator
+from airflow.utils.dates import days_ago
 
-YESTERDAY = datetime.datetime.now() - datetime.timedelta(days=1)
+YESTERDAY = days_ago(1)
 secret_env = [secret.Secret(
     deploy_type='env',
     deploy_target='SQL_CONN',
-- 
2.20.1

thanka! I don't was going wrong, to be honest

@stale
Copy link

stale bot commented Jun 5, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale Stale PRs per the .github/workflows/stale.yml policy file label Jun 5, 2020
@stale stale bot closed this Jun 12, 2020
@kaxil kaxil reopened this Jul 20, 2020
@stale stale bot removed the stale Stale PRs per the .github/workflows/stale.yml policy file label Jul 20, 2020
@kaxil kaxil added the pinned Protect from Stalebot auto closing label Jul 20, 2020
@turbaszek
Copy link
Member

@dimberman is this something that may help us for migration to Airflow 2.0?

KUBERNETES_COMMANDS = (
ActionCommand(
name='pod-preview',
help='Generate a k8s template',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
help='Generate a k8s template',
help='Generate a k8s template for KubernetesPodOperator tasks',

pod_args['extract_xcom'] = kubernetes_tasks_args.get('do_xcom_push', None)

pod = pod_generator.PodGenerator(**(pod_args)).gen_pod()
pod = append_to_pod(pod,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dimberman
Copy link
Contributor

@Javier162380 do you want to finish this? If not I can pick this up :)

@Javier162380
Copy link
Author

@Javier162380 do you want to finish this? If not I can pick this up :)

I can help you with! Need to reclone the repo it is quite oldie this PR

@mik-laj mik-laj removed their request for review October 12, 2020 11:14
@kaxil kaxil added provider:cncf-kubernetes Kubernetes provider related issues and removed area:k8s labels Nov 18, 2020
@dimberman
Copy link
Contributor

Hi @Javier162380 are you interested in continuing with this task? Glad to help :).

@ashb
Copy link
Member

ashb commented Feb 8, 2021

@dimberman Didn't you add something like this already?

@mik-laj
Copy link
Member

mik-laj commented Jun 6, 2021

We already have airflow kubernetes airflow kubernetes generate-dag-yaml command. Closing...

@mik-laj mik-laj closed this Jun 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:CLI pinned Protect from Stalebot auto closing provider:cncf-kubernetes Kubernetes provider related issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants