Skip to content

Commit

Permalink
tasks: check allocatable resources
Browse files Browse the repository at this point in the history
* Adds task calling k8s api to check if there are sufficient
  allocatable resources available in any nodes of the cluster.

Signed-off-by: Dinos Kousidis <dinos.kousidis@cern.ch>
  • Loading branch information
dinosk committed Dec 19, 2018
1 parent 146d445 commit b3b08c6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
9 changes: 9 additions & 0 deletions reana_commons/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,12 @@
'reana_job_controller.json')
}
"""REANA Workflow Controller address."""

K8S_MINIMUM_CAPACITY_CPU = 1
"""Minimum allocatable cpu capacity in cluster to start new workflows."""

K8S_MINIMUM_CAPACITY_MEMORY = 1000000
"""Minimum allocatable memory capacity in cluster to start new workflows."""

K8S_MINIMUM_CAPACITY_PODS = 109
"""Minimum allocatable pod capacity in cluster to start new workflows."""
31 changes: 28 additions & 3 deletions reana_commons/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
from kubernetes.client.rest import ApiException

from reana_commons.api_client import JobControllerAPIClient
from reana_commons.config import (K8S_MINIMUM_CAPACITY_CPU,
K8S_MINIMUM_CAPACITY_MEMORY,
K8S_MINIMUM_CAPACITY_PODS)
from reana_commons.k8s.api_client import current_k8s_corev1_api_client

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -49,9 +52,31 @@ def stop_workflow(workflow_uuid, job_list):
def reana_ready():
"""Check if reana can start new workflows."""
try:
import wdb
wdb.set_trace()
current_k8s_corev1_api_client.read_node_status('minikube')
import random
import time
time.sleep(10)
return random.random() > 0.5
is_ready = False
node_info = current_k8s_corev1_api_client.list_node()
for node in node_info.items:
# One check could be based on the predefined conditions about the
# node status: MemoryPressure, OutOfDisk, KubeletReady
# DiskPressure, PIDPressure,
for condition in node.status.conditions:
if not condition.status:
return False
allocatable_capacity = node.status.allocatable
# Another could be based on watermarks set in the configuration
# an issue here is allocatable_capacity does not live update,
# and there are cluster monitoring tools available like heapster
# that expose an API with the real time data. So the lines below
# are not meaningful.
if int(allocatable_capacity['cpu']) > K8S_MINIMUM_CAPACITY_CPU and \
int(allocatable_capacity['pods']) > K8S_MINIMUM_CAPACITY_PODS and \
int(allocatable_capacity['memory'][:-2]) > K8S_MINIMUM_CAPACITY_MEMORY:
is_ready = True
break
return is_ready
except ApiException as e:
print(str(e))
return True

0 comments on commit b3b08c6

Please sign in to comment.