本文整理汇总了Python中airflow.contrib.operators.kubernetes_pod_operator.KubernetesPodOperator类的典型用法代码示例。如果您正苦于以下问题:Python KubernetesPodOperator类的具体用法?Python KubernetesPodOperator怎么用?Python KubernetesPodOperator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了KubernetesPodOperator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_volume_mount
def test_volume_mount():
with mock.patch.object(PodLauncher, 'log') as mock_logger:
volume_mount = VolumeMount('test-volume',
mount_path='/root/mount_file',
sub_path=None,
read_only=True)
volume_config = {
'persistentVolumeClaim':
{
'claimName': 'test-volume'
}
}
volume = Volume(name='test-volume', configs=volume_config)
k = KubernetesPodOperator(
namespace='default',
image="ubuntu:16.04",
cmds=["bash", "-cx"],
arguments=["cat /root/mount_file/test.txt"],
labels={"foo": "bar"},
volume_mounts=[volume_mount],
volumes=[volume],
name="test",
task_id="task"
)
k.execute(None)
mock_logger.info.assert_any_call(b"retrieved from mount\n")
示例2: test_pod_affinity
def test_pod_affinity():
affinity = {
'nodeAffinity': {
'requiredDuringSchedulingIgnoredDuringExecution': {
'nodeSelectorTerms': [
{
'matchExpressions': [
{
'key': 'beta.kubernetes.io/os',
'operator': 'In',
'values': ['linux']
}
]
}
]
}
}
}
k = KubernetesPodOperator(
namespace='default',
image="ubuntu:16.04",
cmds=["bash", "-cx"],
arguments=["echo", "10"],
labels={"foo": "bar"},
name="test",
task_id="task",
affinity=affinity,
executor_config={'KubernetesExecutor': {'affinity': affinity}}
)
k.execute(None)
示例3: test_working_pod
def test_working_pod():
k = KubernetesPodOperator(
namespace='default',
image="ubuntu:16.04",
cmds=["bash", "-cx"],
arguments=["echo 10"],
labels={"foo": "bar"},
name="test",
task_id="task"
)
k.execute(None)
示例4: test_xcom_push
def test_xcom_push(self):
return_value = '{"foo": "bar"\n, "buzz": 2}'
k = KubernetesPodOperator(
namespace='default',
image="ubuntu:16.04",
cmds=["bash", "-cx"],
arguments=['echo \'{}\' > /airflow/xcom/return.json'.format(return_value)],
labels={"foo": "bar"},
name="test",
task_id="task",
do_xcom_push=True
)
self.assertEqual(k.execute(None), json.loads(return_value))
示例5: test_logging
def test_logging(self):
with mock.patch.object(PodLauncher, 'log') as mock_logger:
k = KubernetesPodOperator(namespace='default',
image="ubuntu:16.04",
cmds=["bash", "-cx"],
arguments=["echo", "10"],
labels={"foo": "bar"},
name="test",
task_id="task",
get_logs=True
)
k.execute(None)
mock_logger.info.assert_any_call("+ echo\n")
示例6: test_faulty_image
def test_faulty_image(self):
bad_image_name = "foobar"
k = KubernetesPodOperator(
namespace='default',
image=bad_image_name,
cmds=["bash", "-cx"],
arguments=["echo 10"],
labels={"foo": "bar"},
name="test",
task_id="task",
startup_timeout_seconds=5
)
with self.assertRaises(AirflowException):
k.execute(None)
示例7: test_faulty_service_account
def test_faulty_service_account(self):
bad_service_account_name = "foobar"
k = KubernetesPodOperator(
namespace='default',
image="ubuntu:16.04",
cmds=["bash", "-cx"],
arguments=["echo 10"],
labels={"foo": "bar"},
name="test",
task_id="task",
startup_timeout_seconds=5,
service_account_name=bad_service_account_name
)
with self.assertRaises(ApiException):
k.execute(None)
示例8: test_config_path_move
def test_config_path_move():
new_config_path = '/tmp/kube_config'
old_config_path = os.path.expanduser('~/.kube/config')
shutil.copy(old_config_path, new_config_path)
k = KubernetesPodOperator(
namespace='default',
image="ubuntu:16.04",
cmds=["bash", "-cx"],
arguments=["echo 10"],
labels={"foo": "bar"},
name="test",
task_id="task",
config_file=new_config_path
)
k.execute(None)
示例9: test_pod_failure
def test_pod_failure(self):
"""
Tests that the task fails when a pod reports a failure
"""
bad_internal_command = "foobar"
k = KubernetesPodOperator(
namespace='default',
image="ubuntu:16.04",
cmds=["bash", "-cx"],
arguments=[bad_internal_command + " 10"],
labels={"foo": "bar"},
name="test",
task_id="task"
)
with self.assertRaises(AirflowException):
k.execute(None)
示例10: test_pod_node_selectors
def test_pod_node_selectors():
node_selectors = {
'beta.kubernetes.io/os': 'linux'
}
k = KubernetesPodOperator(
namespace='default',
image="ubuntu:16.04",
cmds=["bash", "-cx"],
arguments=["echo", "10"],
labels={"foo": "bar"},
name="test",
task_id="task",
node_selectors=node_selectors,
executor_config={'KubernetesExecutor': {'node_selectors': node_selectors}}
)
k.execute(None)
示例11: test_pod_delete_even_on_launcher_error
def test_pod_delete_even_on_launcher_error(self, client_mock, delete_pod_mock, run_pod_mock):
k = KubernetesPodOperator(
namespace='default',
image="ubuntu:16.04",
cmds=["bash", "-cx"],
arguments=["echo 10"],
labels={"foo": "bar"},
name="test",
task_id="task",
in_cluster=False,
cluster_context='default',
is_delete_operator_pod=True
)
run_pod_mock.side_effect = AirflowException('fake failure')
with self.assertRaises(AirflowException):
k.execute(None)
assert delete_pod_mock.called
示例12: test_envs_from_secrets
def test_envs_from_secrets(self, client_mock, launcher_mock):
# GIVEN
from airflow.utils.state import State
secrets = [Secret('env', None, "secret_name")]
# WHEN
k = KubernetesPodOperator(
namespace='default',
image="ubuntu:16.04",
cmds=["bash", "-cx"],
arguments=["echo 10"],
secrets=secrets,
labels={"foo": "bar"},
name="test",
task_id="task",
)
# THEN
launcher_mock.return_value = (State.SUCCESS, None)
k.execute(None)
self.assertEqual(launcher_mock.call_args[0][0].secrets, secrets)
示例13: test_fs_group
def test_fs_group():
security_context = {
'securityContext': {
'fsGroup': 1000,
}
}
k = KubernetesPodOperator(
namespace='default',
image="ubuntu:16.04",
cmds=["bash", "-cx"],
arguments=["echo", "10"],
labels={"foo": "bar"},
name="test",
task_id="task",
security_context=security_context,
executor_config={'KubernetesExecutor': {'securityContext': security_context}}
)
k.execute(None)
示例14: test_image_pull_secrets_correctly_set
def test_image_pull_secrets_correctly_set(self, client_mock, launcher_mock):
from airflow.utils.state import State
fake_pull_secrets = "fakeSecret"
k = KubernetesPodOperator(
namespace='default',
image="ubuntu:16.04",
cmds=["bash", "-cx"],
arguments=["echo 10"],
labels={"foo": "bar"},
name="test",
task_id="task",
image_pull_secrets=fake_pull_secrets,
in_cluster=False,
cluster_context='default'
)
launcher_mock.return_value = (State.SUCCESS, None)
k.execute(None)
self.assertEqual(launcher_mock.call_args[0][0].image_pull_secrets,
fake_pull_secrets)
示例15: test_config_path
def test_config_path(self, client_mock, launcher_mock):
from airflow.utils.state import State
file_path = "/tmp/fake_file"
k = KubernetesPodOperator(
namespace='default',
image="ubuntu:16.04",
cmds=["bash", "-cx"],
arguments=["echo 10"],
labels={"foo": "bar"},
name="test",
task_id="task",
config_file=file_path,
in_cluster=False,
cluster_context='default'
)
launcher_mock.return_value = (State.SUCCESS, None)
k.execute(None)
client_mock.assert_called_with(in_cluster=False,
cluster_context='default',
config_file=file_path)