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

Define the required key for most keys from schema.yaml and default the key docker to False #222

Merged
merged 2 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 8 additions & 0 deletions schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ mapping:
# Global configuration of computing nodes.
"images":
type: map
required: true
mapping:
"default":
type: str
Expand Down Expand Up @@ -38,6 +39,7 @@ mapping:
# Resource group definitions.
"deployment":
type: map
required: true
mapping:
"=":
type: map
Expand Down Expand Up @@ -74,17 +76,21 @@ mapping:
- m1.xxlarge
"start":
type: date
required: false
format: "%Y-%m-%d"
"end":
type: date
required: false
format: "%Y-%m-%d"
"group":
type: str
required: true
"image":
type: str
required: false
"volume":
type: map
required: false
'mapping':
"size":
type: int
Expand All @@ -99,6 +105,7 @@ mapping:
type: bool
"cgroups":
type: map
required: false
'mapping':
"mem_limit_policy":
type: str
Expand All @@ -112,3 +119,4 @@ mapping:
min: 1024
"docker":
type: bool
required: false
26 changes: 16 additions & 10 deletions synchronize.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,18 @@ def template_userdata(
rendering the template.
"""
vars_files = frozenset(vars_files)

environment = Environment(
loader=FileSystemLoader(user_data_file.parent),
undefined=StrictUndefined,
)
template = environment.get_template(
user_data_file.name,
)

group_defaults = {
"docker": False,
}
vars_from_files = (
reduce(
lambda x, y: x.update(y),
Expand All @@ -601,19 +613,13 @@ def template_userdata(
else {}
)

environment = Environment(
loader=FileSystemLoader(user_data_file.parent),
undefined=StrictUndefined,
)
template = environment.get_template(
user_data_file.name,
)
variables = {}
for vars_group in (group_defaults, config, group_config, vars_from_files):
variables.update(vars_group)

return template.render(
name=name,
**config,
**group_config,
**vars_from_files,
**variables,
)


Expand Down
2 changes: 2 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1440,6 +1440,7 @@ def test_template_userdata() -> None:
owner: root:root
path: /etc/configuration_file
permissions: "0644"
docker: {{ docker }}
"""
)[1:]

Expand Down Expand Up @@ -1481,6 +1482,7 @@ def test_template_userdata() -> None:
owner: root:root
path: /etc/configuration_file
permissions: "0644"
docker: False
"""
)[1:-1]
assert templated == expected
Expand Down
Loading