Ë
    eQêjž5  ã                   ó”   — d Z ddlZddlZddlZddlmZ ddlmZ ddlm	Z	m
Z
  ej                  e«      ZdZdZd	Zd
ZdZ G d„ d«      Zy)zàInformer implementation for the Kubernetes Python client.

Provides SharedInformer: a background watcher that keeps a local
ObjectCache in sync with the Kubernetes API server and notifies
registered event-handler callbacks.
é    N)ÚApiException)ÚWatché   )ÚObjectCacheÚ_meta_namespace_keyÚADDEDÚMODIFIEDÚDELETEDÚBOOKMARKÚERRORc                   ób   — e Zd ZdZ	 	 	 	 	 dd„Zed„ «       Zd„ Zd„ Zd„ Z	d„ Z
d	„ Zd
„ Zd„ Zd„ Zy)ÚSharedInformera;  Watch a Kubernetes resource and maintain a local cache.

    The informer starts a daemon thread that continuously watches the
    given resource via ``list_func``.  On each event the local
    :class:`ObjectCache` is updated and registered
    event-handler callbacks are invoked.

    Parameters
    ----------
    list_func:
        Bound API method used for the initial list **and** as the watch
        source.  It must accept a watch keyword argument (e.g.
        CoreV1Api().list_namespaced_pod).
    namespace:
        Kubernetes namespace to watch.  Pass None for cluster-scoped
        or all-namespace list functions.
    resync_period:
        How often (seconds) to perform a full re-list from the API server.
        Defaults to 0 which disables periodic resyncs.
    label_selector:
        Optional label selector string forwarded to the API server.
    field_selector:
        Optional field selector string forwarded to the API server.
    key_func:
        Optional callable (obj) -> str used to key objects in the
        cache.  Defaults to namespace/name.
    Nc           
      óD  — || _         || _        || _        || _        || _        t        |¬«      | _        t        g t        g t        g t        g t        g i| _        t        j                  «       | _        d | _        d | _        t        j$                  «       | _        d | _        y )N)Úkey_func)Ú
_list_funcÚ
_namespaceÚ_resync_periodÚ_label_selectorÚ_field_selectorr   Ú_cacher   r	   r
   r   r   Ú	_handlersÚ	threadingÚLockÚ_handler_lockÚ_watchÚ_threadÚEventÚ_stop_eventÚ_resource_version)ÚselfÚ	list_funcÚ	namespaceÚresync_periodÚlabel_selectorÚfield_selectorr   s          úa/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/kubernetes/informer/informer.pyÚ__init__zSharedInformer.__init__G   s‡   € ð $ˆŒØ#ˆŒØ+ˆÔØ-ˆÔØ-ˆÔä!¨8Ô4ˆŒÜ ¤X¨r´7¸BÄÈ"ÌeÐUWÐXˆŒÜ&Ÿ^™^Ó-ˆÔàˆŒØˆŒÜ$Ÿ?™?Ó,ˆÔØ!%ˆÕó    c                 ó   — | j                   S )z5The :class:`ObjectCache` maintained by this informer.)r   ©r    s    r&   ÚcachezSharedInformer.cachec   s   € ð �{‰{Ðr(   c           
      ó  — || j                   vr=t        dj                  |dj                  t	        | j                   «      «      «      «      ‚| j
                  5  | j                   |   j                  |«       ddd«       y# 1 sw Y   yxY w)a_  Register a callback for a specific event type.

        Parameters
        ----------
        event_type:
            One of :data:`ADDED`, :data:`MODIFIED`, :data:`DELETED`,
            :data:`BOOKMARK` or :data:`ERROR`.
        handler:
            Callable invoked with the event object (or the raw exception for
            ERROR events).
        z'Unknown event_type {!r}. Use one of: {}z, N)r   Ú
ValueErrorÚformatÚjoinÚsortedr   Úappend©r    Ú
event_typeÚhandlers      r&   Úadd_event_handlerz SharedInformer.add_event_handlerh   sy   € ð ˜TŸ^™^Ñ+ÜØ9×@Ñ@Ø §	¡	¬&°·±Ó*@Ó Aóóð ð
 ×Ññ 	7Ø�N‰N˜:Ñ&×-Ñ-¨gÔ6÷	7÷ 	7ñ 	7ús   ÁB Â B	c                 ó®   — | j                   5  	 | j                  |   j                  |«       ddd«       y# t        t        f$ r Y Œw xY w# 1 sw Y   yxY w)zeDeregister a previously registered *handler*.

        No-op if *handler* is not registered.
        N)r   r   ÚremoveÚKeyErrorr-   r2   s      r&   Úremove_event_handlerz#SharedInformer.remove_event_handler}   s\   € ð
 ×Ññ 	ðØ—‘˜zÑ*×1Ñ1°'Ô:÷	ð 	øô œjÐ)ò Ùðú÷	ð 	ús&   �A�6¶AÁAÁAÁAÁAc                 ó  — | j                   �| j                   j                  «       ry| j                  j                  «        t	        j
                  | j                  dd¬«      | _         | j                   j                  «        y)z¢Start the background watch loop in a daemon thread.

        Calling :meth:`start` more than once without an intervening
        :meth:`stop` is a no-op.
        Nr   T)ÚtargetÚnameÚdaemon)r   Úis_aliver   Úclearr   ÚThreadÚ	_run_loopÚstartr*   s    r&   rB   zSharedInformer.startˆ   sc   € ð �<‰<Ð#¨¯©×(=Ñ(=Ô(?ØØ×Ñ×ÑÔ Ü ×'Ñ'Ø—>‘>Ø!Øô
ˆŒð
 	�‰×ÑÕr(   c                 óÞ   — | j                   j                  «        | j                  �| j                  j                  «        | j                  �| j                  j                  «        d| _        y)z:Ask the background watch loop to stop and join the thread.N)r   Úsetr   Ústopr   r/   r*   s    r&   rE   zSharedInformer.stop˜   sO   € à×Ñ×ÑÔØ�;‰;Ð"Ø�K‰K×ÑÔØ�<‰<Ð#Ø�L‰L×ÑÔØˆ�r(   c                 ó¬   — i }| j                   �| j                   |d<   | j                  �| j                  |d<   | j                  �| j                  |d<   |S )Nr"   r$   r%   )r   r   r   )r    Úkws     r&   Ú_build_kwargszSharedInformer._build_kwargs¥   s]   € ØˆØ�?‰?Ð&Ø"Ÿo™oˆBˆ{‰OØ×ÑÐ+Ø#'×#7Ñ#7ˆBÐÑ Ø×ÑÐ+Ø#'×#7Ñ#7ˆBÐÑ Øˆ	r(   c                 óú   — | j                   5  t        | j                  j                  |g «      «      }ddd«       D ]  }	  ||«       Œ y# 1 sw Y   ŒxY w# t        $ r t
        j                  d|«       Y Œ<w xY w)a  Execute all registered callbacks for *event_type*, passing *obj*.

        Callbacks are invoked sequentially on the informer's background thread.
        Any exception raised by an individual handler is logged and swallowed so
        that remaining handlers still run.
        Nz$Exception in informer handler for %s)r   Úlistr   ÚgetÚ	ExceptionÚloggerÚ	exception)r    r3   ÚobjÚhandlersÚfns        r&   Ú_firezSharedInformer._fire¯   s   € ð ×Ññ 	@Ü˜DŸN™N×.Ñ.¨z¸2Ó>Ó?ˆH÷	@àò 	ˆBðÙ�3•ñ	÷	@ð 	@ûô
 ò Ü× Ñ Ø:¸Jöðús   �&AÁAÁAÁA:Á9A:c                 óœ  — | j                  «       } | j                  di |¤Ž}t        |dg «      xs g }i }|D ]"  }| j                  j	                  |«      }|||<   Œ$ t        | j                  j                  «       «      }|D ];  }||vsŒ| j                  j                  |«      }|€Œ&| j                  t        |«       Œ= | j                  j                  |«       |j                  «       D ]6  \  }}||v r| j                  t        |«       Œ!| j                  t        |«       Œ8 d}	t        |dd«      }
|
�t        |
dd«      }	|	xs d| _        y)a¬  List all objects and populate the cache, firing ADDED/MODIFIED/DELETED events.

        On the first call (empty cache) every returned item fires ADDED.
        On subsequent calls (resync or after a 410 Gone) the new list is
        diffed against the existing cache:
        * Items absent from the new list fire DELETED.
        * Items present in both fire MODIFIED.
        * Items only in the new list fire ADDED.
        ÚitemsNÚmetadataÚresource_versionÚ0© )rH   r   Úgetattrr   Ú	_key_funcrD   Ú	list_keysÚ
get_by_keyrR   r
   Ú_replace_allrT   r	   r   r   )r    rG   ÚresprT   Únew_items_mapÚitemÚkeyÚold_keysÚold_objÚrvÚmetas              r&   Ú_initial_listzSharedInformer._initial_listÀ   sQ  € ð ×ÑÓ!ˆØˆt�‰Ñ$ Ñ$ˆÜ˜˜g rÓ*Ò0¨bˆð ˆØò 	&ˆDØ—+‘+×'Ñ'¨Ó-ˆCØ!%ˆM˜#Òð	&ô
 �t—{‘{×,Ñ,Ó.Ó/ˆð ò 	1ˆCØ˜-Ò'ØŸ+™+×0Ñ0°Ó5�ØÑ&Ø—J‘Jœw¨Õ0ð		1ð 	�‰× Ñ  Ô'ð '×,Ñ,Ó.ò 	(‰IˆC�Ø�h‰Ø—
‘
œ8 TÕ*à—
‘
œ5 $Õ'ð		(ð ˆÜ�t˜Z¨Ó.ˆØÐÜ˜Ð1°4Ó8ˆBØ!#¢ sˆÕr(   c                 óæ	  — | j                   j                  «       �s+| j                  €	 | j                  «        t        j                  «       }t        «       | _        | j                  «       }| j                  |d<   | j                  dkD  r"t!        dt#        | j                  «      «      |d<   	  | j                  j$                  | j&                  fi |¤ŽD �]ƒ  }| j                   j                  «       r �nf|j)                  d	«      }|j)                  d
«      }| j                  �1| j                  j*                  r| j                  j*                  | _        |t,        k(  r2| j.                  j1                  |«       | j                  t,        |«       Œ»|t2        k(  r2| j.                  j1                  |«       | j                  t2        |«       Œö|t4        k(  r3| j.                  j7                  |«       | j                  t4        |«       �Œ2|t8        k(  r(| j                  t8        |j)                  d|«      «       �Œc|t        k(  s�Œn| j                  t        |«       �Œ† | j                  �=| j                  �1| j                  j*                  r| j                  j*                  | _        d| _        | j                   j                  «       se| j                  �Y| j                  dkD  rJt        j                  «       |z
  | j                  k\  r&t
        jA                  d«       	 | j                  «        | j                   j                  «       s�Œ*yy# t        $ rR}t
        j                  d«       | j                  t        |«       | j                   j                  d¬«       Y d}~�Œ�d}~ww xY w# t:        $ rm}|j<                  dk(  rt
        j?                  d«       d| _        n t
        j?                  d|j<                  «       | j                  t        |«       Y d}~�Œ¼d}~wt        $ r6}t
        j                  d«       | j                  t        |«       Y d}~�Œùd}~ww xY w# | j                  �=| j                  �1| j                  j*                  r| j                  j*                  | _        d| _        w xY w# t        $ r6}t
        j                  d«       | j                  t        |«       Y d}~�ŒÁd}~ww xY w)a†  Background loop: list then watch, reconnect on errors.

        A full re-list is only performed when ``self._resource_version`` is
        ``None`` (first start or after a 410 Gone response).  On all other
        reconnects the most recent ``resourceVersion`` is reused so that no
        events are missed and the API server does not need to send a full
        object snapshot.
        Nz#Error during initial list; retryingé   )ÚtimeoutrV   r   r   Útimeout_secondsÚtypeÚobjectÚ
raw_objectiš  z3Watch expired (410 Gone); will re-list from scratchz>Watch stream ended with ApiException (status=%s); reconnectingz,Unexpected error in watch loop; reconnectingzInformer resync triggeredz$Error during resync list; continuing)!r   Úis_setr   rf   rL   rM   rN   rR   r   ÚwaitÚtimeÚ	monotonicr   r   rH   r   ÚmaxÚintÚstreamr   rK   rV   r   r   Ú_putr	   r
   Ú_remover   r   ÚstatusÚwarningÚdebug)r    ÚexcÚlast_resyncrG   ÚeventÚevt_typerO   s          r&   rA   zSharedInformer._run_loopî   sÏ  € ð ×"Ñ"×)Ñ)Õ+à×%Ñ%Ð-ðØ×&Ñ&Ô(ô Ÿ.™.Ó*ˆKÜ›'ˆDŒKØ×#Ñ#Ó%ˆBØ%)×%;Ñ%;ˆBÐ!Ñ"ð ×"Ñ" QÒ&Ü(+¨A¬s°4×3FÑ3FÓ/GÓ(H�Ð$Ñ%ð7#Ø/˜TŸ[™[×/Ñ/°·±ÑFÀ2ÑFó /�EØ×'Ñ'×.Ñ.Ô0ÚØ$Ÿy™y¨Ó0�HØŸ)™) HÓ-�Cð
 —{‘{Ð.°4·;±;×3OÒ3OØ15·±×1MÑ1M˜Ô.Ø¤5Ò(ØŸ™×(Ñ(¨Ô-ØŸ
™
¤5¨#Õ.Ø!¤XÒ-ØŸ™×(Ñ(¨Ô-ØŸ
™
¤8¨SÕ1Ø!¤WÒ,ØŸ™×+Ñ+¨CÔ0ØŸ
™
¤7¨CÖ0Ø!¤XÒ-ð Ÿ
™
¤8¨U¯Y©Y°|ÀSÓ-IÖJØ!¤UÔ*ØŸ
™
¤5¨#Ö.ð5/ðb ×*Ñ*Ð6ØŸ™Ð/ØŸ™×4Ò4à-1¯[©[×-IÑ-I�DÔ*Ø"�”ð ×$Ñ$×+Ñ+Ô-Ø×*Ñ*Ð6Ø×'Ñ'¨!Ò+Ü—^‘^Ó%¨Ñ3¸×8KÑ8KÒKä—‘Ð8Ô9ð+Ø×&Ñ&Ô(ðy ×"Ñ"×)Ñ)×+Ð+øô
 !ò Ü×$Ñ$Ð%JÔKØ—J‘Jœu cÔ*Ø×$Ñ$×)Ñ)°!Ð)Ô4Ýûð	ûô\  ò 'Ø—:‘: Ò$ä—N‘NØMôð .2�DÕ*ä—N‘NØXØŸ
™
ôð —
‘
œ5 #×&Ò&ûÜò 'Ü× Ñ Ð!OÔPØ—
‘
œ5 #×&Ò&ûð'ûð ×*Ñ*Ð6ØŸ™Ð/ØŸ™×4Ò4à-1¯[©[×-IÑ-I�DÔ*Ø"�•ûô !ò +Ü×$Ñ$Ð%KÔLØ—J‘Jœu c×*Ò*ûð+úsu   ©M Â-FN& ÉN& ÌR1 Í	N#ÍANÎN#Î&	QÎ/A"PÐQ ÐQÐ#+QÑQ ÑQÑQ ÑAR.Ò1	S0Ò:+S+Ó+S0)Nr   NNN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r'   Úpropertyr+   r5   r9   rB   rE   rH   rR   rf   rA   rX   r(   r&   r   r   *   s[   „ ñð> ØØØØó&ð8 ñó ðò7ò*	òò òòò",+ó\h+r(   r   )r�   Úloggingr   rp   Úkubernetes.client.exceptionsr   Úkubernetes.watchr   r+   r   r   Ú	getLoggerr~   rM   r   r	   r
   r   r   r   rX   r(   r&   ú<module>r‡      sW   ðñó Û Û å 5Ý "ç 3à	ˆ×	Ñ	˜8Ó	$€ð 	€Ø€Ø
€Ø€Ø€÷l+ò l+r(   