-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[minor] Add must-gather summarizer (#295)
Co-authored-by: David Parker <[email protected]>
- Loading branch information
Showing
11 changed files
with
234 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,4 @@ tmp/ | |
tekton/test-*.yaml | ||
tekton/target | ||
tekton/tmp | ||
*.pyc |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ kubernetes==12.0.1 | |
openshift==0.12.1 | ||
jmespath==1.0.0 | ||
click==8.1.3 | ||
prettytable==3.7.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
image/cli/mascli/must-gather/summarizer/mg-print-summary.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import sys | ||
|
||
import mg.cluster | ||
import mg.catalogs | ||
import mg.subscriptions | ||
|
||
if __name__ == "__main__": | ||
output_dir=sys.argv[1] | ||
|
||
mg.cluster.summarize(output_dir) | ||
mg.catalogs.summarize(output_dir) | ||
mg.subscriptions.summarize(output_dir) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import yaml | ||
from prettytable import PrettyTable | ||
|
||
from mg.utils import printHeader | ||
|
||
# process the catalog source information and show any catalogsources that have problems | ||
def process_catalogsource( output_dir, catalogsource, catalogsource_table ): | ||
catalogsourcename = catalogsource.rsplit()[0] | ||
catalogsource_yaml_file = output_dir + "/resources/openshift-marketplace/catalogsources/" + catalogsourcename + ".yaml" | ||
|
||
with open(catalogsource_yaml_file, 'r') as file: | ||
catalogsource_yaml=yaml.safe_load( file ) | ||
|
||
catalogsource_table.add_row([catalogsourcename, | ||
catalogsource_yaml['spec']['displayName'], | ||
catalogsource_yaml['spec']['publisher'], | ||
catalogsource_yaml['status']['connectionState']['lastObservedState']]) | ||
|
||
|
||
# Create a report summarizing the catalog source status | ||
def summarize(output_dir): | ||
catalogsource_file=output_dir + "/resources/openshift-marketplace/catalogsources.txt" | ||
catalogsource_table=PrettyTable() | ||
catalogsource_table.field_names = [ "Name", "Display Name", "Publisher", "Status" ] | ||
header=True | ||
with open( catalogsource_file ) as file: | ||
for catalogsource in file: | ||
if header == True: | ||
header=False | ||
else: | ||
process_catalogsource( output_dir, catalogsource, catalogsource_table ) | ||
|
||
printHeader("Catalog Sources") | ||
catalogsource_table.align = "l" | ||
print(catalogsource_table) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import yaml | ||
from prettytable import PrettyTable | ||
|
||
from mg.utils import printHeader | ||
|
||
# Create a report summarizing the cluster verison of the cluster | ||
def processClusterVersion(output_dir): | ||
clusterversion_file=output_dir + "/resources/_cluster/clusterversions.txt" | ||
with open(clusterversion_file , 'r') as file: | ||
clusterversion = file.read() | ||
print(clusterversion) | ||
|
||
|
||
# process the node information and show any nodes that have problems | ||
def processNode( output_dir, node, node_table ): | ||
nodename = node.rsplit()[0] | ||
node_yaml_file = output_dir + "/resources/_cluster/nodes/" + nodename + ".yaml" | ||
|
||
with open(node_yaml_file, 'r') as file: | ||
node_yaml=yaml.safe_load( file ) | ||
|
||
# Extract the conditions we are interested in | ||
condition_types=['MemoryPressure', 'DiskPressure', 'PIDPressure', 'Ready'] | ||
condition_statuses= {x['type']:{ | ||
"status": x[ 'status']} for x in node_yaml['status']['conditions'] if x['type'] in condition_types} | ||
condition_statuses | ||
|
||
node_table.add_row([nodename, | ||
node_yaml['status']['capacity']['cpu'], | ||
node_yaml['status']['capacity']['memory'], | ||
condition_statuses['Ready']['status'], | ||
condition_statuses['MemoryPressure']['status'], | ||
condition_statuses['DiskPressure']['status'], | ||
condition_statuses['PIDPressure']['status'] ]) | ||
|
||
def processNodes(output_dir): | ||
nodes_file=output_dir + "/resources/_cluster/nodes.txt" | ||
node_table=PrettyTable() | ||
node_table.field_names = [ "Node", "CPU", "Memory", "Ready" , "Memory Pressure", "Disk Pressure", "PID Pressure" ] | ||
header=True | ||
with open( nodes_file ) as nodes_file: | ||
for node in nodes_file: | ||
if header == True: | ||
header=False | ||
else: | ||
processNode( output_dir, node, node_table ) | ||
|
||
node_table.align = "l" | ||
print( node_table ) | ||
|
||
|
||
def summarize(output_dir): | ||
printHeader("Cluster Information") | ||
processClusterVersion(output_dir) | ||
processNodes(output_dir) |
73 changes: 73 additions & 0 deletions
73
image/cli/mascli/must-gather/summarizer/mg/subscriptions.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import yaml | ||
from prettytable import PrettyTable | ||
|
||
from mg.utils import printHeader | ||
|
||
def process_subscription( output_dir, subscriptionYaml, ipYaml, subscriptions_table ): | ||
# Extract the conditions we are interested in | ||
sub_condition_types=["CatalogSourcesUnhealthy"] | ||
sub_condition_statuses= {x["type"]:{ | ||
"status": x[ "status"]} for x in subscriptionYaml["status"]["conditions"] if x["type"] in sub_condition_types} | ||
|
||
if ipYaml is not None: | ||
ip_status = ipYaml["status"]["phase"] | ||
else: | ||
ip_status="<unknown>" | ||
|
||
if "installPlanApproval" in subscriptionYaml["spec"]: | ||
approval = subscriptionYaml["spec"]["installPlanApproval"] | ||
else: | ||
approval = "<undefined>" | ||
|
||
if "installplan" in subscriptionYaml["status"]: | ||
installPlan = subscriptionYaml["status"]["installplan"]["name"] | ||
else: | ||
installPlan = "<undefined>" | ||
|
||
if "installedCSV" in subscriptionYaml["status"]: | ||
installedCSV = subscriptionYaml["status"]["installedCSV"] | ||
else: | ||
installedCSV = "<undefined>" | ||
|
||
subscriptions_table.add_row([ | ||
subscriptionYaml["metadata"]["namespace"], | ||
subscriptionYaml["metadata"]["name"], | ||
subscriptionYaml["spec"]["channel"], | ||
subscriptionYaml["spec"]["source"], | ||
installedCSV, | ||
approval, | ||
sub_condition_statuses["CatalogSourcesUnhealthy"]["status"], | ||
installPlan, | ||
ip_status | ||
]) | ||
|
||
|
||
def summarize( output_dir): | ||
subsFile = output_dir + "/resources/_cluster/subscriptions/all-namespaces.yaml" | ||
ipsFile = output_dir + "/resources/_cluster/installplans/all-namespaces.yaml" | ||
|
||
with open(subsFile, "r") as file: | ||
subs=yaml.safe_load( file ) | ||
|
||
with open(ipsFile, "r") as file: | ||
ips=yaml.safe_load( file ) | ||
|
||
installPlansByName={} | ||
for ip in ips["items"]: | ||
installPlansByName[ip["metadata"]["name"]]=ip | ||
|
||
subscriptions_table=PrettyTable() | ||
subscriptions_table.field_names = [ "Namespace", "Name", "Channel", "Source", "Installed CSV" ,"Approval", "CS Health", "Install Plan", "Install Phase"] | ||
|
||
for sub in subs["items"]: | ||
if "installplan" in sub["status"] and sub["status"]["installplan"]["name"] in installPlansByName: | ||
ip = installPlansByName[sub["status"]["installplan"]["name"]] | ||
else: | ||
ip = None | ||
process_subscription( output_dir, sub, ip, subscriptions_table ) | ||
|
||
printHeader( "Subscriptions" ) | ||
subscriptions_table.align = "l" | ||
print( subscriptions_table ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/usr/bin/env python3 | ||
|
||
def printHeader(header): | ||
print("") | ||
print(header) | ||
print("====================================================================================================") | ||
print("") |