def _create_job(self, task_type, task_idx, add_service, command=None, args=None, env_vars=None, resources=None, annotations=None, node_selector=None, affinity=None, tolerations=None, max_restarts=None): ephemeral_token = None if self.token_scope: ephemeral_token = RedisEphemeralTokens.generate_header_token( scope=self.token_scope) resource_name = self.resource_manager.get_resource_name( task_type=task_type, task_idx=task_idx) job_uuid = self.get_job_uuids(task_type=task_type, task_idx=task_idx) reconcile_url = get_experiment_reconcile_url(self.experiment_name, job_uuid) labels = self.get_labels(task_type=task_type, task_idx=task_idx, job_uuid=job_uuid) # Set and validate volumes volumes, volume_mounts = get_pod_volumes( persistence_outputs=self.persistence_config.outputs, persistence_data=self.persistence_config.data) refs_volumes, refs_volume_mounts = get_pod_refs_outputs_volumes( outputs_refs=self.outputs_refs_jobs, persistence_outputs=self.persistence_config.outputs) volumes += refs_volumes volume_mounts += refs_volume_mounts refs_volumes, refs_volume_mounts = get_pod_refs_outputs_volumes( outputs_refs=self.outputs_refs_experiments, persistence_outputs=self.persistence_config.outputs) volumes += refs_volumes volume_mounts += refs_volume_mounts shm_volumes, shm_volume_mounts = get_shm_volumes() volumes += shm_volumes volume_mounts += shm_volume_mounts context_volumes, context_mounts = get_auth_context_volumes() volumes += context_volumes volume_mounts += context_mounts pod = self.resource_manager.get_task_pod( task_type=task_type, task_idx=task_idx, volume_mounts=volume_mounts, volumes=volumes, labels=labels, env_vars=env_vars, command=command, args=args, ports=self.ports, init_env_vars=self.get_init_env_vars(), persistence_outputs=self.persistence_config.outputs, persistence_data=self.persistence_config.data, outputs_refs_jobs=self.outputs_refs_jobs, outputs_refs_experiments=self.outputs_refs_experiments, secret_refs=self.spec.secret_refs, config_map_refs=self.spec.config_map_refs, resources=resources, ephemeral_token=ephemeral_token, node_selector=node_selector, affinity=affinity, tolerations=tolerations, init_context_mounts=context_mounts, reconcile_url=reconcile_url, max_restarts=max_restarts, restart_policy=get_pod_restart_policy(max_restarts)) pod_resp, _ = self.create_or_update_pod(name=resource_name, body=pod, reraise=True) results = {'pod': pod_resp.to_dict()} if add_service: service = services.get_service(namespace=self.namespace, name=resource_name, labels=labels, ports=self.ports, target_ports=self.ports) service_resp, _ = self.create_or_update_service(name=resource_name, body=service, reraise=True) results['service'] = service_resp.to_dict() return results
def _create_job( self, # pylint:disable=arguments-differ task_type, command=None, args=None, env_vars=None, resources=None, node_selector=None, affinity=None, tolerations=None, replicas=1, restart_policy='Never'): ephemeral_token = None if self.token_scope: ephemeral_token = RedisEphemeralTokens.generate_header_token( scope=self.token_scope) resource_name = self.resource_manager.get_kf_resource_name( task_type=task_type) labels = self.resource_manager.get_labels(task_type=task_type) # Set and validate volumes volumes, volume_mounts = get_pod_volumes( persistence_outputs=self.persistence_config.outputs, persistence_data=self.persistence_config.data) refs_volumes, refs_volume_mounts = get_pod_refs_outputs_volumes( outputs_refs=self.outputs_refs_jobs, persistence_outputs=self.persistence_config.outputs) volumes += refs_volumes volume_mounts += refs_volume_mounts refs_volumes, refs_volume_mounts = get_pod_refs_outputs_volumes( outputs_refs=self.outputs_refs_experiments, persistence_outputs=self.persistence_config.outputs) volumes += refs_volumes volume_mounts += refs_volume_mounts shm_volumes, shm_volume_mounts = get_shm_volumes() volumes += shm_volumes volume_mounts += shm_volume_mounts context_volumes, context_mounts = get_auth_context_volumes() volumes += context_volumes volume_mounts += context_mounts # Validate secret and configmap refs secret_refs = validate_secret_refs(self.spec.secret_refs) configmap_refs = validate_configmap_refs(self.spec.configmap_refs) pod_template_spec = self.resource_manager.get_pod_template_spec( resource_name=resource_name, volume_mounts=volume_mounts, volumes=volumes, labels=labels, env_vars=env_vars, command=command, args=args, ports=self.ports, init_env_vars=self.get_init_env_vars(), persistence_outputs=self.persistence_config.outputs, persistence_data=self.persistence_config.data, outputs_refs_jobs=self.outputs_refs_jobs, outputs_refs_experiments=self.outputs_refs_experiments, secret_refs=secret_refs, configmap_refs=configmap_refs, resources=resources, ephemeral_token=ephemeral_token, node_selector=node_selector, affinity=affinity, tolerations=tolerations, init_context_mounts=context_mounts, restart_policy=restart_policy) return { 'replicas': replicas, 'restartPolicy': restart_policy, 'template': pod_template_spec }
def _create_job(self, task_type, task_idx, add_service, command=None, args=None, env_vars=None, resources=None, node_selector=None, affinity=None, tolerations=None, restart_policy='Never'): ephemeral_token = RedisEphemeralTokens.generate_header_token( scope=self.token_scope) job_name = self.pod_manager.get_job_name(task_type=task_type, task_idx=task_idx) sidecar_args = get_sidecar_args(pod_id=job_name) labels = self.pod_manager.get_labels(task_type=task_type, task_idx=task_idx) # Set and validate volumes volumes, volume_mounts = get_pod_volumes( persistence_outputs=self.persistence_config.outputs, persistence_data=self.persistence_config.data) refs_volumes, refs_volume_mounts = get_pod_refs_outputs_volumes( outputs_refs=self.outputs_refs_jobs, persistence_outputs=self.persistence_config.outputs) volumes += refs_volumes volume_mounts += refs_volume_mounts refs_volumes, refs_volume_mounts = get_pod_refs_outputs_volumes( outputs_refs=self.outputs_refs_experiments, persistence_outputs=self.persistence_config.outputs) volumes += refs_volumes volume_mounts += refs_volume_mounts shm_volumes, shm_volume_mounts = get_shm_volumes() volumes += shm_volumes volume_mounts += shm_volume_mounts # Validate secret and configmap refs secret_refs = validate_secret_refs(self.spec.secret_refs) configmap_refs = validate_configmap_refs(self.spec.configmap_refs) pod = self.pod_manager.get_pod( task_type=task_type, task_idx=task_idx, volume_mounts=volume_mounts, volumes=volumes, labels=labels, env_vars=env_vars, command=command, args=args, sidecar_args=sidecar_args, persistence_outputs=self.persistence_config.outputs, persistence_data=self.persistence_config.data, outputs_refs_jobs=self.outputs_refs_jobs, outputs_refs_experiments=self.outputs_refs_experiments, secret_refs=secret_refs, configmap_refs=configmap_refs, resources=resources, ephemeral_token=ephemeral_token, node_selector=node_selector, affinity=affinity, tolerations=tolerations, restart_policy=restart_policy) pod_resp, _ = self.create_or_update_pod(name=job_name, data=pod) results = {'pod': pod_resp.to_dict()} if add_service: service = services.get_service(namespace=self.namespace, name=job_name, labels=labels, ports=self.pod_manager.ports, target_ports=self.pod_manager.ports) service_resp, _ = self.create_or_update_service(name=job_name, data=service) results['service'] = service_resp.to_dict() return results