diff --git a/roles/installer/filter_plugins/cpu_string_to_decimal.py b/roles/installer/filter_plugins/cpu_string_to_decimal.py new file mode 100644 index 00000000..ef9aae1b --- /dev/null +++ b/roles/installer/filter_plugins/cpu_string_to_decimal.py @@ -0,0 +1,27 @@ +# Copyright (c) 2017 Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +from ansible.errors import AnsibleFilterError + +__ERROR_MSG = "Not a valid cpu value. Cannot process value" + +class FilterModule(object): + def filters(self): + return { + 'cpu_string_to_decimal': self.cpu_string_to_decimal + } + def cpu_string_to_decimal(self, cpu_string): + + # verify if task_output is a dict + if not isinstance(cpu_string, str): + raise AnsibleFilterError(__ERROR_MSG) + + if cpu_string[-1] == 'm': + cpu = int(cpu_string[:-1])//1000 + else: + cpu = int(cpu_string) + + return cpu diff --git a/roles/installer/templates/configmaps/config.yaml.j2 b/roles/installer/templates/configmaps/config.yaml.j2 index ec5a757d..aa795d14 100644 --- a/roles/installer/templates/configmaps/config.yaml.j2 +++ b/roles/installer/templates/configmaps/config.yaml.j2 @@ -42,10 +42,19 @@ data: SYSTEM_TASK_ABS_CPU = '{{ task_resource_requirements["limits"]["cpu"] }}' {% endif %} +{%- set cpu_limit = task_resource_requirements["limits"]["cpu"] if "limits" in task_resource_requirements and "cpu" in task_resource_requirements["limits"] -%} +{%- if cpu_limit is defined -%} +{%- set callback_receiver_cpu = cpu_limit | cpu_string_to_decimal -%} +{%- if callback_receiver_cpu |int > 4 -%} +# Set callback receiver workers based off cpu limit, default workers are 4, but if we have more than 4 cpu we can set higher value for workers + JOB_EVENT_WORKERS = {{ callback_receiver_cpu }} +{%- endif -%} +{%- endif %} + SECRET_KEY = get_secret() - + ALLOWED_HOSTS = ['*'] - + INTERNAL_API_URL = 'http://127.0.0.1:8052' # Sets Ansible Collection path