示例#1
0
def main() -> None:
    system_paasta_config = load_system_paasta_config()

    kube_client = KubeClient()

    services = {
        service
        for service, instance in get_services_for_cluster(
            cluster=system_paasta_config.get_cluster(),
            instance_type="kubernetes")
    }

    for service in services:
        pscl = PaastaServiceConfigLoader(service=service,
                                         load_deployments=False)
        for instance_config in pscl.instance_configs(
                cluster=system_paasta_config.get_cluster(),
                instance_type_class=KubernetesDeploymentConfig,
        ):
            max_instances = instance_config.get_max_instances()
            if max_instances is not None:
                formatted_application = instance_config.format_kubernetes_app()
                formatted_application.spec.replicas = max_instances
                wrapper = get_application_wrapper(formatted_application)
                wrapper.soa_config = instance_config
                print(f"Scaling up {service}.{instance_config.instance}")
                wrapper.update(kube_client)
示例#2
0
def create_application_object(
    kube_client: KubeClient,
    service: str,
    instance: str,
    cluster: str,
    soa_dir: str,
) -> Tuple[bool, Optional[Application]]:
    try:
        service_instance_config = load_kubernetes_service_config_no_cache(
            service,
            instance,
            cluster,
            soa_dir=soa_dir,
        )
    except NoDeploymentsAvailable:
        log.debug("No deployments found for %s.%s in cluster %s. Skipping." %
                  (service, instance, cluster))
        return True, None
    except NoConfigurationForServiceError:
        error_msg = (
            f"Could not read kubernetes configuration file for %s.%s in cluster %s"
            % (service, instance, cluster))
        log.error(error_msg)
        return False, None

    try:
        formatted_application = service_instance_config.format_kubernetes_app()
    except InvalidKubernetesConfig as e:
        log.error(str(e))
        return False, None

    app = get_application_wrapper(formatted_application)
    app.load_local_config(soa_dir, cluster)
    return True, app