Exemplo n.º 1
0
 def get_resource(
     self,
     compiled_operation: V1CompiledOperation,
     artifacts_store: V1ConnectionType,
     connection_by_names: Dict[str, V1ConnectionType],
     secrets: Optional[Iterable[V1K8sResourceType]],
     config_maps: Optional[Iterable[V1K8sResourceType]],
     default_sa: str = None,
     default_auth: bool = False,
 ) -> Dict:
     job = compiled_operation.run  # type: V1Job
     plugins = compiled_operation.plugins or V1Plugins()
     contexts = PluginsContextsSpec.from_config(plugins,
                                                default_auth=default_auth)
     replica_spec = self.get_replica_resource(
         plugins=plugins,
         contexts=contexts,
         environment=job.environment,
         volumes=job.volumes or [],
         init=job.init or [],
         sidecars=job.sidecars or [],
         container=job.container,
         artifacts_store=artifacts_store,
         connections=job.connections or [],
         connection_by_names=connection_by_names,
         secrets=secrets,
         config_maps=config_maps,
         default_sa=default_sa,
     )
     return get_job_custom_resource(
         namespace=self.namespace,
         main_container=replica_spec.main_container,
         sidecar_containers=replica_spec.sidecar_containers,
         init_containers=replica_spec.init_containers,
         resource_name=self.resource_name,
         volumes=replica_spec.volumes,
         environment=replica_spec.environment,
         termination=compiled_operation.termination,
         collect_logs=contexts.collect_logs,
         sync_statuses=contexts.sync_statuses,
         notifications=plugins.notifications,
         labels=replica_spec.labels,
         annotations=replica_spec.annotations,
     )
Exemplo n.º 2
0
    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