summaryrefslogtreecommitdiffstats
path: root/roles/openshift_logging/filter_plugins/openshift_logging.py
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2017-10-27 15:11:38 -0700
committerGitHub <noreply@github.com>2017-10-27 15:11:38 -0700
commit2c81304511afcf03b35583f85040fb7d0b83cad5 (patch)
tree3c496a4e621fa6545385e4c9c9a3a70f3883c70c /roles/openshift_logging/filter_plugins/openshift_logging.py
parentd40744574297204f5e7c326491ae1af07fab17ed (diff)
parent205d03455cf37d66f3629de7951463d755b72b16 (diff)
downloadopenshift-2c81304511afcf03b35583f85040fb7d0b83cad5.tar.gz
openshift-2c81304511afcf03b35583f85040fb7d0b83cad5.tar.bz2
openshift-2c81304511afcf03b35583f85040fb7d0b83cad5.tar.xz
openshift-2c81304511afcf03b35583f85040fb7d0b83cad5.zip
Merge pull request #5897 from jcantrill/1506073_cpu_request_match_limit
Automatic merge from submit-queue. bug 1506073. Lower cpu request for logging when it exceeds limit This PR fixes https://bugzilla.redhat.com/show_bug.cgi?id=1506073 by: * Lowering the CPU request to match the limit when the request is greater then a specified limit I have an open question on if this is an acceptable change of if it makes the outcome unexpected. Should we prefer to exit during the deployment and advise the operator to correct their inventory?
Diffstat (limited to 'roles/openshift_logging/filter_plugins/openshift_logging.py')
-rw-r--r--roles/openshift_logging/filter_plugins/openshift_logging.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/roles/openshift_logging/filter_plugins/openshift_logging.py b/roles/openshift_logging/filter_plugins/openshift_logging.py
index 959573635..e1a5ea726 100644
--- a/roles/openshift_logging/filter_plugins/openshift_logging.py
+++ b/roles/openshift_logging/filter_plugins/openshift_logging.py
@@ -3,6 +3,7 @@
'''
import random
+import re
def es_storage(os_logging_facts, dc_name, pvc_claim, root='elasticsearch'):
@@ -17,6 +18,31 @@ def es_storage(os_logging_facts, dc_name, pvc_claim, root='elasticsearch'):
return dict(kind='emptydir')
+def min_cpu(left, right):
+ '''Return the minimum cpu value of the two values given'''
+ message = "Unable to evaluate {} cpu value is specified correctly '{}'. Exp whole, decimal or int followed by M"
+ pattern = re.compile(r"^(\d*\.?\d*)([Mm])?$")
+ millis_per_core = 1000
+ if not right:
+ return left
+ m_left = pattern.match(left)
+ if not m_left:
+ raise RuntimeError(message.format("left", left))
+ m_right = pattern.match(right)
+ if not m_right:
+ raise RuntimeError(message.format("right", right))
+ left_value = float(m_left.group(1))
+ right_value = float(m_right.group(1))
+ if m_left.group(2) not in ["M", "m"]:
+ left_value = left_value * millis_per_core
+ if m_right.group(2) not in ["M", "m"]:
+ right_value = right_value * millis_per_core
+ response = left
+ if left_value != min(left_value, right_value):
+ response = right
+ return response
+
+
def walk(source, path, default, delimiter='.'):
'''Walk the sourch hash given the path and return the value or default if not found'''
if not isinstance(source, dict):
@@ -87,6 +113,7 @@ class FilterModule(object):
'random_word': random_word,
'entry_from_named_pair': entry_from_named_pair,
'map_from_pairs': map_from_pairs,
+ 'min_cpu': min_cpu,
'es_storage': es_storage,
'serviceaccount_name': serviceaccount_name,
'serviceaccount_namespace': serviceaccount_namespace,