Skip to content

Commit

Permalink
Add Reference Docs for Charm Configurations (#939)
Browse files Browse the repository at this point in the history
* Add Reference for charm configurations
  • Loading branch information
mateoflorido authored Jan 9, 2025
1 parent 909229d commit 12e32f0
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 0 deletions.
24 changes: 24 additions & 0 deletions docs/src/charm/reference/charm-configurations.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Charm configuration options reference

This reference section provides the sites where you can find the configuration
options for the `k8s` and `k8s-worker` charms. These options can be set at
various points during the charm's lifecycle. Some options are limited to the
bootstrap process, while others can be modified at any time. Options restricted
to bootstrap are explicitly noted in their descriptions and prefixed with
`bootstrap-`.

## Configuration options for `k8s` charm

The configuration options for the `k8s` charm are available on the
Charmhub configurations [page][k8s charmhub configurations].

## Configuration options for `k8s-worker` charm

The configuration options for the `k8s-worker` charm are available on the
Charmhub configurations [page][k8s-worker charmhub configurations].


<!-- LINKS -->

[k8s charmhub configurations]: https://charmhub.io/k8s/configurations
[k8s-worker charmhub configurations]: https://charmhub.io/k8s-worker/configurations
1 change: 1 addition & 0 deletions docs/src/charm/reference/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ releases
charms
proxy
architecture
charm-configurations
Community <community>
```
Expand Down
70 changes: 70 additions & 0 deletions docs/tools/generate_charms_reference.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
from typing import Dict
import yaml
import argparse
from pathlib import Path

def parse_yaml_content(yaml_file):
with open(yaml_file, "r") as f:
try:
data: Dict = yaml.safe_load(f)
config = data.get("config", {})
return config.get("options")
except yaml.YAMLError as e:
print(f"Error parsing YAML file {yaml_file}: {e}")
return {}

def generate_markdown(config_data, output_file):
with open(output_file, "w") as f:
for key, values in sorted(config_data.items()):
f.write(f"### {key}\n")
if "type" in values:
f.write(f"**Type:** `{values["type"]}`\n")
if "default" in values and values['default']:
f.write(f"**Default Value:** `{values["default"]}`\n")
f.write("\n")
if "description" in values and values['description']:
description = values["description"].strip()
f.write(f"{description}\n")
f.write("\n")

def parse_arguments():
parser = argparse.ArgumentParser(
description="Generate markdown documentation from charmcraft YAML files."
)
parser.add_argument(
"input_files",
nargs="+",
type=str,
help="One or more charmcraft YAML files to process"
)
parser.add_argument(
"--output-dir",
"-o",
type=str,
default=".",
help="Directory where markdown files will be generated (default: current directory)"
)
return parser.parse_args()

def main():
args = parse_arguments()

output_dir = Path(args.output_dir)
output_dir.mkdir(parents=True, exist_ok=True)

for yaml_file in args.input_files:
yaml_path = Path(yaml_file)
if not yaml_path.exists():
print(f"Error: File {yaml_file} not found")
continue

output_file = output_dir / f"{yaml_path.stem}.md"
config_data = parse_yaml_content(yaml_file)
if config_data:
generate_markdown(config_data, output_file)
print(f"Generated documentation for {yaml_file} charm in {output_file}")
else:
print(f"No config section found in {yaml_file}")

if __name__ == "__main__":
main()

0 comments on commit 12e32f0

Please sign in to comment.