-
Notifications
You must be signed in to change notification settings - Fork 352
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
(CODEMGMT-1415) SPIKE assume modules unchanged locally #1145
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
require 'puppet_forge' | ||
|
||
class R10K::MockModule | ||
|
||
# @!attribute [r] title | ||
# @return [String] The forward slash separated owner and name of the module | ||
attr_reader :title | ||
|
||
# @!attribute [r] name | ||
# @return [String] The name of the module | ||
attr_reader :name | ||
|
||
# @param [r] dirname | ||
# @return [String] The name of the directory containing this module | ||
attr_reader :dirname | ||
|
||
# @!attribute [r] owner | ||
# @return [String, nil] The owner of the module if one is specified | ||
attr_reader :owner | ||
|
||
# @!attribute [r] path | ||
# @return [Pathname] The full path of the module | ||
attr_reader :path | ||
|
||
# @!attribute [r] version | ||
# @return [Pathname] The version, if it can be statically determined from args | ||
attr_reader :version | ||
|
||
# @param title [String] | ||
# @param dirname [String] | ||
# @param args [Array] | ||
def initialize(title, dirname, args, environment=nil) | ||
@title = PuppetForge::V3.normalize_name(title) | ||
@dirname = dirname | ||
@owner, @name = parse_title(@title) | ||
@path = Pathname.new(File.join(@dirname, @name)) | ||
@version = find_version(args) | ||
end | ||
|
||
private | ||
|
||
def find_version(args) | ||
if args.is_a?(String) | ||
args | ||
elsif args.is_a?(Hash) | ||
if args[:type] == 'forge' | ||
args[:version] | ||
elsif args[:ref] && args[:ref].match(/[0-9a-f]{40}/) | ||
args[:ref] | ||
elsif args[:type] == 'git' && args[:version].match(/[0-9a-f]{40}/) | ||
args[:version] | ||
else | ||
args[:tag] || args[:commit] | ||
end | ||
end | ||
end | ||
|
||
def parse_title(title) | ||
if (match = title.match(/\A(\w+)\Z/)) | ||
[nil, match[1]] | ||
elsif (match = title.match(/\A(\w+)[-\/](\w+)\Z/)) | ||
[match[1], match[2]] | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,11 @@ class Puppetfile | |
# @return [String] The path to the Puppetfile | ||
attr_reader :puppetfile_path | ||
|
||
# @!attrbute [rw] previous_version | ||
# @return [R10K::StubPuppetfile] A simplified version of this Puppetfile | ||
# available on disk prior to the environment sync | ||
attr_accessor :previous_version | ||
|
||
# @!attribute [rw] environment | ||
# @return [R10K::Environment] Optional R10K::Environment that this Puppetfile belongs to. | ||
attr_accessor :environment | ||
|
@@ -130,6 +135,19 @@ def add_module(name, args) | |
args[:default_branch_override] = @default_branch_override | ||
end | ||
|
||
no_change = false | ||
if @previous_version | ||
stub_module = R10K::MockModule.new(name, install_path, args) | ||
logger.debug2 _("Checking previous Puppetfile for version %{version} of %{name}" % { version: stub_module.version, name: stub_module.name }) | ||
if stub_module.version == @previous_version.modules[stub_module.name].version | ||
logger.debug _("Expected version has not changed between this and previous deployment, skipping %{name}" % { name: stub_module.name }) | ||
# The version in this Puppetfile is the same as the version previous | ||
# specified in the Puppetfile (or we cannot be sure the versions | ||
# specified are static, eg a branch specifier). | ||
no_change = true | ||
end | ||
end | ||
|
||
mod = R10K::Module.new(name, install_path, args, @environment) | ||
mod.origin = :puppetfile | ||
|
||
|
@@ -144,7 +162,9 @@ def add_module(name, args) | |
@managed_content[install_path] = Array.new unless @managed_content.has_key?(install_path) | ||
@managed_content[install_path] << mod.name | ||
|
||
@modules << mod | ||
# We want to manage the content (and not purge it) even if we do not want | ||
# to sync modules that we assume unchanged. | ||
no_change ? @modules : @modules << mod | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I worry about focusing effort on the Puppetfile, when I see the future direction being more "modules attached to an environment", with the Puppetfile being kind of a legacy way to attach them. Is it possible to take something like this approach instead?
That approach would also preserve the ability to "see" all modules attached to an environment, regardless of what you're planning on doing to/with them. Again, mostly I'm just worried about embedding important logic in the Puppetfile specifically, given that the Puppetfile is only one way to define environment content. At some point a general encapsulation/cleanup of how environments and modules relate would be nice, but in the meantime I think not implementing new stuff as Puppetfile-specific would be a good idea. |
||
end | ||
|
||
include R10K::Util::Purgeable | ||
|
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.
Do we need all these fields? Is there some hidden contract that requires them?
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 need the version and name in the current implementation (which requires the title). I thought we might need the path but I don't think so. This file was just a copy and pared down version of the module base class.