示例#1
0
def main() -> None:
    args = parse_args()
    logging.basicConfig(level=logging.DEBUG if args.verbose else logging.INFO)
    kube_client = KubeClient()
    ensure_namespace(kube_client, namespace=PAASTA_NAMESPACE)
    success = setup_istio_mesh(kube_client, args.rate_limit, args.soa_dir)
    sys.exit(0 if success else 1)
示例#2
0
def main() -> None:
    args = parse_args()
    soa_dir = args.soa_dir
    if args.verbose:
        logging.basicConfig(level=logging.DEBUG)
    else:
        # filter out unwanted zookeeper messages in the log
        logging.getLogger("kazoo").setLevel(logging.WARN)
        logging.basicConfig(level=logging.INFO)

    deploy_metrics = metrics_lib.get_metrics_interface("paasta")

    # system_paasta_config = load_system_paasta_config()
    kube_client = KubeClient()

    ensure_namespace(kube_client, namespace="paasta")
    setup_kube_succeeded = setup_kube_deployments(
        kube_client=kube_client,
        service_instances=args.service_instance_list,
        soa_dir=soa_dir,
        cluster=args.cluster or load_system_paasta_config().get_cluster(),
        rate_limit=args.rate_limit,
        metrics_interface=deploy_metrics,
    )
    sys.exit(0 if setup_kube_succeeded else 1)
def setup_all_custom_resources(
    kube_client: KubeClient,
    soa_dir: str,
    cluster: str,
    custom_resource_definitions: Sequence[CustomResourceDefinition],
    service: str = None,
    instance: str = None,
) -> bool:
    cluster_crds = {
        crd.spec.names.kind
        for crd in kube_client.apiextensions.list_custom_resource_definition(
            label_selector=paasta_prefixed("service")).items
    }
    log.debug(f"CRDs found: {cluster_crds}")
    results = []
    for crd in custom_resource_definitions:
        if crd.kube_kind.singular not in cluster_crds:
            # TODO: kube_kind.singular seems to correspond to `crd.names.kind`
            # and not `crd.names.singular`
            log.warning(f"CRD {crd.kube_kind.singular} "
                        f"not found in {cluster}")
            continue

        # by convention, entries where key begins with _ are used as templates
        raw_config_dicts = load_all_configs(cluster=cluster,
                                            file_prefix=crd.file_prefix,
                                            soa_dir=soa_dir)
        config_dicts = {}
        for svc, raw_sdict in raw_config_dicts.items():
            sdict = {
                inst: idict
                for inst, idict in raw_sdict.items() if inst[0] != "_"
            }
            if sdict:
                config_dicts[svc] = sdict
        if not config_dicts:
            continue

        ensure_namespace(kube_client=kube_client,
                         namespace=f"paasta-{crd.kube_kind.plural}")
        results.append(
            setup_custom_resources(
                kube_client=kube_client,
                kind=crd.kube_kind,
                crd=crd,
                config_dicts=config_dicts,
                version=crd.version,
                group=crd.group,
                cluster=cluster,
                service=service,
                instance=instance,
            ))
    return any(results) if results else True
示例#4
0
def setup_all_custom_resources(
    kube_client: KubeClient,
    soa_dir: str,
    cluster: str,
    custom_resources: Sequence[CustomResource],
    service: str = None,
    instance: str = None,
) -> bool:
    cluster_crds = {
        crd.spec.names.kind
        for crd in kube_client.apiextensions.list_custom_resource_definition(
            label_selector="yelp.com/paasta_service", ).items
    }
    log.debug(f"CRDs found: {cluster_crds}")
    results = []
    for custom_resource in custom_resources:
        if custom_resource.kube_kind.singular not in cluster_crds:
            # TODO: kube_kind.singular seems to correspond to `crd.names.kind`
            # and not `crd.names.singular`
            log.warning(
                f"CRD {custom_resource.kube_kind.singular} "
                f"not found in {cluster}", )
            continue
        config_dicts = load_all_configs(
            cluster=cluster,
            file_prefix=custom_resource.file_prefix,
            soa_dir=soa_dir,
        )
        if not config_dicts:
            continue
        ensure_namespace(
            kube_client=kube_client,
            namespace=f'paasta-{custom_resource.kube_kind.plural}',
        )
        results.append(
            setup_custom_resources(
                kube_client=kube_client,
                kind=custom_resource.kube_kind,
                config_dicts=config_dicts,
                version=custom_resource.version,
                group=custom_resource.group,
                cluster=cluster,
                service=service,
                instance=instance,
            ), )
    return all(results) if results else True
示例#5
0
def main() -> None:
    args = parse_args()
    soa_dir = args.soa_dir
    if args.verbose:
        logging.basicConfig(level=logging.DEBUG)
    else:
        logging.basicConfig(level=logging.WARNING)

    # system_paasta_config = load_system_paasta_config()
    kube_client = KubeClient()

    ensure_namespace(kube_client, namespace='paasta')
    setup_kube_succeeded = setup_kube_deployments(
        kube_client=kube_client,
        service_instances=args.service_instance_list,
        soa_dir=soa_dir,
    )
    sys.exit(0 if setup_kube_succeeded else 1)
def main() -> None:
    args = parse_args()
    service_instance_list = args.service_instance_list
    deployment_names = get_deployment_names_from_list(service_instance_list)

    log.debug(f"Deleting deployments: {deployment_names}")
    kube_client = KubeClient()
    ensure_namespace(kube_client=kube_client, namespace="paasta")

    for deployment_name in deployment_names:
        try:
            log.debug(f"Deleting {deployment_name}")
            delete_deployment(kube_client=kube_client,
                              deployment_name=deployment_name)
        except Exception as err:
            log.error(f"Unable to delete {deployment_name}: {err}")
            sys.exit(1)

    sys.exit(0)
def main() -> int:
    args = parse_args()
    if args.verbose:
        logging.basicConfig(level=logging.DEBUG)
    else:
        logging.basicConfig(level=logging.INFO)

    log.info("Generating adapter config from soaconfigs.")
    config = create_prometheus_adapter_config(paasta_cluster=args.cluster,
                                              soa_dir=args.soa_dir)
    log.info("Generated adapter config from soaconfigs.")
    if args.dry_run:
        log.info(
            "Generated the following config:\n%s",
            yaml.dump(config,
                      default_flow_style=False,
                      explicit_start=True,
                      width=sys.maxsize),
        )
        return 0  # everything after this point requires creds/updates state
    else:
        log.debug(
            "Generated the following config:\n%s",
            yaml.dump(config,
                      default_flow_style=False,
                      explicit_start=True,
                      width=sys.maxsize),
        )

    if not config["rules"]:
        log.error("Got empty rule configuration - refusing to continue.")
        return 0

    kube_client = KubeClient()
    if not args.dry_run:
        ensure_namespace(kube_client, namespace="paasta")
        ensure_namespace(kube_client, namespace="custom-metrics")

    existing_config = get_prometheus_adapter_configmap(kube_client=kube_client)
    if existing_config and existing_config != config:
        log.info("Existing config differs from soaconfigs - updating.")
        log.debug("Existing data: %s", existing_config)
        log.debug("Desired data: %s", config)
        update_prometheus_adapter_configmap(kube_client=kube_client,
                                            config=config)
        log.info("Updated adapter config.")
    elif existing_config:
        log.info("Existing config matches soaconfigs - exiting.")
        return 0
    else:
        log.info("No existing config - creating.")
        create_prometheus_adapter_configmap(kube_client=kube_client,
                                            config=config)
        log.info("Created adapter config.")

    # the prometheus adapter doesn't currently have a good way to reload on config changes
    # so we do the next best thing: restart the pod so that it picks up the new config.
    # see: https://github.com/DirectXMan12/k8s-prometheus-adapter/issues/104
    restart_prometheus_adapter(kube_client=kube_client)

    return 0