From 78e0d25b38bf109b694e2ffd710eb345de321820 Mon Sep 17 00:00:00 2001 From: LeaveMyYard Date: Tue, 10 Oct 2023 14:49:17 +0300 Subject: [PATCH] Patch fix for proxy not working from kubeconfig --- .../{kubernetes.py => kubernetes/__init__.py} | 1 + .../integrations/kubernetes/config_patch.py | 37 +++++++++++++++++++ .../integrations/{ => kubernetes}/rollout.py | 0 3 files changed, 38 insertions(+) rename robusta_krr/core/integrations/{kubernetes.py => kubernetes/__init__.py} (99%) create mode 100644 robusta_krr/core/integrations/kubernetes/config_patch.py rename robusta_krr/core/integrations/{ => kubernetes}/rollout.py (100%) diff --git a/robusta_krr/core/integrations/kubernetes.py b/robusta_krr/core/integrations/kubernetes/__init__.py similarity index 99% rename from robusta_krr/core/integrations/kubernetes.py rename to robusta_krr/core/integrations/kubernetes/__init__.py index db85fb9a..8bb89a19 100644 --- a/robusta_krr/core/integrations/kubernetes.py +++ b/robusta_krr/core/integrations/kubernetes/__init__.py @@ -22,6 +22,7 @@ from robusta_krr.core.models.result import ResourceAllocations from robusta_krr.utils.configurable import Configurable +from . import config_patch as _ from .rollout import RolloutAppsV1Api AnyKubernetesAPIObject = Union[V1Deployment, V1DaemonSet, V1StatefulSet, V1Pod, V1Job] diff --git a/robusta_krr/core/integrations/kubernetes/config_patch.py b/robusta_krr/core/integrations/kubernetes/config_patch.py new file mode 100644 index 00000000..5f294bcb --- /dev/null +++ b/robusta_krr/core/integrations/kubernetes/config_patch.py @@ -0,0 +1,37 @@ +# NOTE: This is a workaround for the issue described here: +# https://github.com/kubernetes-client/python/pull/1863 + +from __future__ import annotations + +from kubernetes.client import configuration +from kubernetes.config import kube_config + + +class KubeConfigLoader(kube_config.KubeConfigLoader): + def _load_cluster_info(self): + super()._load_cluster_info() + + if "proxy-url" in self._cluster: + self.proxy = self._cluster["proxy-url"] + + def _set_config(self, client_configuration: Configuration): + super()._set_config(client_configuration) + + key = "proxy" + if key in self.__dict__: + setattr(client_configuration, key, getattr(self, key)) + + +class Configuration(configuration.Configuration): + def __init__( + self, + proxy: str | None = None, + **kwargs, + ): + super().__init__(**kwargs) + + self.proxy = proxy + + +configuration.Configuration = Configuration +kube_config.KubeConfigLoader = KubeConfigLoader diff --git a/robusta_krr/core/integrations/rollout.py b/robusta_krr/core/integrations/kubernetes/rollout.py similarity index 100% rename from robusta_krr/core/integrations/rollout.py rename to robusta_krr/core/integrations/kubernetes/rollout.py