Exemple #1
0
    def __init__(self) -> None:
        super().__init__()

        try:
            import pykube
        except ImportError:
            pass
        else:
            self.activity_handlers.append(handlers.ActivityHandler(
                id=handlers.HandlerId('login_via_pykube'),
                fn=cast(callbacks.ActivityHandlerFn, piggybacking.login_via_pykube),
                activity=causation.Activity.AUTHENTICATION,
                errors=errors_.ErrorsMode.IGNORED,
                timeout=None, retries=None, backoff=None, cooldown=None,
                _fallback=True,
            ))
        try:
            import kubernetes
        except ImportError:
            pass
        else:
            self.activity_handlers.append(handlers.ActivityHandler(
                id=handlers.HandlerId('login_via_client'),
                fn=cast(callbacks.ActivityHandlerFn, piggybacking.login_via_client),
                activity=causation.Activity.AUTHENTICATION,
                errors=errors_.ErrorsMode.IGNORED,
                timeout=None, retries=None, backoff=None, cooldown=None,
                _fallback=True,
            ))
Exemple #2
0
 def register(
     self,
     fn: callbacks.ActivityHandlerFn,
     *,
     id: Optional[str] = None,
     errors: Optional[errors_.ErrorsMode] = None,
     timeout: Optional[float] = None,
     retries: Optional[int] = None,
     backoff: Optional[float] = None,
     cooldown: Optional[float] = None,  # deprecated, use `backoff`
     activity: Optional[causation.Activity] = None,
     _fallback: bool = False,
 ) -> callbacks.ActivityHandlerFn:
     warnings.warn(
         "registry.register() is deprecated; "
         "use @kopf.on... decorators with registry= kwarg.",
         DeprecationWarning)
     real_id = generate_id(fn=fn, id=id)
     handler = handlers.ActivityHandler(
         id=real_id,
         fn=fn,
         activity=activity,
         errors=errors,
         timeout=timeout,
         retries=retries,
         backoff=backoff,
         cooldown=cooldown,
         _fallback=_fallback,
     )
     self.append(handler)
     return fn
Exemple #3
0
 def decorator(
         fn: callbacks.ActivityHandlerFn) -> callbacks.ActivityHandlerFn:
     real_registry = registry if registry is not None else registries.get_default_registry(
     )
     real_id = registries.generate_id(fn=fn, id=id)
     handler = handlers.ActivityHandler(
         fn=fn,
         id=real_id,
         errors=errors,
         timeout=timeout,
         retries=retries,
         backoff=backoff,
         cooldown=cooldown,
         activity=causation.Activity.CLEANUP,
     )
     real_registry.activity_handlers.append(handler)
     return fn
Exemple #4
0
 def register(
         self,
         fn: callbacks.ActivityHandlerFn,
         *,
         id: Optional[str] = None,
         errors: Optional[errors_.ErrorsMode] = None,
         timeout: Optional[float] = None,
         retries: Optional[int] = None,
         backoff: Optional[float] = None,
         cooldown: Optional[float] = None,  # deprecated, use `backoff`
         activity: Optional[causation.Activity] = None,
         _fallback: bool = False,
 ) -> callbacks.ActivityHandlerFn:
     real_id = generate_id(fn=fn, id=id, prefix=self.prefix)
     handler = handlers.ActivityHandler(
         id=real_id, fn=fn, activity=activity,
         errors=errors, timeout=timeout, retries=retries, backoff=backoff, cooldown=cooldown,
         _fallback=_fallback,
     )
     self.append(handler)
     return fn