mik-laj commented on a change in pull request #10393:
URL: https://github.com/apache/airflow/pull/10393#discussion_r483310271
##########
File path: tests/kubernetes/test_pod_generator.py
##########
@@ -241,238 +213,224 @@ def test_gen_pod_extract_xcom(self, mock_uuid):
],
'resources': {'requests': {'cpu': '1m'}},
}
- self.expected['spec']['containers'].append(container_two)
- self.expected['spec']['containers'][0]['volumeMounts'].insert(0, {
- 'name': 'xcom',
- 'mountPath': '/airflow/xcom'
- })
- self.expected['spec']['volumes'].insert(0, {
- 'name': 'xcom', 'emptyDir': {}
- })
- result_dict['spec']['containers'][0]['env'].sort(key=lambda x:
x['name'])
- self.assertEqual(result_dict, self.expected)
+ self.expected.spec.containers.append(container_two)
+ base_container: k8s.V1Container = self.expected.spec.containers[0]
+ base_container.volume_mounts = base_container.volume_mounts or []
+ base_container.volume_mounts.append(k8s.V1VolumeMount(
+ name="xcom",
+ mount_path="/airflow/xcom"
+ ))
+ self.expected.spec.containers[0] = base_container
+ self.expected.spec.volumes = self.expected.spec.volumes or []
+ self.expected.spec.volumes.append(
+ k8s.V1Volume(
+ name='xcom',
+ empty_dir={},
+ )
+ )
+ result_dict = self.k8s_client.sanitize_for_serialization(result)
+ expected_dict =
self.k8s_client.sanitize_for_serialization(self.expected)
+
+ self.assertEqual(result_dict, expected_dict)
def test_from_obj(self):
- result = PodGenerator.from_obj({
- "KubernetesExecutor": {
- "annotations": {"test": "annotation"},
- "volumes": [
- {
- "name": "example-kubernetes-test-volume",
- "hostPath": {"path": "/tmp/"},
- },
- ],
- "volume_mounts": [
- {
- "mountPath": "/foo/",
- "name": "example-kubernetes-test-volume",
- },
- ],
+ result = PodGenerator.from_obj(
+ {
+ "KubernetesExecutor": k8s.V1Pod(
+ api_version="v1",
+ kind="Pod",
+ metadata=k8s.V1ObjectMeta(
+ name="foo",
+ annotations={"test": "annotation"}
+ ),
+ spec=k8s.V1PodSpec(
+ containers=[
+ k8s.V1Container(
+ name="base",
+ volume_mounts=[
+ k8s.V1VolumeMount(
+ mount_path="/foo/",
+ name="example-kubernetes-test-volume"
+ )
+ ]
+ )
+ ],
+ volumes=[
+ k8s.V1Volume(
+ name="example-kubernetes-test-volume",
+ host_path=k8s.V1HostPathVolumeSource(
+ path="/tmp/"
+ )
+ )
+ ]
+ )
+ )
}
- })
+ )
result = self.k8s_client.sanitize_for_serialization(result)
self.assertEqual({
'apiVersion': 'v1',
'kind': 'Pod',
'metadata': {
+ 'name': 'foo',
'annotations': {'test': 'annotation'},
},
'spec': {
'containers': [{
- 'args': [],
- 'command': [],
- 'env': [],
- 'envFrom': [],
'name': 'base',
- 'ports': [],
'volumeMounts': [{
'mountPath': '/foo/',
'name': 'example-kubernetes-test-volume'
}],
}],
- 'hostNetwork': False,
- 'imagePullSecrets': [],
'volumes': [{
'hostPath': {'path': '/tmp/'},
'name': 'example-kubernetes-test-volume'
}],
}
}, result)
+ # TODO: Should we save this feature?
+ # result = PodGenerator.from_obj({
+ # "KubernetesExecutor": {
+ # "annotations": {"test": "annotation"},
+ # "volumes": [
+ # {
+ # "name": "example-kubernetes-test-volume",
+ # "hostPath": {"path": "/tmp/"},
+ # },
+ # ],
+ # "volume_mounts": [
+ # {
+ # "mountPath": "/foo/",
+ # "name": "example-kubernetes-test-volume",
+ # },
+ # ],
+ # }
+ # })
+ # result = self.k8s_client.sanitize_for_serialization(result)
+ #
+ # self.assertEqual({
+ # 'apiVersion': 'v1',
+ # 'kind': 'Pod',
+ # 'metadata': {
+ # 'annotations': {'test': 'annotation'},
+ # },
+ # 'spec': {
+ # 'containers': [{
+ # 'args': [],
+ # 'command': [],
+ # 'env': [],
+ # 'envFrom': [],
+ # 'name': 'base',
+ # 'ports': [],
+ # 'volumeMounts': [{
+ # 'mountPath': '/foo/',
+ # 'name': 'example-kubernetes-test-volume'
+ # }],
+ # }],
+ # 'hostNetwork': False,
+ # 'imagePullSecrets': [],
+ # 'volumes': [{
+ # 'hostPath': {'path': '/tmp/'},
+ # 'name': 'example-kubernetes-test-volume'
+ # }],
+ # }
+ # }, result)
@mock.patch('uuid.uuid4')
def test_reconcile_pods_empty_mutator_pod(self, mock_uuid):
- mock_uuid.return_value = self.static_uuid
- base_pod = PodGenerator(
- image='image1',
- name='name1',
- envs={'key1': 'val1'},
- cmds=['/bin/command1.sh', 'arg1'],
- ports=[k8s.V1ContainerPort(name='port', container_port=2118)],
- volumes=[{
- 'hostPath': {'path': '/tmp/'},
- 'name': 'example-kubernetes-test-volume1'
- }],
- volume_mounts=[{
- 'mountPath': '/foo/',
- 'name': 'example-kubernetes-test-volume1'
- }],
- ).gen_pod()
-
- mutator_pod = None
- name = 'name1-' + self.static_uuid.hex
-
- base_pod.metadata.name = name
-
- result = PodGenerator.reconcile_pods(base_pod, mutator_pod)
- self.assertEqual(base_pod, result)
-
- mutator_pod = k8s.V1Pod()
- result = PodGenerator.reconcile_pods(base_pod, mutator_pod)
- self.assertEqual(base_pod, result)
+ pass
+ # mock_uuid.return_value = self.static_uuid
Review comment:
?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]