-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Reference Docs for Charm Configurations (#939)
* Add Reference for charm configurations
- Loading branch information
1 parent
909229d
commit 12e32f0
Showing
3 changed files
with
95 additions
and
0 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 |
---|---|---|
@@ -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 |
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 |
---|---|---|
|
@@ -15,6 +15,7 @@ releases | |
charms | ||
proxy | ||
architecture | ||
charm-configurations | ||
Community <community> | ||
``` | ||
|
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,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() |