-
Notifications
You must be signed in to change notification settings - Fork 270
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
improve ordering of options #224
Conversation
This looks interesting and useful IMO! But can you maybe add a comment or two explaining the sort code block for those of us not that well versed in Ruby? I think the existing tests should pretty much cover this, but there should be probably a parameter added to the And I think the haproxy::backend { 'bk_example_app':
options => {
'acl' => 'allowed_networks src 10.1.0.0/16',
'http-request' => 'deny unless allowed_networks',
'server' => [
'app01 app01.backend.example.com:8080 check',
'app02 app02.backend.example.com:8080 check',
]
}
} |
As I have often trouble finding the right amount of explanation here my first try explaining how the sorting is working:
I would add the explanation before the first sort. I have trouble coming up with a name for the option to enable the "new sorting". At the moment I'm going with sort_options_alphabetic. The default would be true and not use the "new sorting". If someone has a better/shorter idea I'm all ears. |
I added, that the option |
I think this looks good! Could you provide an acceptance test similar to one of the existing ones, but pass |
01b572d
to
558955b
Compare
I have added a unit test and an acceptance test. I'm not very happy how the option to enable |
@@ -4,7 +4,9 @@ | |||
# currently, only the Redhat family is supported, but this can be easily | |||
# extended by changing package names and configuration file paths. | |||
# | |||
class haproxy::params { | |||
class haproxy::params ( | |||
$sort_options_alphabetic = true, |
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're talking about putting the parameter here to globally modify it? Yeah, passing parameters to *::params
is not a pattern we use. If we HAVE to have global parameters that apply to all defines, we try to put it in the base class. If that doesn't work for some reason, then we use a *::globals
class (iirc, postgresql and mongodb do this).
But yeah, moving it somewhere else would be nice.
Looks like there is a merge conflict also, so can't be merged currently. Thanks for working on this! |
Ok, I have created the class |
@@ -77,6 +82,8 @@ | |||
$instance_name = "haproxy-${instance}" | |||
$config_file = inline_template($haproxy::params::config_file_tmpl) | |||
} | |||
include haproxy::globals | |||
$_sort_options_alphabetic = pick($sort_options_alphabetic, $haproxy::globals::sort_options_alphabetic) |
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.
Is it impossible to put the sort_options_alphabetic
parameter in the base haproxy
class and follow this pattern as usual, instead of having a haproxy::globals
class? We only use globals when it is otherwise impossible to use the base class.
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.
It is impossible because you can use the haproxy
module without using the haproxy
class, only using haproxy::instance
resources.
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.
Ah right, because the base class declares a default instance.
I'm aware that the ordering of options is relevant for haproxy and there are cases were you have to configure the ordering via an array. But I'm lazy and I want the module to do as much work by itself as is possible and custom sorting will remove a lot of warnings automatically.
I think the change will not break existing haproxy setups because the options are already sorted and the change only reorders the options like haproxy internally does in https://github.com/haproxy/haproxy/blob/master/src/cfgparse.c. But I'm no expert so I can be mistaken.
I'm willing to improve the change like make it optional per haproxy instance, add tests or any other improvement necessary.