<p>I am writing an Airflow DAG to pull data from an API and store it in a database I own. Following best practices outlined in <a href="https://medium.com/bluecore-engineering/were-all-using-airflow-wrong-and-how-to-fix-it-a56f14cb0753" rel="nofollow noreferrer">We're All Using Airflow Wrong</a>, I'm writing the DAG as a sequence of <code>KubernetesPodOperator</code>s that run pretty simple Python functions as the entry point to the Docker image. </p>

<p>The problem I'm trying to solve is that this DAG should only pull data for the <code>execution_date</code>. </p>

<p>If I was using a <code>PythonOperator</code> (<a href="http://airflow.apache.org/_api/airflow/operators/python_operator/index.html" rel="nofollow noreferrer">doc</a>), I could use the <code>provide_context</code> argument to make the execution date available to the function. But judging from <a href="http://airflow.apache.org/_api/airflow/contrib/operators/kubernetes_pod_operator/index.html" rel="nofollow noreferrer">the KubernetesPodOperator's documentation</a>, it seems that the Kubernetes operator has no argument that does what <code>provide_context</code> does.</p>

<p>My best guess is that you could use the <code>arguments</code> command to pass in a date range, and since it's templated, you can reference it like this:</p>

<pre class="lang-py prettyprint-override"><code>my_pod_operator = KubernetesPodOperator(
    # ... other args here
    arguments=['python', 'my_script.py', '{{ ds }}'],
    # arguments continue
)
</code></pre>

<p>And then you'd get the start date like you'd get any other argument provided to a Python file run as a script, by using <code>sys.argv</code>.</p>

<p>Is this the right way of doing it? </p>

<p>Thanks for the help.</p>

<p>Yes, that is the correct way of doing it.</p>

<p>Each Operator would have <code>template_fields</code>. All the parameters listed in <code>template_fields</code> can render Jinja2 templates and Airflow Macros.</p>

<p>For KubernetesPodOperator, if you check <a href="http://airflow.apache.org/1.10.3/_api/airflow/contrib/operators/kubernetes_pod_operator/index.html#airflow.contrib.operators.kubernetes_pod_operator.KubernetesPodOperator.template_fields" rel="noreferrer">docs</a>, you would find:</p>

<pre><code>template_fields = ['cmds', 'arguments', 'env_vars', 'config_file']
</code></pre>

<p>which means you can pass <code>'{{ ds }}'</code>to any of the four params listed above.</p>
