我正在尝试在气流中使用kubernetes pod运算符,并且我想与我的气流工作人员上的kubernetes pod共享一个目录,有没有办法将气流工作人员的目录挂载到kubernetes pod? >
我尝试使用下面的代码,但似乎未成功装载该卷。
import datetime
import unittest
from unittest import TestCase
from airflow.operators.kubernetes_pod_operator import KubernetesPodOperator
from airflow.kubernetes.volume import Volume
from airflow.kubernetes.volume_mount import VolumeMount
class TestMailAlarm(TestCase):
def setUp(self):
self.namespace = "test-namespace"
self.image = "ubuntu:16.04"
self.name = "default"
self.cluster_context = "default"
self.dag_id = "test_dag"
self.task_id = "root_test_dag"
self.execution_date = datetime.datetime.now()
self.context = {"dag_id": self.dag_id,
"task_id": self.task_id,
"execution_date": self.execution_date}
self.cmds = ["sleep"]
self.arguments = ["100"]
self.volume_mount = VolumeMount('test',
mount_path='/tmp',
sub_path=None,
read_only=False)
volume_config = {
'persistentVolumeClaim':
{
'claimName': 'test'
}
}
self.volume = Volume(name='test', configs=volume_config)
self.operator = KubernetesPodOperator(
namespace=self.namespace, image=self.image, name=self.name,
cmds=self.cmds,
arguments=self.arguments,
startup_timeout_seconds=600,
is_delete_operator_pod=True,
# the operator could run successfully but the directory /tmp is not mounted to kubernetes operator
volume=[self.volume],
volume_mount=[self.volume_mount],
**self.context)
def test_execute(self):
self.operator.execute(self.context)
答案 0 :(得分:0)
文档中的示例似乎与您的代码非常相似,只是参数为复数 volume_mounts
和 volumes
。对于您的代码,它看起来像这样:
self.operator = KubernetesPodOperator(
namespace=self.namespace, image=self.image, name=self.name,
cmds=self.cmds,
arguments=self.arguments,
startup_timeout_seconds=600,
is_delete_operator_pod=True,
# the operator could run successfully but the directory /tmp is not mounted to kubernetes operator
volumes=[self.volume],
volume_mounts=[self.volume_mount],
**self.context)