Created
June 15, 2017 02:40
-
-
Save so0k/256cde434cbb0b58702249b31203a357 to your computer and use it in GitHub Desktop.
Print Helm's Values.yaml
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
import yaml | |
print_format="| {parameter:<40}| | {default:<50}|" | |
def walk_dict(d,keys=[],depth=0): | |
for k,v in sorted(d.items(),key=lambda x: x[0]): | |
keys.append(k) | |
if isinstance(v,dict): | |
walk_dict(v,keys,depth+1) | |
else: | |
print(print_format.format(parameter='`{0}`'.format(".".join(keys)),default='`{0}`'.format(v))) | |
keys.pop() | |
s = open("./values.yaml") | |
d = yaml.load(s) | |
walk_dict(d) |
to walk over variables.tf
and output.tf
:
#!/usr/bin/env python
import hcl
print_var_format="|`{parameter:<25}`|`{default:<20}`|{description:<80}|{required:<8}|"
print_out_format="|`{parameter:<25}`|{description:<80}|"
var_header="|{name:^27}|{default:^22}|{description:^80}|{required:^8}|\n|{a:-<27}|{a:-<22}|{a:-<80}|{a:-<8}|".format(
name="Name",
default="Default",
description="Description",
required="Required",
a=":"
)
out_header="|{name:<27}|{description:<80}|\n|{a:-<27}|{a:-<80}|".format(
name="Name",
description="Description",
a=":"
)
with open('variables.tf', 'r') as fp:
d = hcl.load(fp)
var = d.get("variable")
if var != None:
print("## Variables\n")
print(var_header)
for k,v in sorted(var.items(),key=lambda x:x[0]):
required = v.get('default') == None
if not required and isinstance(v.get('default'),dict):
for x,y in v['default'].items():
s = print_var_format.format(
parameter=k+"."+x,
default=y,
description=v.get('description')+" "+x,
required= "No"
)
print(s)
else:
s = print_var_format.format(
parameter=k,
default=v.get('default'),
description=v.get('description'),
required= "Yes" if required else "No"
)
print(s)
print("\n")
out = d.get("output")
if out != None:
print("## Outputs\n")
print(out_header)
for k,v in sorted(out.items(),key=lambda x:x[0]):
s = print_out_format.format(
parameter=k,
description=v.get('description')
)
print(s)
print("\n")
Sample variables.tf
variable "test" {
description = "Config map"
default = {
foo = "bar"
baz = "qux"
}
}
Result:
| Name | Default | Description |Required|
|:--------------------------|:---------------------|:-------------------------------------------------------------------------------|:-------|
|`test.foo `|`bar `|Config map foo |No |
|`test.baz `|`qux `|Config map baz |No |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample of resulting table - https://github.com/honestbee/public-charts/tree/portus/stable/portus#chart-details