Skip to content

Commit

Permalink
F OpenNebula/one-aiops#70: wait until kubernetes detect all workers n…
Browse files Browse the repository at this point in the history
…odes
  • Loading branch information
MarioRobres committed Jul 26, 2024
1 parent a5d7a71 commit 198170b
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions lithops/serverless/backends/one/one.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,17 @@ def __init__(self, one_config, internal_storage):


def invoke(self, docker_image_name, runtime_memory, job_payload):
# Wait for nodes to become available in Kubernetes
vms = len(self._get_vm_workers())
super()._get_nodes()
while len(self.nodes) < vms:
time.sleep(1)
super()._get_nodes()

# Scale nodes
scale_nodes, pods, chunksize, worker_processes = self._granularity(
job_payload['total_calls']
)

# Scale nodes
if scale_nodes == 0 and len(self.nodes) == 0:
raise OneError(
f"No nodes available and can't scale. Ensure nodes are active, detected by "
Expand Down Expand Up @@ -244,6 +249,17 @@ def _check_vms_status(self):
)


def _get_vm_workers(self):
workers_ids = set()
_service_json = self.client.servicepool[self.service_id].info()
roles = _service_json[str(self.service_id)]['TEMPLATE']['BODY']['roles']
for role in roles:
if role['name'] == 'worker':
for node in role['nodes']:
workers_ids.add(node['vm_info']['VM']['ID'])
return workers_ids


def _granularity(self, total_functions):
_host_cpu, _host_mem = self._one_resources()
_node_cpu, _node_mem = self._node_resources()
Expand Down

0 comments on commit 198170b

Please sign in to comment.