Pod spec to be used to create pods for tasks: master, worker, ps.

def get_task_pod_spec(self,
                          volume_mounts,
                          volumes,
                          resource_name,
                          persistence_outputs=None,
                          persistence_data=None,
                          outputs_refs_jobs=None,
                          outputs_refs_experiments=None,
                          env_vars=None,
                          command=None,
                          args=None,
                          init_command=None,
                          init_args=None,
                          init_env_vars=None,
                          resources=None,
                          ports=None,
                          secret_refs=None,
                          configmap_refs=None,
                          ephemeral_token=None,
                          node_selector=None,
                          affinity=None,
                          tolerations=None,
                          sidecar_context_mounts=None,
                          init_context_mounts=None,
                          restart_policy=None):
        """Pod spec to be used to create pods for tasks: master, worker, ps."""
        sidecar_context_mounts = to_list(sidecar_context_mounts, check_none=True)
        init_context_mounts = to_list(init_context_mounts, check_none=True)
        volume_mounts = to_list(volume_mounts, check_none=True)
        volumes = to_list(volumes, check_none=True)

        gpu_volume_mounts, gpu_volumes = get_gpu_volumes_def(resources)
        volume_mounts += gpu_volume_mounts
        volumes += gpu_volumes

        pod_container = self.get_pod_container(volume_mounts=volume_mounts,
                                               persistence_outputs=persistence_outputs,
                                               persistence_data=persistence_data,
                                               outputs_refs_jobs=outputs_refs_jobs,
                                               outputs_refs_experiments=outputs_refs_experiments,
                                               secret_refs=secret_refs,
                                               configmap_refs=configmap_refs,
                                               resources=resources,
                                               env_vars=env_vars,
                                               command=command,
                                               args=args,
                                               ports=ports,
                                               ephemeral_token=ephemeral_token)

        containers = [pod_container]
        if self.use_sidecar:
            sidecar_volume_mounts = self.get_sidecar_volume_mounts(
                persistence_outputs=persistence_outputs,
                persistence_data=persistence_data,
                context_mounts=sidecar_context_mounts)
            sidecar_container = self.get_sidecar_container(volume_mounts=sidecar_volume_mounts)
            containers.append(sidecar_container)

        init_container = self.get_init_container(init_command=init_command,
                                                 init_args=init_args,
                                                 env_vars=init_env_vars,
                                                 context_mounts=init_context_mounts,
                                                 persistence_outputs=persistence_outputs,
                                                 persistence_data=persistence_data)
        init_containers = to_list(init_container, check_none=True)

        node_selector = self._get_node_selector(node_selector=node_selector)
        affinity = self._get_affinity(affinity=affinity)
        tolerations = self._get_tolerations(tolerations=tolerations)
        service_account_name = self._get_service_account_name()
        return client.V1PodSpec(
            security_context=get_security_context() if self.use_security_context else None,
            restart_policy=restart_policy,
            service_account_name=service_account_name,
            init_containers=init_containers,
            containers=containers,
            volumes=volumes,
            node_selector=node_selector,
            tolerations=tolerations,
            affinity=affinity)