Skip to content

Commit

Permalink
Add the patching of kubernetes.client.models.v1_pod_failure_policy_ru…
Browse files Browse the repository at this point in the history
…le.V1PodFailurePolicyRule.on_pod_conditions setter (robusta-dev#1172)
  • Loading branch information
RobertSzefler authored and pavangudiwada committed May 30, 2024
1 parent cb3a764 commit 65c11f9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/robusta/core/discovery/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
from robusta.core.model.jobs import JobInfo
from robusta.core.model.namespaces import NamespaceInfo
from robusta.core.model.services import ContainerInfo, ServiceConfig, ServiceInfo, VolumeInfo
from robusta.patch.patch import patch_on_pod_conditions
from robusta.utils.cluster_provider_discovery import cluster_provider
from robusta.utils.stack_tracer import StackTracer

Expand Down Expand Up @@ -135,6 +136,7 @@ def create_service_info(obj: Union[Deployment, DaemonSet, StatefulSet, Pod, Repl

@staticmethod
def discovery_process() -> DiscoveryResults:
patch_on_pod_conditions()
Discovery.stacktrace_thread_active = True
threading.Thread(target=Discovery.stack_dump_on_signal).start()
pods_metadata: List[V1ObjectMeta] = []
Expand Down
15 changes: 14 additions & 1 deletion src/robusta/patch/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from hikaru import HikaruBase, HikaruDocumentBase
from kubernetes.client.models.events_v1_event import EventsV1Event
from kubernetes.client.models.v1_container_image import V1ContainerImage
from kubernetes.client.models.v1_pod_failure_policy_rule import V1PodFailurePolicyRule
from ruamel.yaml import YAML

try:
Expand Down Expand Up @@ -38,6 +38,19 @@ def create_monkey_patches():
# which causes the kubernetes python api to throw an exception
logging.info("Creating kubernetes ContainerImage monkey patch")
EventsV1Event.event_time = EventsV1Event.event_time.setter(event_time)
patch_on_pod_conditions()


def patch_on_pod_conditions():
# This fixes https://github.com/kubernetes-client/python/issues/2056 before the
# k8s people take care of it (it's urgent for us).

logging.info("Creating kubernetes PodFailurePolicyRUle.on_pod_conditions monkey patch")

def patched_setter(self, on_pod_conditions):
self._on_pod_conditions = on_pod_conditions

V1PodFailurePolicyRule.on_pod_conditions = V1PodFailurePolicyRule.on_pod_conditions.setter(patched_setter)


def event_time(self, event_time):
Expand Down

0 comments on commit 65c11f9

Please sign in to comment.