Kubernetes integration with OpenStack networking
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
2.9 KiB

  1. # Copyright (c) 2016 Mirantis, Inc.
  2. # All Rights Reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  5. # not use this file except in compliance with the License. You may obtain
  6. # a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. # License for the specific language governing permissions and limitations
  14. # under the License.
  15. from requests import exceptions as requests_exc
  16. from keystoneauth1 import exceptions as key_exc
  17. from kuryr_kubernetes import exceptions
  18. from kuryr_kubernetes.handlers import asynchronous as h_async
  19. from kuryr_kubernetes.handlers import dispatch as h_dis
  20. from kuryr_kubernetes.handlers import k8s_base as h_k8s
  21. from kuryr_kubernetes.handlers import logging as h_log
  22. from kuryr_kubernetes.handlers import retry as h_retry
  23. class ControllerPipeline(h_dis.EventPipeline):
  24. """Serves as an entry point for controller Kubernetes events.
  25. `ControllerPipeline` is an entry point handler for the Kuryr-Kubernetes
  26. controller. `ControllerPipeline` allows registering
  27. :class:`kuryr_kubernetes.handlers.k8s_base.ResourceEventHandler`s and
  28. ensures the proper handler is called for each event that is passed to the
  29. `ControllerPipeline`. Also it ensures the following behavior:
  30. - multiple `ResourceEventHandler`s can be registered for the same
  31. resource type (`OBJECT_KIND`)
  32. - failing handlers (i.e. ones that raise `Exception`s) are retried
  33. until either the handler succeeds or a finite amount of time passes,
  34. in which case the most recent exception is logged
  35. - in case there are multiple handlers registered for the same resource
  36. type, all such handlers are considered independent (i.e. if one
  37. handler fails, other handlers will still be called regardless; and the
  38. order in which such handlers are called is not determined)
  39. - events for different Kubernetes objects can be handled concurrently
  40. - events for the same Kubernetes object are handled sequentially in
  41. the order of arrival
  42. """
  43. def __init__(self, thread_group):
  44. self._tg = thread_group
  45. super(ControllerPipeline, self).__init__()
  46. def _wrap_consumer(self, consumer):
  47. # TODO(ivc): tune retry interval/timeout
  48. return h_log.LogExceptions(h_retry.Retry(
  49. consumer, exceptions=(
  50. exceptions.ResourceNotReady,
  51. key_exc.connection.ConnectFailure,
  52. requests_exc.ConnectionError)))
  53. def _wrap_dispatcher(self, dispatcher):
  54. return h_log.LogExceptions(h_async.Async(dispatcher, self._tg,
  55. h_k8s.object_uid))