Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Reference Docs for Charm Configurations #939

Merged
merged 3 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

Check failure on line 4 in docs/src/charm/reference/charm-configurations.md

View workflow job for this annotation

GitHub Actions / markdown-lint

Line length

docs/src/charm/reference/charm-configurations.md:4:81 MD013/line-length Line length [Expected: 80; Actual: 89] https://github.com/DavidAnson/markdownlint/blob/v0.34.0/doc/md013.md
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
mateoflorido marked this conversation as resolved.
Show resolved Hide resolved
[k8s-worker charmhub configurations]: https://charmhub.io/k8s-worker/configurations
mateoflorido marked this conversation as resolved.
Show resolved Hide resolved
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What a nice addition to this PR. Maybe we can also add a check in CI (in the future) to make sure running this script won't cause changes (so that the docs match the charmcraft.yaml file).

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()
Loading