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=V1Statuses.DONE) ] launcher, launcher_replica_template = self.get_replica(environment) worker, worker_replica_template = self.get_replica(environment) template_spec = { "cleanPodPolicy": "Running", "slotsPerWorker": 12, "replicaSpecs": { "Launcher": launcher_replica_template, "Worker": worker_replica_template, }, } custom_object = { "mpiJobSpec": template_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"}, annotations={"foo": "bar"}, custom_object=custom_object, ) crd = get_mpi_job_custom_resource( namespace="default", resource_name="foo", launcher=launcher, worker=worker, slots_per_worker=12, clean_pod_policy="Running", termination=termination, collect_logs=True, sync_statuses=True, notifications=notifications, labels=environment.labels, annotations={"foo": "bar"}, ) assert crd == expected_crd
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
def test_termination_config(self): config_dict = {} config = V1Termination.from_dict(config_dict) assert_equal_dict(config_dict, config.to_dict()) # Add max_retries config_dict["maxRetries"] = 4 config = V1Termination.from_dict(config_dict) assert_equal_dict(config_dict, config.to_dict()) # Add timeout config_dict["timeout"] = 4 config = V1Termination.from_dict(config_dict) assert_equal_dict(config_dict, config.to_dict()) # Add ttl config_dict["ttl"] = 40 config = V1Termination.from_dict(config_dict) assert_equal_dict(config_dict, config.to_dict())
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
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