コード例 #1
0
    def test_get_job_custom_resource(self):
        termination = V1Termination(max_retries=5, ttl=10, timeout=10)
        environment = V1Environment(
            labels={"foo": "bar"},
            annotations={"foo": "bar"},
            node_selector={"foo": "bar"},
            node_name="foo",
            restart_policy="never",
        )
        notifications = [
            V1Notification(connections=["test"],
                           trigger=V1NotificationTrigger.DONE)
        ]
        chief, chief_replica_template = self.get_replica(environment)
        worker, worker_replica_template = self.get_replica(environment)
        template_spec = {
            "cleanPodPolicy": "Running",
            "Chief": chief_replica_template,
            "Worker": worker_replica_template,
        }
        custom_object = {
            "tfJobSpec": template_spec,
            "termination": {
                "backoffLimit": termination.max_retries,
                "activeDeadlineSeconds": termination.timeout,
                "ttlSecondsAfterFinished": termination.ttl,
            },
            "collectLogs": True,
            "syncStatuses": True,
            "notifications": [n.to_dict() for n in notifications],
        }

        expected_crd = get_custom_object(
            namespace="default",
            resource_name="foo",
            kind="Operation",
            api_version="core.polyaxon.com/v1",
            labels={"foo": "bar"},
            custom_object=custom_object,
        )

        crd = get_tf_job_custom_resource(
            namespace="default",
            resource_name="foo",
            chief=chief,
            worker=worker,
            ps=None,
            evaluator=None,
            clean_pod_policy="Running",
            termination=termination,
            collect_logs=True,
            sync_statuses=True,
            notifications=notifications,
            labels=environment.labels,
        )

        assert crd == expected_crd
コード例 #2
0
    def test_get_service_custom_resource(self):
        main_container = k8s_schemas.V1Container(name="main")
        sidecar_containers = [k8s_schemas.V1Container(name="sidecar")]
        init_containers = [k8s_schemas.V1Container(name="init")]
        termination = V1Termination(timeout=10)
        environment = V1Environment(
            labels={"foo": "bar"},
            annotations={"foo": "bar"},
            node_selector={"foo": "bar"},
            node_name="foo",
            restart_policy="never",
        )
        metadata, pod_spec = get_pod_spec(
            namespace="default",
            main_container=main_container,
            sidecar_containers=sidecar_containers,
            init_containers=init_containers,
            resource_name="foo",
            volumes=[],
            environment=environment,
            labels=environment.labels,
        )
        custom_object = {
            "serviceSpec": {
                "template": get_pod_template_spec(metadata=metadata, pod_spec=pod_spec),
            },
            "termination": {"activeDeadlineSeconds": termination.timeout},
            "collectLogs": True,
            "syncStatuses": True,
            "notifications": [],
        }
        expected_crd = get_custom_object(
            namespace="default",
            resource_name="foo",
            kind="Operation",
            api_version="core.polyaxon.com/v1",
            labels={"foo": "bar"},
            custom_object=custom_object,
        )

        crd = get_service_custom_resource(
            namespace="default",
            resource_name="foo",
            main_container=main_container,
            sidecar_containers=sidecar_containers,
            init_containers=init_containers,
            volumes=[],
            termination=termination,
            environment=environment,
            labels=environment.labels,
            collect_logs=True,
            sync_statuses=True,
            notifications=None,
            ports=[],
        )

        assert crd == expected_crd
コード例 #3
0
    def test_get_service_custom_resource_missing_keys(self):
        main_container = k8s_schemas.V1Container(name="main")
        metadata, pod_spec = get_pod_spec(
            namespace="default",
            main_container=main_container,
            sidecar_containers=None,
            init_containers=None,
            resource_name="foo",
            volumes=[],
            environment=None,
            labels=None,
            annotations=None,
        )
        notifications = [
            V1Notification(connections=["test"], trigger=V1Statuses.DONE)
        ]
        custom_object = {
            "template": get_pod_template_spec(metadata=metadata,
                                              pod_spec=pod_spec),
            "ports": [12, 121, 12],
        }
        expected_crd = get_custom_object(
            namespace="default",
            resource_name="foo",
            kind="Operation",
            api_version="core.polyaxon.com/v1",
            labels=None,
            annotations=None,
            custom_object={
                "serviceSpec": custom_object,
                "collectLogs": False,
                "syncStatuses": False,
                "notifications": [n.to_operator() for n in notifications],
            },
        )

        crd = get_service_custom_resource(
            namespace="default",
            resource_name="foo",
            main_container=main_container,
            sidecar_containers=None,
            init_containers=None,
            volumes=[],
            termination=None,
            collect_logs=None,
            sync_statuses=None,
            notifications=notifications,
            environment=None,
            labels=None,
            annotations=None,
            ports=[12, 121, 12],
        )

        assert crd == expected_crd
コード例 #4
0
def get_operation_custom_object(resource_name: str, namespace: str,
                                custom_object: Dict,
                                labels: Dict[str, str]) -> Dict:
    return get_custom_object(
        resource_name=resource_name,
        namespace=namespace,
        kind=KIND,
        api_version="{}/{}".format(GROUP, API_VERSION),
        labels=labels,
        custom_object=custom_object,
    )
コード例 #5
0
    def test_get_tf_job_custom_resource_with_no_workers(self):
        termination = V1Termination(max_retries=5, ttl=10, timeout=10)
        environment = V1Environment(
            labels={"foo": "bar"},
            annotations={"foo": "bar"},
            node_selector={"foo": "bar"},
            node_name="foo",
            restart_policy="never",
        )
        custom_object = {
            "tfJobSpec": {
                "cleanPodPolicy": "All",
                "replicaSpecs": {}
            },
            "termination": {
                "backoffLimit": termination.max_retries,
                "activeDeadlineSeconds": termination.timeout,
                "ttlSecondsAfterFinished": termination.ttl,
            },
            "collectLogs": False,
            "syncStatuses": False,
            "notifications": [],
        }
        expected_crd = get_custom_object(
            namespace="default",
            resource_name="foo",
            kind="Operation",
            api_version="core.polyaxon.com/v1",
            labels={"foo": "bar"},
            annotations={"foo": "long-foo-bar" * 300},
            custom_object=custom_object,
        )

        crd = get_tf_job_custom_resource(
            namespace="default",
            resource_name="foo",
            chief=None,
            worker=None,
            ps=None,
            evaluator=None,
            clean_pod_policy=None,
            termination=termination,
            collect_logs=False,
            sync_statuses=False,
            notifications=None,
            labels=environment.labels,
            annotations={"foo": "long-foo-bar" * 300},
        )

        assert crd == expected_crd
コード例 #6
0
ファイル: test_crd.py プロジェクト: zhaohb/polyaxon
 def test_get_custom_object(self):
     crd = get_custom_object(
         namespace="default",
         resource_name="foo",
         kind="job",
         api_version="v1",
         labels={"foo": "bar"},
         custom_object={"some_spec": {
             "foo": "bar"
         }},
     )
     assert crd["kind"] == "job"
     assert crd["apiVersion"] == "v1"
     assert crd["metadata"].name == "foo"
     assert crd["metadata"].labels == {"foo": "bar"}
     assert crd["metadata"].namespace == "default"
     assert crd["some_spec"] == {"foo": "bar"}
コード例 #7
0
ファイル: test_job_crd.py プロジェクト: zeyaddeeb/polyaxon
    def test_get_job_custom_resource(self):
        main_container = k8s_schemas.V1Container(name="main")
        sidecar_containers = [k8s_schemas.V1Container(name="sidecar")]
        init_containers = [k8s_schemas.V1Container(name="init")]
        termination = V1Termination(max_retries=5, ttl=10, timeout=10)
        environment = V1Environment(
            labels={"foo": "bar"},
            annotations={"foo": "bar"},
            node_selector={"foo": "bar"},
            node_name="foo",
            restart_policy="never",
        )
        notifications = [
            V1Notification(connections=["test"], trigger=V1NotificationTrigger.DONE)
        ]
        metadata, pod_spec = get_pod_spec(
            namespace="default",
            main_container=main_container,
            sidecar_containers=sidecar_containers,
            init_containers=init_containers,
            resource_name="foo",
            volumes=[],
            environment=environment,
            labels=environment.labels,
        )
        custom_object = {
            "batchJobSpec": {
                "template": get_pod_template_spec(metadata=metadata, pod_spec=pod_spec),
            },
            "termination": {
                "backoffLimit": termination.max_retries,
                "activeDeadlineSeconds": termination.timeout,
                "ttlSecondsAfterFinished": termination.ttl,
            },
            "collectLogs": True,
            "syncStatuses": True,
            "notifications": [n.to_operator() for n in notifications],
        }
        expected_crd = get_custom_object(
            namespace="default",
            resource_name="foo",
            kind="Operation",
            api_version="core.polyaxon.com/v1",
            labels={"foo": "bar"},
            custom_object=custom_object,
            annotations={"foo": "long-foo-bar" * 300},
        )

        crd = get_job_custom_resource(
            namespace="default",
            resource_name="foo",
            main_container=main_container,
            sidecar_containers=sidecar_containers,
            init_containers=init_containers,
            volumes=[],
            termination=termination,
            environment=environment,
            collect_logs=True,
            sync_statuses=True,
            notifications=notifications,
            labels=environment.labels,
            annotations={"foo": "long-foo-bar" * 300},
        )

        assert crd == expected_crd