From f52f16ade824f055288c6783d4c3330876592765 Mon Sep 17 00:00:00 2001 From: Sanja Bonic <86982064+sanjacodes@users.noreply.github.com> Date: Wed, 18 May 2022 11:00:30 +0200 Subject: [PATCH] Starts fixing small parts of issue #185 --- kraken/kubernetes/client.py | 26 ++++++++++++++++++++++++++ run_kraken.py | 13 +++++++------ 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/kraken/kubernetes/client.py b/kraken/kubernetes/client.py index 042df621..f7ff0120 100644 --- a/kraken/kubernetes/client.py +++ b/kraken/kubernetes/client.py @@ -23,6 +23,32 @@ def initialize_clients(kubeconfig_path): sys.exit(1) +def get_host() -> str: + """Returns the Kubernetes server URL""" + return client.configuration.Configuration.get_default_copy().host + + +def get_clusterversion_string() -> str: + """Returns clusterversion status text on OpenShift, empty string on other distributions""" + try: + custom_objects_api = client.CustomObjectsApi() + cvs = custom_objects_api.list_cluster_custom_object( + "config.openshift.io", + "v1", + "clusterversions", + ) + for cv in cvs["items"]: + for condition in cv["status"]["conditions"]: + if condition["type"] == "Progressing": + return condition["message"] + return "" + except client.exceptions.ApiException as e: + if e.status == 404: + return "" + else: + raise + + # List all namespaces def list_namespaces(label_selector=None): namespaces = [] diff --git a/run_kraken.py b/run_kraken.py index 60234c9b..36bf8547 100644 --- a/run_kraken.py +++ b/run_kraken.py @@ -9,7 +9,6 @@ import pyfiglet import uuid import time import kraken.kubernetes.client as kubecli -import kraken.invoke.command as runcommand import kraken.litmus.common_litmus as common_litmus import kraken.time_actions.common_time_functions as time_actions import kraken.performance_dashboards.setup as performance_dashboards @@ -97,11 +96,13 @@ def main(cfg): # Cluster info logging.info("Fetching cluster info") - cluster_version = runcommand.invoke("kubectl get clusterversion", 60) - cluster_info = runcommand.invoke( - "kubectl cluster-info | awk 'NR==1' | sed -r " "'s/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g'", 60 - ) # noqa - logging.info("\n%s%s" % (cluster_version, cluster_info)) + cv = kubecli.get_clusterversion_string() + if cv != "": + logging.info(cv) + else: + logging.info("Cluster version CRD not detected, skipping") + + logging.info("Server URL: %s" % kubecli.get_host()) # Deploy performance dashboards if deploy_performance_dashboards: