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

(wip) some patches to get things working with puppet-unbound #1

Open
wants to merge 2 commits into
base: add-hiera-overrides
Choose a base branch
from

Conversation

b4ldr
Copy link

@b4ldr b4ldr commented Apr 28, 2021

ill probably continue working on this but just in case it slips my mind i thought id send the fixes i already needed to apply

It is possible to explode the Hiera overrides and generate a table in
the reference.
@b4ldr
Copy link
Author

b4ldr commented Apr 28, 2021

I made som progress on parsing the common.yaml file or should i say files wit no interpolation tokens see here

def load_config
return unless File.exist?(config_path)

config = YAML.load(File.read(config_path))

unless config['version'] == 5
raise "Unsupported version '#{config['version']}'"
log.warn("Unsupported version '#{config['version']}'")
return
Copy link
Author

Choose a reason for hiding this comment

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

i think this achieves "Graceful fallback if legacy Hiera data is used" although see the todo above, currently we load the config for every instance

Copy link
Owner

@ekohl ekohl left a comment

Choose a reason for hiding this comment

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

Interesting idea to override the default. I didn't really think of that. I do think we should do that at another level then. This is just the markdown implementation, but that means HTML and JSON don't benefit from it. I initially wrote code mostly just so I could demonstrate it could be done in the reference, but it's really not the right thing.

lib/puppet-strings/hiera/data.rb Outdated Show resolved Hide resolved
lib/puppet-strings/hiera/data.rb Outdated Show resolved Hide resolved
lib/puppet-strings/hiera/data.rb Outdated Show resolved Hide resolved
regex.match(entry) do |match|
full_path = File.join(datadir, entry)
interpolations = {}
regex.match(entry) do |match|
Copy link
Owner

Choose a reason for hiding this comment

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

I had the chdir there so the globbed paths were relative to datadir rather than absolute. This reduced the risk of any oddities with the regex here caused by the unused part.

Copy link
Author

Choose a reason for hiding this comment

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

hmm im not sure thats the best idea. 1) im not convinced there is a problem to solve (do you have some examples, even contrived ones) 2) if there is a problem at best we are just reducing the risk of triggering it by using chdir

Copy link
Owner

Choose a reason for hiding this comment

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

The alternative is to normalize it again. For example (using pathname):

data_dir = Pathname.new(datadir)
data_dir.glob('**').each do |entry|
  next unless x.file?

  regex.match(entry.relative_path_from(data_dir)) do |match|
    # ...
  end
end

Note that I also chose to glob everything so that we don't have to think about extensions (yaml vs yml). The regex matching will take care of that.

@@ -82,7 +82,7 @@ Options:
Default value: `<%= value_string(defaults[param[:name]]) %>`

<% end -%>
<% if hiera_overrides[param[:name]] -%>
<% if !hiera_overrides.empty? && hiera_overrides[param[:name]] -%>
Copy link
Owner

Choose a reason for hiding this comment

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

I didn't have the empty check because in Ruby a missing key in a hash returns nil so it wouldn't be triggered. I think this change is redundant.

Copy link
Author

@b4ldr b4ldr Apr 29, 2021

Choose a reason for hiding this comment

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

hiera_overrides by default returns [] and defined as @return [Array[Tuple[String, Hash[String, String], Any]]] not sure if this is by design or not but i got a stack trace when it was empty: unable to cast string to int (or something like that)

@b4ldr
Copy link
Author

b4ldr commented Apr 29, 2021

responded to most things inline, in general im pretty sure i agree with you. however from a practical point of view. im not familiar with yard or puppet-strings, and even ruby its self is one of my weaker languages. So when it comes to moving things to "the correct place" i definitely agree but at the same time. I took a quick look and couldn't work out where the correct place would be. If you have pointers that would be great if not i could maybe ping the initial thread?

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.

2 participants