Ejemplo n.º 1
0
    def handle(self, *args, **options):
        log_sleep_interval = options['log_sleep_interval']
        self.stdout.write(
            "Started a new namespace monitor with, "
            "log sleep interval: `{}`.".format(log_sleep_interval),
            ending='\n')
        k8s_manager = K8SManager(namespace=conf.get('K8S_NAMESPACE'),
                                 in_cluster=True)
        cluster = self.get_cluster_or_wait(log_sleep_interval)
        if not cluster:
            # End process
            return

        while True:
            try:
                monitor.run(k8s_manager, cluster)
            except ApiException as e:
                monitor.logger.error(
                    "Exception when calling CoreV1Api->list_event_for_all_namespaces: %s\n",
                    e)
                time.sleep(log_sleep_interval)
            except ValueError as e:
                monitor.logger.error(
                    "Exception when calling CoreV1Api->list_event_for_all_namespaces: %s\n",
                    e)
            except Exception as e:
                monitor.logger.exception("Unhandled exception occurred: %s\n",
                                         e)
Ejemplo n.º 2
0
    def handle(self, *args, **options):
        log_sleep_interval = options['log_sleep_interval']
        self.stdout.write(
            "Started a new namespace monitor with, "
            "log sleep interval: `{}`.".format(log_sleep_interval),
            ending='\n')
        k8s_manager = K8SManager(namespace=settings.K8S_NAMESPACE, in_cluster=True)
        cluster = self.get_cluster_or_wait(log_sleep_interval)
        if not cluster:
            # End process
            return

        while True:
            try:
                monitor.run(k8s_manager, cluster)
            except ApiException as e:
                monitor.logger.error(
                    "Exception when calling CoreV1Api->list_event_for_all_namespaces: %s\n", e)
                time.sleep(log_sleep_interval)
            except Exception as e:
                monitor.logger.exception("Unhandled exception occurred: %s\n", e)