From 75efd74c18339dad5502bf49abf86b587c72b35c Mon Sep 17 00:00:00 2001 From: "avi@robusta.dev" Date: Thu, 20 Jun 2024 09:40:02 +0300 Subject: [PATCH] patched pod conditions --- robusta_krr/core/runner.py | 3 ++- robusta_krr/utils/patch.py | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 robusta_krr/utils/patch.py diff --git a/robusta_krr/core/runner.py b/robusta_krr/core/runner.py index e61200c..b28d071 100644 --- a/robusta_krr/core/runner.py +++ b/robusta_krr/core/runner.py @@ -20,6 +20,7 @@ from robusta_krr.utils.intro import load_intro_message from robusta_krr.utils.progress_bar import ProgressBar from robusta_krr.utils.version import get_version, load_latest_version +from robusta_krr.utils.patch import create_monkey_patches logger = logging.getLogger("krr") @@ -312,7 +313,6 @@ async def _collect_result(self) -> Result: async def run(self) -> int: """Run the Runner. The return value is the exit code of the program.""" await self._greet() - try: settings.load_kubeconfig() except Exception as e: @@ -321,6 +321,7 @@ async def run(self) -> int: return 1 # Exit with error try: + create_monkey_patches() # eks has a lower step limit than other types of prometheus, it will throw an error step_count = self._strategy.settings.history_duration * 60 / self._strategy.settings.timeframe_duration if settings.eks_managed_prom and step_count > 11000: diff --git a/robusta_krr/utils/patch.py b/robusta_krr/utils/patch.py new file mode 100644 index 0000000..e12114f --- /dev/null +++ b/robusta_krr/utils/patch.py @@ -0,0 +1,15 @@ +import logging + +from kubernetes.client.models.v1_pod_failure_policy_rule import V1PodFailurePolicyRule + +def create_monkey_patches(): + """ + The python kubernetes client will throw exceptions for specific fields that were not allowed to be None on older versions of kubernetes. + """ + logger = logging.getLogger("krr") + logger.debug("Creating kubernetes python cli monkey patches") + + def patched_setter_pod_failure_policy(self, on_pod_conditions): + self._on_pod_conditions = on_pod_conditions + + V1PodFailurePolicyRule.on_pod_conditions = V1PodFailurePolicyRule.on_pod_conditions.setter(patched_setter_pod_failure_policy)