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

Standard module options #1131

Merged
merged 4 commits into from
Mar 15, 2021
Merged

Conversation

reidmv
Copy link
Contributor

@reidmv reidmv commented Mar 4, 2021

This PR is primarily designed to sanitize the schema used by the Hash source type to define environments and modules, adopting a standard way of describing content (environments, modules) which is not implementation-dependent, the way today's modules especially are.

The idea is that when specifying content in a data hash, it should be possible to specify it using these standard keys.

---
object-name:
  type: <string> # E.g. "git", "forge", "svn"
  source: <string> # E.g. "git://server.tld/project/repo.git", "https://forge.puppet.com", etc.
  version: <string> # E.g. "main", "06a32bc", "6.1.0", etc.

This PR assumes #1130 exists to improve the visibility of what happens if users use conflicting ways of specifying values like version, such as by using both version and an implementation-specific key like git, but does not depend on that improvement.

This PR homogenizes how options are parsed for many objects by standardizing on the use of R10K::Util::Setopts.

See the rich diff of the doc/dynamic-environments/configuration.mkd page for the best visual of what this change accomplishes for consumers.

This improvement takes a UX step in the direction of r10k being able to support other types of environment sources and module sources, such as e.g. tarballs from Artifactory or S3.

This PR should be backwards compatible, without behavior changes, with one exception. Some object types did not validate schema in any way for keys passed into them. R10K::Util::Setopts does validate schema, and so garbage keys that would have been ignored previously may now cause an error.

@reidmv reidmv requested a review from a team March 4, 2021 18:34
@reidmv reidmv force-pushed the standard-module-options branch 2 times, most recently from 779a1a8 to 7555154 Compare March 4, 2021 19:06
@justinstoller
Copy link
Member

Overall, I really like it.

However, I'm also really concerned about there being garbage in folks repository definitions. I haven't looked far enough into it to know if that concern is valid though.

@reidmv reidmv force-pushed the standard-module-options branch from 7555154 to 9bbcd5f Compare March 9, 2021 22:43
@reidmv
Copy link
Contributor Author

reidmv commented Mar 9, 2021

@binford2k can you take a look at this and @justinstoller's comment, let me know what you think?

For now I'll whip up a commit permitting and warning on garbage parameters.

@binford2k
Copy link
Contributor

@reidmv is there a pressing reason to disallow garbage parameters? Warn/permit seems like a reasonable non-breaking solution, with the expectation that next major release would make it invalid.

@reidmv
Copy link
Contributor Author

reidmv commented Mar 11, 2021

@binford2k @justinstoller I've added some commits that permit R10K::Util::Setopts to warn on unhandled options instead of raising, and R10K::Environment::Git now makes use of that. It looks to me like that was the only object, actually, that wasn't already validating input options somehow. In any case though, it's now possible to permit unhandled options when necessary to preserve behavior.

@justinstoller
Copy link
Member

@mwaggett had mentioned in the pre-req PR that we should be updating the changelog as we go - we should do that here. Did you want to also review this PR @mwaggett ?

@mwaggett
Copy link
Contributor

mwaggett commented Mar 11, 2021

yes, this should also include a changelog update (and add one for the other PR while you're at it, please 😊 ).

I was planning to review this eventually, but don't wait on me if you think it's already received sufficient review.

@reidmv reidmv force-pushed the standard-module-options branch 2 times, most recently from 9e90783 to 606cbd5 Compare March 11, 2021 21:27
@reidmv
Copy link
Contributor Author

reidmv commented Mar 11, 2021

New commit pushed with additional docs updates, changelog additions

@mwaggett mwaggett self-requested a review March 12, 2021 22:10
doc/puppetfile.mkd Outdated Show resolved Hide resolved
lib/r10k/environment/base.rb Outdated Show resolved Hide resolved
lib/r10k/environment/git.rb Show resolved Hide resolved
lib/r10k/environment/git.rb Show resolved Hide resolved
lib/r10k/module/forge.rb Show resolved Hide resolved
lib/r10k/module/svn.rb Show resolved Hide resolved
spec/unit/module_spec.rb Outdated Show resolved Hide resolved
spec/unit/module_spec.rb Show resolved Hide resolved
spec/unit/module/forge_spec.rb Show resolved Hide resolved
spec/unit/module/forge_spec.rb Outdated Show resolved Hide resolved
doc/puppetfile.mkd Outdated Show resolved Hide resolved
lib/r10k/environment/svn.rb Outdated Show resolved Hide resolved
spec/unit/module/forge_spec.rb Show resolved Hide resolved
@mwaggett
Copy link
Contributor

Anything you wanna squash @reidmv ? I take it this probably shouldn't all be a single commit, but there are pieces that could be squashed.

@reidmv
Copy link
Contributor Author

reidmv commented Mar 13, 2021

Yeah, lemme clean it up a bit. Just a moment.

Let setopts explicity ignore some arguments, and give it the ability to
warn on options that don't match the schema, instead of raising. This is
to enable using setopts in places where we need to preserve backwards
compatibility with a less clearly defined, more permissive interface.
@reidmv reidmv force-pushed the standard-module-options branch from 029560c to d873f13 Compare March 13, 2021 00:43
@reidmv
Copy link
Contributor Author

reidmv commented Mar 13, 2021

Rebased into something resembling a clean history. There is one final cleanup change mixed in here as well. It relates to how :puppetfile_name is handled. Some tests added to help verify that passing options managed in base classes (such as :puppetfile_name) all works correctly.

Copy link
Contributor

@mwaggett mwaggett left a comment

Choose a reason for hiding this comment

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

Not sure if you wanted to squash in the various pieces of that last improvements commit, but otherwise looks good!

@justinstoller did you want to take another look?

reidmv and others added 3 commits March 14, 2021 14:09
Allow modules of any currently supported type to be initialized using
the following standard specification:

  ---
  <module-name>:
    type: <type>
    source: <source>
    version: <version>

This is in slight contrast to today's expectations, which are largely
based on the presence of a type-specific key to indicate the kind of
module to create, and there are no standard parameters to indicate
source and version.

By providing a standard schema for defining modules of any type, this
paves the way for easier integration with external data systems which
may define sets of modules of many types to include in different
environments.

This schema is generalized away from implementation and towards the
concepts that matter to the user.
And make it obvious which options are part of the standard interface.

Clean up :puppetfile_name handling

The pattern appears to be, call super first. The base class initialize
method saves off the original, unmodified options to @Args. Base classes
then delete options they process. The outer class uses setopts to
process the remainder.
Add standard interface updates to docs, changelog

Co-authored-by: Molly Waggett <mwaggett@alumni.reed.edu>
@reidmv reidmv force-pushed the standard-module-options branch from d873f13 to a70e301 Compare March 14, 2021 21:10
@reidmv
Copy link
Contributor Author

reidmv commented Mar 14, 2021

Alright, totally squashed, ended with four total commits: 1 for setopts enhancements, 1 for module interface additions, 1 for environment interface additions, and a separate commit for docs updates.

@mwaggett mwaggett merged commit 93d38cb into puppetlabs:master Mar 15, 2021
@reidmv reidmv deleted the standard-module-options branch March 17, 2021 19:24
tvpartytonight added a commit to tvpartytonight/r10k that referenced this pull request Mar 23, 2021
The PR puppetlabs#1131 changed the order of method calls in the Forge initialization;
that ended up breaking scenarios where the opts was not a Hash and the
else branch in the logic called `current_version`, which needs the
@metadata object defined before it can be successfully called. This change
just simply restores the previous ordering.
tvpartytonight added a commit to tvpartytonight/r10k that referenced this pull request Mar 23, 2021
The PR puppetlabs#1131 changed the order of method calls in the Forge initialization;
that ended up breaking scenarios where the opts was not a Hash and the
else branch in the logic called `current_version`, which needs the
@metadata object defined before it can be successfully called. This change
moves that instantiation up to happen before that `current_version` could
be called.
tvpartytonight added a commit to tvpartytonight/r10k that referenced this pull request Mar 23, 2021
The PR puppetlabs#1131 changed the order of method calls in the Forge initialization;
that ended up breaking scenarios where the opts was not a Hash and the
else branch in the logic called `current_version`, which needs the
@metadata object defined before it can be successfully called. This change
moves that instantiation up to happen before that `current_version` could
be called.
tvpartytonight added a commit to tvpartytonight/r10k that referenced this pull request Mar 25, 2021
The PR puppetlabs#1131 changed the order of method calls in the Forge initialization;
that ended up breaking scenarios where the opts was not a Hash and the
else branch in the logic called `current_version`, which needs the
@metadata object defined before it can be successfully called. This change
moves that instantiation up to happen before that `current_version` could
be called.
tvpartytonight added a commit to tvpartytonight/r10k that referenced this pull request Mar 25, 2021
The PR puppetlabs#1131 changed the order of method calls in the Forge initialization;
that ended up breaking scenarios where the opts was not a Hash and the
else branch in the logic called `current_version`, which needs the
@metadata object defined before it can be successfully called. This change
moves that instantiation up to happen before that `current_version` could
be called.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants