Skip to content

Commit

Permalink
Fix for getting optional information about openshift cluster version. (
Browse files Browse the repository at this point in the history
…#137)

* Fix for getting optional information about openshift cluster version.

* Rephrased comment after rebase
  • Loading branch information
ratsuf authored May 11, 2021
1 parent 60b09cd commit a77601b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
18 changes: 17 additions & 1 deletion cerberus/invoke/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import sys


# Invokes a given command and returns the stdout
# Invokes a given command and returns the stdout.
# Will stop Cerberus execution with exit code 1.
def invoke(command):
output = ""
try:
Expand All @@ -13,3 +14,18 @@ def invoke(command):
logging.error("Failed to run %s" % (command))
sys.exit(1)
return output


# Invokes a given command and returns the stdout.
# In case of exception, returns message about the impossibility to execute the command instead of stdout.
# It won't stop Cerberus execution but doesn't guarantee that command returns expected stdout.
def optional_invoke(command):
try:
optional_output = subprocess.check_output(command, shell=True,
universal_newlines=True)
except Exception:
optional_output = "Result is absent."
logging.info(
"Optional command '%s' can't be executed, but it's not a problem at all. We can continue." % command)

return optional_output
8 changes: 6 additions & 2 deletions start_cerberus.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,12 @@ def main(cfg):
# Cluster info
logging.info("Fetching cluster info")
if distribution == "openshift":
cluster_version = runcommand.invoke("kubectl get clusterversion")
logging.info("\n%s" % (cluster_version))
oc_version = runcommand.optional_invoke("oc version")
logging.info("oc version:\n%s" % oc_version)

cluster_version = runcommand.optional_invoke("oc get clusterversion")
logging.info("oc get clusterversion:\n%s" % cluster_version)

cluster_info = runcommand.invoke("kubectl cluster-info | awk 'NR==1' | sed -r "
"'s/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g'") # noqa
logging.info("%s" % (cluster_info))
Expand Down

0 comments on commit a77601b

Please sign in to comment.