Skip to content

Commit

Permalink
K8S: support for different priorityClassNames per job resource type (…
Browse files Browse the repository at this point in the history
…SCORE, MCORE...) (#119)
  • Loading branch information
fbarreir authored Sep 8, 2021
1 parent 81444c4 commit 108152c
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 8 deletions.
45 changes: 38 additions & 7 deletions pandaharvester/harvestermisc/info_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,26 +167,57 @@ def get_prorated_maxwdir_GiB(self, panda_resource, worker_corecount):

return maxwdir_prorated

def get_k8s_affinity_settings(self, panda_resource):
# this is how the parameters are declared in CRIC
def get_k8s_scheduler_settings(self, panda_resource):
# this is how the affinity settings are declared in CRIC
key_affinity = 'k8s.scheduler.use_score_affinity'
key_anti_affinity = 'k8s.scheduler.use_score_mcore_anti_affinity'

params = self.get_harvester_params(panda_resource)
ret_map = {}

try:
ret_map['use_affinity'] = params[key_affinity]
except KeyError:
# return default value
ret_map['use_affinity'] = True

try:
ret_map['use_anti_affinity'] = params[key_anti_affinity]
except KeyError:
# return default value
ret_map['use_anti_affinity'] = True

# this is how the affinity settings are declared in CRIC
key_priority_class_score = 'k8s.scheduler.priorityClassName.score'
key_priority_class_score_himem = 'k8s.scheduler.priorityClassName.score_himem'
key_priority_class_mcore = 'k8s.scheduler.priorityClassName.mcore'
key_priority_class_mcore_himem = 'k8s.scheduler.priorityClassName.mcore_himem'

try:
use_affinity = params[key_affinity]
ret_map['priority_class_score'] = params[key_priority_class_score]
except KeyError:
# return default value
use_affinity = True
ret_map['priority_class_score'] = None

try:
use_anti_affinity = params[key_anti_affinity]
ret_map['priority_class_score_himem'] = params[key_priority_class_score_himem]
except KeyError:
# return default value
use_anti_affinity = True
ret_map['priority_class_score_himem'] = None

return use_affinity, use_anti_affinity
try:
ret_map['priority_class_mcore'] = params[key_priority_class_mcore]
except KeyError:
# return default value
ret_map['priority_class_mcore'] = None

try:
ret_map['priority_class_mcore_himem'] = params[key_priority_class_mcore_himem]
except KeyError:
# return default value
ret_map['priority_class_mcore_himem'] = None

return ret_map

def get_k8s_resource_settings(self, panda_resource):
params = self.get_harvester_params(panda_resource)
Expand Down
14 changes: 13 additions & 1 deletion pandaharvester/harvestermisc/k8s_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,22 @@ def create_job_from_yaml(self, yaml_content, work_spec, prod_source_label, pilot
container_env['volumeMounts'].append({'name': 'job-config', 'mountPath': CONFIG_DIR})

# set the affinity
use_affinity, use_anti_affinity = self.panda_queues_dict.get_k8s_affinity_settings(work_spec.computingSite)
scheduling_settings = self.panda_queues_dict.get_k8s_scheduler_settings(work_spec.computingSite)

use_affinity = scheduling_settings['use_affinity']
use_anti_affinity = scheduling_settings['use_anti_affinity']
if (use_affinity or use_anti_affinity) and 'affinity' not in yaml_content['spec']['template']['spec']:
yaml_content = self.set_affinity(yaml_content, use_affinity, use_anti_affinity)

# set the priority classes
priority_class_key = 'priority_class_{0}'.format(work_spec.resourceType.lower())
try:
priority_class = scheduling_settings[priority_class_key]
except KeyError:
priority_class = None
if priority_class and 'priorityClassName' not in yaml_content['spec']['template']['spec']:
yaml_content['spec']['template']['spec']['priorityClassName'] = priority_class

# set max_time to avoid having a pod running forever
if 'activeDeadlineSeconds' not in yaml_content['spec']['template']['spec']:
if not max_time: # 4 days
Expand Down

0 comments on commit 108152c

Please sign in to comment.