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

(PDK-1093) Replace null values and empty data structures in metadata when converting #584

Merged
merged 3 commits into from
Oct 31, 2018

Conversation

rodjek
Copy link
Contributor

@rodjek rodjek commented Oct 29, 2018

Currently when we're updating a module's metadata.json file during
convert, we only replace values if they are completely absent from the
file. Unfortunately, this means if - for example - the existing metadata
defines dependencies as null or an empty array then it will not be
updated when the module is converted and it will subsequently fail to
validate cleanly.

This PR changes the metadata merging logic so that values defined as
null will be replaced with the default metadata value. Additionally, if the requirements array exists but is empty, it will also be updated with the default value.

@coveralls
Copy link

coveralls commented Oct 29, 2018

Coverage Status

Coverage increased (+0.005%) to 92.939% when pulling eb07915 on rodjek:pdk-1093 into f1688e9 on puppetlabs:master.

begin
metadata = PDK::Module::Metadata.from_file(metadata_path)
new_values = PDK::Module::Metadata::DEFAULTS.select do |key, _|
!metadata.data.key?(key) || metadata.data[key].nil? ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. This PR makes me think about how we handle operatingsystem_support. Currently.. if the key doesn't exist, we put the defaults in, which may be inaccurate. But if the key does exist and is empty, we leave it alone. With this PR, in both of the cases, we will update the metadata with the default operating system support, which might be undesirable.

This is out of scope of this PR, but IMO, I think we need to remove operating system support from the defaults, and only check the key (and prompt user to select OS) if --full-interview is specified or if they are doing a pdk build and we detect the key is missing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'm 👍 to replacing values that are null but I think replacing empty arrays with the defaults could be more problematic.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough, but we'll have to add an exception for requirements as PDK will fail to validate as it expects to find a puppet version requirement.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we just have a pre-condition somewhere that bails out if requirements is an empty array?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so. If the requirements array exists and is empty, it is a pretty harmless change to add a puppet requirement and saves the user from having to make a manual change (either removing the array which would then be re-added with the default value anyway during convert, or manually creating the puppet requirement).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that sounds reasonable!

…when converting

Currently when we're updating a module's `metadata.json` file during
convert, we only replace values if they are completely absent from the
file. Unfortunately, this means if - for example - the existing metadata
defines `dependencies` as `null` or an empty array then it will not be
updated when the module is converted and it will subsequently fail to
validate cleanly.

This PR changes the metadata merging logic so that values defined as
`null`, empty array, or empty hash are considered to be undefined and
will be replaced with the default metadata value.
@bmjen bmjen merged commit 3527c5c into puppetlabs:master Oct 31, 2018
@rodjek rodjek deleted the pdk-1093 branch November 1, 2018 05:35
@bmjen bmjen added the bug label Nov 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants