Пример #1
0
def get_gateway_info(platform):
    ingress_host = ""
    ingress_port = ""
    if platform == "GCP":
        cmd = "kubectl -n istio-system get service istio-ingressgateway "
        cmd += "-o jsonpath={.status.loadBalancer.ingress[0].ip} "
        ingress_host = util.get_output_from_proc(cmd).decode("utf-8").replace(
            "'", "")

        cmd = "kubectl -n istio-system get service istio-ingressgateway "
        cmd += " -o jsonpath={.spec.ports[?(@.name==\"http2\")].port}"
        ingress_port = util.get_output_from_proc(cmd).decode("utf-8").replace(
            "'", "")
    else:
        cmd = "minikube ip"
        ingress_host = util.get_output_from_proc(cmd).decode("utf-8").rstrip()
        cmd = "kubectl -n istio-system get service istio-ingressgateway"
        cmd += " -o jsonpath={.spec.ports[?(@.name==\"http2\")].nodePort}"
        ingress_port = util.get_output_from_proc(cmd).decode("utf-8")

    log.debug("Ingress Host: %s", ingress_host)
    log.debug("Ingress Port: %s", ingress_port)
    gateway_url = f"{ingress_host}:{ingress_port}"
    log.debug("Gateway: %s", gateway_url)

    return ingress_host, ingress_port, gateway_url
Пример #2
0
def deploy_addons(addons):
    apply_cmd = "kubectl apply -f "
    url = "https://raw.githubusercontent.com/istio/istio/release-1.9"
    cmd = ""
    if "kiali" in addons:
        addons.append("kiali")
    for (idx, addon) in enumerate(addons):
        if addon == "prometheus-mod":
            cmd += f"{apply_cmd} {YAML_DIR}/prometheus-mod.yaml"
        else:
            cmd += f"{apply_cmd} {url}/samples/addons/{addon}.yaml"
        if idx < len(addons) - 1:
            cmd += " && "
    result = util.exec_process(cmd)
    if result != util.EXIT_SUCCESS:
        return result

    cmd = "kubectl get deploy -n istio-system -o name"
    deployments = util.get_output_from_proc(cmd).decode("utf-8").strip()
    deployments = deployments.split("\n")
    for depl in deployments:
        wait_cmd = "kubectl rollout status -n istio-system "
        wait_cmd += f"{depl} -w --timeout=180s"
        _ = util.exec_process(wait_cmd)
    log.info("Addons are ready.")
    return util.EXIT_SUCCESS
Пример #3
0
def bookinfo_wait():
    cmd = "kubectl get deploy -o name"
    deployments = util.get_output_from_proc(cmd).decode("utf-8").strip()
    deployments = deployments.split("\n")
    for depl in deployments:
        wait_cmd = f"kubectl rollout status {depl} -w --timeout=180s"
        _ = util.exec_process(wait_cmd)
    log.info("Bookinfo is ready.")
    return util.EXIT_SUCCESS
Пример #4
0
def launch_storage_mon():                                                       
    if kube_env.check_kubernetes_status() != util.EXIT_SUCCESS:                 
        log.error("Kubernetes is not set up."                                   
                  " Did you run the deployment script?")                        
        sys.exit(util.EXIT_FAILURE)                                             
    cmd = "kubectl get pods -lapp=storage-upstream "                            
    cmd += " -o jsonpath={.items[0].metadata.name} -n=storage"                  
    storage_pod_name = util.get_output_from_proc(cmd).decode("utf-8")           
    cmd = f"kubectl -n=storage port-forward {storage_pod_name} 8090:8080"       
    storage_proc = util.start_process(cmd, preexec_fn=os.setsid)                
    # Let settle things in a bit                                                
    time.sleep(2)                                                               
    return storage_proc
Пример #5
0
def launch_prometheus():
    if kube_env.check_kubernetes_status() != util.EXIT_SUCCESS:
        log.error("Kubernetes is not set up."
                  " Did you run the deployment script?")
        sys.exit(util.EXIT_FAILURE)
    cmd = "kubectl get pods -n istio-system -lapp=prometheus "
    cmd += " -o jsonpath={.items[0].metadata.name}"
    prom_pod_name = util.get_output_from_proc(cmd).decode("utf-8")
    cmd = f"kubectl port-forward -n istio-system {prom_pod_name} 9090"
    prom_proc = util.start_process(cmd, preexec_fn=os.setsid)
    time.sleep(2)
    prom_api = PrometheusConnect(url="http://localhost:9090", disable_ssl=True)

    return prom_proc, prom_api
Пример #6
0
def patch_bookinfo():
    cmd = "kubectl get deploy -o name"
    deployments = util.get_output_from_proc(cmd).decode("utf-8").strip()
    deployments = deployments.split("\n")
    for depl in deployments:
        patch_cmd = f"kubectl patch {depl} "
        patch_cmd += f"--patch-file {YAML_DIR}/cm_patch.yaml "
        result = util.exec_process(patch_cmd)
        if result != util.EXIT_SUCCESS:
            log.error("Failed to patch %s.", depl)
    # we also patch storage
    patch_cmd = "kubectl patch -n storage deployment.apps/storage-upstream "
    patch_cmd += f"--patch-file {YAML_DIR}/cm_patch.yaml "
    result = util.exec_process(patch_cmd)
    if result != util.EXIT_SUCCESS:
        log.error("Failed to patch storage.")
    return result
Пример #7
0
def query_storage(platform):
    if platform == "GCP":
        time.sleep(10)  # wait for logs to come in
        logs = []
        cmd = f"{kube_env.TOOLS_DIR}/logs_script.sh"
        output = util.get_output_from_proc(cmd).decode("utf-8").split("\n")
        for line in output:
            if "Stored" in line:
                line = line[line.find("Stored"):]  # get right after timestamp
                line = line.split()
                timestamp = line[1]
                name = line[-1]
                logs.append([timestamp, name])
    else:
        storage_content = requests.get("http://localhost:8090/list")
        output = storage_content.text.split("\n")
        logs = []
        for line in output:
            if "->" in line:
                line_time, line_name = line.split("->")
                logs.append([line_time, line_name])
    return sorted(logs, key=lambda tup: tup[0])