コード例 #1
0
def main(args=None):
    parser = cmd.get_parser()
    args = parser.parse_args(args)

    logging.basicConfig(
        format="%(asctime)s %(levelname)s: %(message)s",
        level=logging.DEBUG if args.debug else logging.INFO,
    )

    config_str = ", ".join(f"{k}={v}" for k, v in sorted(vars(args).items()))
    logger.info(f"Janitor v{__version__} started with {config_str}")

    if args.dry_run:
        logger.info("**DRY-RUN**: no deletions will be performed!")

    if args.rules_file:
        rules = load_rules_from_file(args.rules_file)
        logger.info(f"Loaded {len(rules)} rules from file {args.rules_file}")
    else:
        rules = []

    return run_loop(
        args.once,
        args.include_resources,
        args.exclude_resources,
        args.include_namespaces,
        args.exclude_namespaces,
        rules,
        args.interval,
        args.delete_notification,
        args.deployment_time_annotation,
        args.resource_context_hook,
        args.dry_run,
    )
コード例 #2
0
def main(args=None):
    parser = cmd.get_parser()
    args = parser.parse_args(args)

    logging.basicConfig(format='%(asctime)s %(levelname)s: %(message)s',
                        level=logging.DEBUG if args.debug else logging.INFO)

    config_str = ', '.join(f'{k}={v}' for k, v in sorted(vars(args).items()))
    logger.info(f'Janitor v{__version__} started with {config_str}')

    if args.dry_run:
        logger.info('**DRY-RUN**: no deletions will be performed!')

    if args.rules_file:
        rules = load_rules_from_file(args.rules_file)
        logger.info(f'Loaded {len(rules)} rules from file {args.rules_file}')
    else:
        rules = []

    if args.tiller_host and args.tiller_port:
        tiller = Tiller(args.tiller_host, args.tiller_port)
    else:
        tiller = None

    return run_loop(args.once, args.include_resources, args.exclude_resources,
                    args.include_namespaces, args.exclude_namespaces, rules,
                    args.interval, args.delete_notification, args.dry_run,
                    tiller)
コード例 #3
0
def main(args=None):
    parser = cmd.get_parser()
    args = parser.parse_args(args)

    std = logging.StreamHandler(sys.stdout)
    logHandlers = [std]

    if args.slack_webhook_url:
        from slack_logger import SlackHandler, SlackFormatter
        sh = SlackHandler(username='******',
                          icon_emoji=':robot_face:',
                          url=args.slack_webhook_url)
        sh.addFilter(lambda x: x.levelno != logging.DEBUG)
        sh.setFormatter(SlackFormatter())
        logHandlers.append(sh)

    logging.basicConfig(
        handlers=logHandlers,
        format="%(asctime)s %(levelname)s: %(message)s",
        level=logging.DEBUG if args.debug else logging.INFO,
    )

    config_str = ", ".join(f"{k}={v}" for k, v in sorted(vars(args).items()))
    logger.info(f"Janitor v{__version__} started with {config_str}")

    if args.dry_run:
        logger.info("**DRY-RUN**: no deletions will be performed!")

    if args.rules_file:
        rules = load_rules_from_file(args.rules_file)
        logger.info(f"Loaded {len(rules)} rules from file {args.rules_file}")
    else:
        rules = []

    return run_loop(
        args.once,
        args.include_resources,
        args.exclude_resources,
        args.include_namespaces,
        args.exclude_namespaces,
        rules,
        args.interval,
        args.delete_notification,
        args.deployment_time_annotation,
        args.resource_context_hook,
        args.wait_after_delete,
        args.dry_run,
    )
コード例 #4
0
def main(args=None):
    parser = cmd.get_parser()
    args = parser.parse_args(args)

    logging.basicConfig(format='%(asctime)s %(levelname)s: %(message)s',
                        level=logging.DEBUG if args.debug else logging.INFO)

    logger.info(f'Janitor v{__version__} started with config {args}')

    if args.dry_run:
        logger.info('**DRY-RUN**: no deletions will be performed!')

    if args.rules_file:
        rules = load_rules_from_file(args.rules_file)
        logger.info(f'Loaded {len(rules)} rules from file {args.rules_file}')
    else:
        rules = []

    return run_loop(args.once, args.include_resources, args.exclude_resources,
                    args.include_namespaces, args.exclude_namespaces, rules,
                    args.interval, args.dry_run)
コード例 #5
0
def test_parse_args():
    parser = get_parser()
    parser.parse_args(['--dry-run', '--rules-file=/config/rules.yaml'])
コード例 #6
0
ファイル: test_cmd.py プロジェクト: enyachoke/kube-janitor
def test_parse_args():
    parser = get_parser()
    parser.parse_args(["--dry-run", "--rules-file=/config/rules.yaml"])