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_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
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