Exemplo n.º 1
0
#!/usr/bin/env python3
import sys
import time
from typing import Optional

import benji.helpers.prometheus as prometheus
import benji.helpers.settings as settings
import benji.helpers.utils as utils

utils.setup_logging()


def main():
    command = ' '.join(sys.argv[1:])
    start_time = time.time()

    prometheus.command_start_time.labels(command=command).set(start_time)
    try:
        utils.subprocess_run(
            ['benji', '--log-level', settings.benji_log_level] + sys.argv[1:])
    except Exception as exception:
        prometheus.command_status_failed.labels(command=command).set(1)
        completion_time = time.time()
        prometheus.command_completion_time.labels(
            command=command).set(completion_time)
        prometheus.command_runtime_seconds.labels(
            command=command).set(completion_time - start_time)
        prometheus.push(prometheus.command_registry)
        raise exception
    else:
        prometheus.command_status_succeeded.labels(command=command).set(1)
Exemplo n.º 2
0
import argparse
import os
import sys
import time

import kubernetes
from kubernetes.client.rest import ApiException

import benji.helpers.settings as settings
import benji.k8s_tools.kubernetes
from benji.helpers.utils import setup_logging, logger, subprocess_run

PVC_CREATION_MAX_POLLS = 15
PVC_CREATION_POLL_INTERVAL = 2  # seconds

setup_logging()


def main():
    parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter, allow_abbrev=False)

    parser.add_argument('-f',
                        '--force',
                        dest='force',
                        action='store_true',
                        default=False,
                        help='Overwrite content of existing persistent volumes')
    parser.add_argument('--pvc-storage-class',
                        metavar='pvc_storage_class',
                        dest='pvc_storage_class',
                        default=None,