-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: values.schema.json to support air-gapped environments (#141)
Signed-off-by: Tomas Coufal <tcoufal@redhat.com>
- Loading branch information
Showing
7 changed files
with
5,733 additions
and
645 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 |
---|---|---|
|
@@ -21,3 +21,5 @@ | |
.idea/ | ||
*.tmproj | ||
.vscode/ | ||
|
||
values.schema.tmpl.json |
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
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,34 @@ | ||
import json | ||
from typing import List, Dict, Any | ||
from pathlib import Path | ||
|
||
import jsonref | ||
|
||
JSONSCHEMA_TEMPLATE_NAME = "values.schema.tmpl.json" | ||
JSONSCHEMA_NAME = "values.schema.json" | ||
CHART_LOCK = "Chart.lock" | ||
|
||
def load_template_schema(chart_dir: Path) -> Dict[str, Any]: | ||
"""Load values.schema.tmpl.json and template it via Jinja2.""" | ||
with open(chart_dir / JSONSCHEMA_TEMPLATE_NAME, "r") as f: | ||
return json.loads(f.read()) | ||
|
||
def save(chart_dir: Path, schema: Any): | ||
"""Take schema containing $refs and dereference them.""" | ||
with open(chart_dir / JSONSCHEMA_NAME, "w") as f: | ||
json.dump(schema, f, indent=4, sort_keys=True) | ||
|
||
if __name__ == '__main__': | ||
charts = [p.parent for p in Path(".").rglob(CHART_LOCK)] | ||
|
||
errors: List[BaseException] = [] | ||
for chart in charts: | ||
try: | ||
schema_template = load_template_schema(chart) | ||
schema = jsonref.replace_refs(schema_template) | ||
save(chart, schema) | ||
except BaseException as e: | ||
print(f"Could not process schema for '{chart}': {e}") | ||
errors.append(e) | ||
if errors: | ||
exit(1) |
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
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
Oops, something went wrong.