Source code for tests.system.providers.cncf.kubernetes.example_kubernetes_job
## 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."""This is an example dag for using the KubernetesJobOperator."""from__future__importannotationsimportosfromdatetimeimportdatetimefromairflowimportDAGfromairflow.providers.cncf.kubernetes.operators.jobimport(KubernetesDeleteJobOperator,KubernetesJobOperator,KubernetesPatchJobOperator,)
# [END howto_operator_k8s_job]# [START howto_operator_update_job]update_job=KubernetesPatchJobOperator(task_id="update-job-task",namespace="default",name=k8s_job.output["job_name"],body={"spec":{"suspend":False}},)# [END howto_operator_update_job]# [START howto_operator_k8s_job_deferrable]k8s_job_def=KubernetesJobOperator(task_id="job-task-def",namespace="default",image="perl:5.34.0",cmds=["perl","-Mbignum=bpi","-wle","print bpi(2000)"],name=JOB_NAME+"-def",wait_until_job_complete=True,deferrable=True,)# [END howto_operator_k8s_job_deferrable]# [START howto_operator_delete_k8s_job]delete_job_task=KubernetesDeleteJobOperator(task_id="delete_job_task",name=k8s_job.output["job_name"],namespace=JOB_NAMESPACE,wait_for_completion=True,delete_on_status="Complete",poll_interval=1.0,)# [END howto_operator_delete_k8s_job]delete_job_task_def=KubernetesDeleteJobOperator(task_id="delete_job_task_def",name=k8s_job_def.output["job_name"],namespace=JOB_NAMESPACE,)k8s_job>>update_job>>delete_job_taskk8s_job_def>>delete_job_task_deffromtests.system.utils.watcherimportwatcher# This test needs watcher in order to properly mark success/failure# when "tearDown" task with trigger rule is part of the DAGlist(dag.tasks)>>watcher()fromtests.system.utilsimportget_test_run# noqa: E402# Needed to run the example DAG with pytest (see: tests/system/README.md#run_via_pytest)