예제 #1
0
    def __init__(self, args=None):
        self.args = args
        self.logger = logger.KubeManagerLogger(args)
        self.q = Queue()
        self.vnc = vnc_kubernetes.VncKubernetes(args=self.args,
                                                logger=self.logger,
                                                q=self.q)

        kube_api_connected = False
        while not kube_api_connected:
            try:
                self.namespace = namespace_monitor.NamespaceMonitor(
                    args=self.args, logger=self.logger, q=self.q)

                self.pod = pod_monitor.PodMonitor(args=self.args,
                                                  logger=self.logger,
                                                  q=self.q)

                self.service = service_monitor.ServiceMonitor(
                    args=self.args, logger=self.logger, q=self.q)

                self.network_policy =\
                    network_policy_monitor.NetworkPolicyMonitor(args=self.args,
                        logger=self.logger, q=self.q)

                self.endpoint = \
                    endpoint_monitor.EndPointMonitor( args=self.args,
                        logger=self.logger, q=self.q)

                kube_api_connected = True

            except Exception as e:
                time.sleep(5)
예제 #2
0
    def __init__(self, args=None, kube_api_connected=False, queue=None):
        self.args = args
        if 'kube_timer_interval' not in self.args:
            self.args.kube_timer_interval = '60'

        # randomize collector list
        self.args.random_collectors = args.collectors
        if self.args.collectors:
            self.args.random_collectors = random.sample(
                self.args.collectors, len(self.args.collectors))

        self.logger = logger.KubeManagerLogger(args)
        if queue:
            self.q = queue
        else:
            self.q = Queue()
        # All monitors supported by this manager.
        self.monitors = {}
        self.kube = None
        while not kube_api_connected:
            try:
                self.kube = kube_monitor.KubeMonitor(args=self.args,
                                                     logger=self.logger,
                                                     q=self.q)

                self.monitors[
                    'namespace'] = namespace_monitor.NamespaceMonitor(
                        args=self.args, logger=self.logger, q=self.q)

                self.monitors['pod'] = pod_monitor.PodMonitor(
                    args=self.args, logger=self.logger, q=self.q)

                self.monitors['service'] = service_monitor.ServiceMonitor(
                    args=self.args, logger=self.logger, q=self.q)

                self.monitors['network_policy'] =\
                    network_policy_monitor.NetworkPolicyMonitor(args=self.args,
                        logger=self.logger, q=self.q)

                self.monitors['endpoint'] = \
                    endpoint_monitor.EndPointMonitor(args=self.args,
                        logger=self.logger, q=self.q)

                self.monitors['ingress'] = \
                    ingress_monitor.IngressMonitor(args=self.args,
                        logger=self.logger, q=self.q)

                kube_api_connected = True

            except Exception as e:
                time.sleep(30)

        # Register all the known monitors.
        for monitor in self.monitors.values():
            monitor.register_monitor()

        self.vnc = vnc_kubernetes.VncKubernetes(args=self.args,
                                                logger=self.logger,
                                                q=self.q,
                                                kube=self.kube)
    def __init__(self, args=None):
        self.args = args
        self.logger = logger.KubeManagerLogger(args)
        self.q = Queue()
        self.vnc = vnc_kubernetes.VncKubernetes(args=self.args,
                                                logger=self.logger,
                                                q=self.q)

        kube_api_connected = False
        while not kube_api_connected:
            try:
                self.namespace = namespace_monitor.NamespaceMonitor(
                    args=self.args, logger=self.logger, q=self.q,
                    namespace_db=(NamespaceKM if\
                    self._kube_object_cache_enabled() == True else None))

                self.pod = pod_monitor.PodMonitor(args=self.args,
                    logger=self.logger, q=self.q, pod_db=(PodKM if\
                    self._kube_object_cache_enabled() == True else None))

                self.service = service_monitor.ServiceMonitor(
                    args=self.args, logger=self.logger, q=self.q,
                    service_db=(ServiceKM if\
                    self._kube_object_cache_enabled() == True else None))

                self.network_policy =\
                    network_policy_monitor.NetworkPolicyMonitor(args=self.args,
                        logger=self.logger, q=self.q,
                        network_policy_db=(NetworkPolicyKM if\
                        self._kube_object_cache_enabled() == True else None))

                kube_api_connected = True

            except Exception as e:
                time.sleep(5)
예제 #4
0
def main(args_str=None,
         kube_api_skip=False,
         event_queue=None,
         vnc_kubernetes_config_dict=None):
    _zookeeper_client = None

    args = kube_args.parse_args(args_str)
    if 'kube_timer_interval' not in args:
        args.kube_timer_interval = '60'

    if args.cluster_id:
        client_pfx = args.cluster_id + '-'
        zk_path_pfx = args.cluster_id + '/'
    else:
        client_pfx = ''
        zk_path_pfx = ''

    # randomize collector list
    args.random_collectors = args.collectors
    if args.collectors:
        args.random_collectors = random.sample(args.collectors,
                                               len(args.collectors))

    km_logger = common_logger.KubeManagerLogger(args, http_server_port=-1)

    if args.nested_mode == '0':
        # Initialize AMQP handler then close it to be sure remain queue of a
        # precedent run is cleaned
        rabbitmq_cfg = kube_args.rabbitmq_args(args)
        try:
            vnc_amqp = VncAmqpHandle(km_logger._sandesh, km_logger, DBBaseKM,
                                     REACTION_MAP, 'kube_manager',
                                     rabbitmq_cfg)
            vnc_amqp.establish()
            vnc_amqp.close()
        except Exception:  # FIXME: Except clause is too broad
            pass
        finally:
            km_logger.debug("Removed remained AMQP queue")

        # Ensure zookeeper is up and running before starting kube-manager
        _zookeeper_client = ZookeeperClient(client_pfx + "kube-manager",
                                            args.zk_server_ip)

        km_logger.notice("Waiting to be elected as master...")
        _zookeeper_client.master_election(zk_path_pfx + "/kube-manager",
                                          os.getpid(), run_kube_manager,
                                          km_logger, args, kube_api_skip,
                                          event_queue,
                                          vnc_kubernetes_config_dict)

    else:  # nested mode, skip zookeeper mastership check
        run_kube_manager(km_logger, args, kube_api_skip, event_queue,
                         vnc_kubernetes_config_dict)