-
Notifications
You must be signed in to change notification settings - Fork 908
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
jinja: provide and document jinja-safe key aliases in instance-data (SC-622) #1123
Conversation
fbd3394
to
f6cf805
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good overall! I left mostly minor comments inline with the only major thing being removing the unused parameter.
cloudinit/cmd/query.py
Outdated
break | ||
if walked_key_path: | ||
walked_key_path += "." | ||
walked_key_path += key_path_part |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this section is hard to follow in a function that's already fairly long. It might help to break it down some or maybe even just add some more comments, but I don't think it needs to block merging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
118 line long function... I've done worse, but could do a lot better. breaking this down into a couple of separate functions for readability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll leave the existing comments up to you, but I think this is good as-is.
Without a leading non-integer character jinja's lexer gets confused trying to parse underscore-delimited variable names such as 1_0 as the lexer starts to interpret an integer and chokes on the underscore. This prevents cloud-init from providing a simple jinja dot-notation variable alias such as ds.1_0 because the lexer barfs claiminig invalid variable end "_0". Providing the leading character allows the lexer to interpret the variable as a string type and properly interpret v1_0 as the whole variable text.
Provide additional aliased keys in instance-data.json which have replaced any jinja operator characters in key names with underscores. This provides a simple mechanism for "unsafe" key names to be used in #cloud-config user-data or cloud-init query commands using jinja's dot-notation for dict attributes versus the more verbose square-backet accessor and quoting the unsafe key name. For example: ds.1_0.config.user_data instead of ds["1.0"].config["user-data"]
Accept a include_key_aliases param to convert_jinja_instance_data. When true, add key aliases to the instance-data dict returned. Hide jinja variable aliases from simple cloud-init query --all but Use aliases when rendering jinja template files from query --format command or #cloud-config userdata.
Proposed Commit Message
Additional Context
Test Steps
Checklist: