-
Notifications
You must be signed in to change notification settings - Fork 522
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
early-boot-config: Simplify conditional compilation and make local_file
available to all platforms
#1576
Conversation
#[cfg(bottlerocket_platform = "aws-dev")] | ||
pub(crate) mod local_file; | ||
mod local_file; |
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'm confused as to why local_file still has the cfg directive, since the PR says "It also makes local_file a common function that all platforms can use" - wouldn't we remove all conditionals on it, and let the data providers / platforms decide whether to call the function?
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.
We could for sure do that, but when compiling variants that don't use the code in the local_file
module, we're going to get "unused" warnings like:
warning: constant is never used: `USER_DATA_FILE`
...
warning: function is never used: `local_file_user_data`
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'm not really sure how we get around it other than hiding the whole module behind a cfg
directive like I've done here... perhaps someone knows a trick I don't know?
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.
You could just silence the warning with #[allow(dead_code)]
on the function that is sometimes unused. (need to look up the correct string there)
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.
Hm - I suppose we could do that but I like it a bit less. Are those really the only two options here? 🤔
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.
This (very good) article suggests the pattern I'm using: putting cfg
directives on module imports to keep the actual code clean and not ignore any valid warnings.
IMHO let's keep the code as is unless we come up with something better.
{ | ||
match local_file_user_data()? { | ||
Some(s) => output.push(s), | ||
None => warn!("No user data found via local file: {}", USER_DATA_FILE), |
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 not having a user data file is the normal case - is it worth a warning-level message?
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 for variants that have the ability to use a local file it's worth having the message so users know that nothing was found there, similar to what we do for other sources.
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.
Can we have it as a info level message? I guess that would mean the message won't go to the console?
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 keep it as warn!
for now to stay consistent with the rest of the program and ensure it outputs to the console as expected.
Previously, `local_file` was an implementor of the `PlatformDataProvider` trait. This was a bit awkward, considering local file is _not_ a platform. It also meant it was a bit awkward to use inside another provider. This change makes `local_file` a function that all platforms can use and makes use of it inside the `aws` module for `aws-dev` variants.
This change uses `cfg` directives inside of `provider.rs` to compile the appropriate `PlatformDataProvider` for the current variant. It re-exports the data provider as `Platform`, meaning that all conditional compilation details are removed from `main.rs` and it can simply use `Platform` instead of a specific platform trait implementor.
73c4c7a
to
02668ce
Compare
^ Rebases on :( Sorry the rebase wasn't pushed separately. |
Issue number:
Fixes #1457
Description of changes:
This change simplifies the conditional compilation by re-exporting the appropriate
PlatformDataProvider
as the common namePlatform
. This allows us to remove all conditional bits frommain
by usingPlatform
when retrieving user data.It also makes
local_file
a common function that all platforms can use, rather than a "platform-like" module in itself. Currently, we only make use of it in theaws-dev
variant.Testing done:
aws-dev
variant with and without a local file to ensure local file is read if it existsaws-k8s-1.19
variant to ensure user data is read properly (and local file isn't attempted).vmware-k8s-1.20
variant to ensure nothing broke there.Terms of contribution:
By submitting this pull request, I agree that this contribution is dual-licensed under the terms of both the Apache License, version 2.0, and the MIT license.