Skip to content

Commit eedf38c

Browse files
committed
Amend k8s_test.py, fix CM report view
Signed-off-by: Matthias Büchse <matthias.buechse@alasca.cloud>
1 parent 9cb016e commit eedf38c

4 files changed

Lines changed: 25 additions & 23 deletions

File tree

Tests/kaas/k8s_test.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
HERE = os.path.dirname(__file__)
2525
SCS_SONOBUOY_CONFIG_PATH = os.path.join(HERE, 'scs-sonobuoy-config-v1.yaml')
26+
KUBECONFIG_ROOT = os.path.join(os.path.expanduser('~'), '.local', 'share', 'scs', 'clusters')
2627

2728
logger = logging.getLogger(__name__)
2829

@@ -31,35 +32,35 @@ def usage(rcode=1, file=sys.stderr):
3132
"""help output"""
3233
print("Usage: k8s_test.py [options] testcase-id1 ... testcase-idN", file=file)
3334
print("Options:", file=file)
34-
print(" [-k/--kubeconfig KUBECONFIG_PATH] (required)", file=file)
35+
print(" [-c/--cluster-id CLUSTER_ID] (required)", file=file)
3536
print(" [-s/--subject SUBJECT]", file=file)
3637
print(" [--execution-mode MODE] Sonobuoy mode: serial, parallel, or dry", file=file)
37-
print("Runs specified testcases against the default context in kubeconfig provided", file=file)
38-
print("via -k. Reports inconsistencies, errors etc.; returns 0 on success.", file=file)
38+
print("Runs specified testcases against the kubeconfig specified via cluster_id.", file=file)
39+
print("Reports inconsistencies, errors etc.; returns 0 on success.", file=file)
3940
print("Instead of listing testcase-ids, you can supply a single dash (-)", file=file)
4041
print("to have them read from stdin, one testcase-id per line.", file=file)
4142
sys.exit(rcode)
4243

4344

4445
class Config:
4546
def __init__(self):
46-
self.kubeconfig_path = os.environ.get("KUBECONFIG")
47+
self.cluster_id = None
4748
self.subject = None
4849
self.mode = 'serial'
4950
self.testcases = []
5051

5152
def apply_argv(self, argv):
5253
"""Parse cli arguments from the script call"""
5354
try:
54-
opts, args = getopt.gnu_getopt(argv, "k:s:", ("kubeconfig=", "subject=", "execution-mode="))
55+
opts, args = getopt.gnu_getopt(argv, "c:s:", ("cluster-id=", "subject=", "execution-mode="))
5556
except getopt.GetoptError as exc:
5657
print(f"CRITICAL: {exc!r}", file=sys.stderr)
5758
usage(1)
5859
for opt in opts:
5960
if opt[0] == "-h" or opt[0] == "--help":
6061
usage(0)
61-
elif opt[0] == "-k" or opt[0] == "--kubeconfig":
62-
self.kubeconfig_path = opt[1]
62+
elif opt[0] == "-c" or opt[0] == "--cluster-id":
63+
self.cluster_id = opt[1]
6364
elif opt[0] == "-s" or opt[0] == "--subject":
6465
self.subject = opt[1]
6566
elif opt[0] == "--execution-mode":
@@ -72,11 +73,15 @@ def apply_argv(self, argv):
7273
if len(self.testcases) != len(args):
7374
unknown = [a for a in args if a not in self.testcases]
7475
logger.warning(f"ignoring unknown testcases: {','.join(unknown)}")
75-
if not self.kubeconfig_path:
76+
if not self.cluster_id:
7677
print("CRITICAL: You need to have KUBECONFIG set or pass --kubeconfig=KUBECONFIG.", file=sys.stderr)
7778
sys.exit(1)
7879
if not self.subject:
79-
self.subject = self.kubeconfig_path
80+
self.subject = self.cluster_id
81+
82+
@property
83+
def kubeconfig_path(self):
84+
return os.path.join(KUBECONFIG_ROOT, self.cluster_id, 'kubeconfig.yaml')
8085

8186
def compute_sono_args(self, *args):
8287
if self.mode == 'parallel':

Tests/kaas/plugin/run_plugin.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@
1717
"kind": PluginKind,
1818
"static": PluginStatic,
1919
}
20-
BASEPATH = os.path.join(os.path.expanduser('~'), '.config', 'scs')
20+
CONFIG_PATH = os.path.join(os.path.expanduser('~'), '.config', 'scs')
21+
STATE_PATH = os.path.join(os.path.expanduser('~'), '.local', 'share', 'scs')
2122

2223

2324
def load_config(path='clusters.yaml'):
2425
if not os.path.isabs(path):
25-
return load_config(os.path.normpath(os.path.join(BASEPATH, path)))
26+
return load_config(os.path.normpath(os.path.join(CONFIG_PATH, path)))
2627
if not os.path.exists(path):
2728
raise FileNotFoundError()
2829
with open(path, "rb") as fileobj:
@@ -34,12 +35,14 @@ def load_config(path='clusters.yaml'):
3435
return cfg
3536

3637

37-
def init_plugin(plugin_kind, config, cwd='.'):
38+
def init_plugin(plugin_kind, config, cluster_id):
3839
plugin_maker = PLUGIN_LOOKUP.get(plugin_kind)
3940
if plugin_maker is None:
4041
raise ValueError(f"unknown plugin '{plugin_kind}'")
42+
config.setdefault('name', cluster_id)
43+
cwd = os.path.join(STATE_PATH, 'clusters', cluster_id)
4144
os.makedirs(cwd, exist_ok=True)
42-
return plugin_maker(config, basepath=BASEPATH, cwd=cwd)
45+
return plugin_maker(config, basepath=CONFIG_PATH, cwd=cwd)
4346

4447

4548
@click.group()
@@ -53,21 +56,15 @@ def cli(debug=False):
5356
@click.pass_obj
5457
def create(cfg, cluster_id):
5558
spec = cfg['clusters'][cluster_id]
56-
config = spec['config']
57-
config.setdefault('name', cluster_id)
58-
cwd = os.path.abspath(cluster_id)
59-
init_plugin(spec['kind'], config, cwd).create_cluster()
59+
init_plugin(spec['kind'], spec['config'], cluster_id).create_cluster()
6060

6161

6262
@cli.command()
6363
@click.argument('cluster_id', type=str, default="default")
6464
@click.pass_obj
6565
def delete(cfg, cluster_id):
6666
spec = cfg['clusters'][cluster_id]
67-
config = spec['config']
68-
config.setdefault('name', cluster_id)
69-
cwd = os.path.abspath(cluster_id)
70-
init_plugin(spec['kind'], config, cwd).delete_cluster()
67+
init_plugin(spec['kind'], spec['config'], cluster_id).delete_cluster()
7168

7269

7370
if __name__ == '__main__':

compliance-monitor/templates/overview.html.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
html {text-rendering:optimizelegibility;font-family:system-ui,-apple-system,Segoe UI,Roboto,Ubuntu,Cantarell,Noto Sans,sans-serif,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol";}
1313
li {margin:0.33em 0;}
1414
#log + ul {padding-left:0;}
15-
#log + ul > li {margin:0;display:block;text-indent:1em hanging;}
15+
#log + ul > li {margin:0 0 0.3em 0;line-height:1em;display:block;text-indent:1em hanging;}
1616
#log + ul > li strong em {background-color:yellow;font-style:normal;}
1717
</style>
1818
{% if title %}<h1>{{title}}</h1>

compliance-monitor/templates/report.md.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ else %}{% set uuid = report.uuid %}{% set scopeuuid = report.scope %}{% endif -%
2222
- {% if line.split(':', 1)[0].lower() in ('warning', 'error', 'critical') %}**_`{{line}}`_**{%
2323
elif line.startswith('INFO: *** ') %}{% if 'PASS' in line %} `{{line}}` {% else %} **`{{line}}`** {% endif %}
2424
{: #{{line.split()[2]}} }{%
25-
else %}`{{line}}`{% endif %}
25+
else %}{% for line0 in line.splitlines() %}`{{line0}}`{%if not loop.last%}<br>{%endif%}{% endfor %}{% endif %}
2626
{%- endfor %}
2727

2828
{% endif %}

0 commit comments

Comments
 (0)