-
Notifications
You must be signed in to change notification settings - Fork 38
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
HAProxy: Extend configuration options #193
HAProxy: Extend configuration options #193
Conversation
attribute :address, kind_of: String, default: "0.0.0.0" | ||
attribute :port, kind_of: Integer, default: 0 | ||
attribute :mode, kind_of: String, default: "http", equal_to: ["http", "tcp", "health"] | ||
attribute :balance, kind_of: String, default: "", equal_to: ["", "roundrobin", "static-rr", "leastconn", "first", "source"] |
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.
Metrics/LineLength: Line is too long. [132/100] (https://github.com/SUSE/style-guides/blob/master/Ruby.md#metricslinelength)
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.
Same here.
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.
Done
attribute :options, kind_of: Array, default: [] | ||
attribute :servers, kind_of: Array, default: [] | ||
attribute :name, kind_of: String, name_attribute: true | ||
attribute :type, kind_of: String, default: "listen", equal_to: ["listen", "backend", "frontend"] |
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.
Metrics/LineLength: Line is too long. [108/100] (https://github.com/SUSE/style-guides/blob/master/Ruby.md#metricslinelength)
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.
Any chance you could break the equal_to: ...
onto a continuation line?
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.
Done, but hound complain now about Style/ExtraSpacing: Unnecessary spacing detected. in next line...
#193 (comment)
raise "One of the servers has no name." if server["name"].nil? | ||
raise "Server #{server["name"]} has no address." if server["address"].nil? | ||
raise "Server #{server["name"]} has no port." if server["port"].nil? | ||
raise "Server #{server["name"]} has invalid port." if server["port"] < 1 || server["port"] > 65535 |
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.
Metrics/LineLength: Line is too long. [104/100] (https://github.com/SUSE/style-guides/blob/master/Ruby.md#metricslinelength)
Sorry about previous PR |
@matrixik No problem :) I'm missing context so I could be completely wrong, but you might find this blog post useful? |
e60e449
to
83002e4
Compare
unless new_resource.default_backend.empty? | ||
section["default_backend"] = new_resource.default_backend | ||
end | ||
unless new_resource.servers.empty? |
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.
Style/IfUnlessModifier: Favor modifier unless usage when having a single-line body. Another good alternative is the usage of control flow &&/||. (https://github.com/bbatsov/ruby-style-guide#if-as-a-modifier)
section["use_ssl"] = new_resource.use_ssl | ||
if new_resource.use_ssl | ||
section["mode"] = "tcp" | ||
else | ||
section["mode"] = new_resource.mode | ||
end | ||
unless new_resource.balance.empty? |
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.
Style/IfUnlessModifier: Favor modifier unless usage when having a single-line body. Another good alternative is the usage of control flow &&/||. (https://github.com/bbatsov/ruby-style-guide#if-as-a-modifier)
unless new_resource.address.empty? | ||
section["address"] = new_resource.address | ||
end | ||
unless new_resource.port == 0 |
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.
Style/IfUnlessModifier: Favor modifier unless usage when having a single-line body. Another good alternative is the usage of control flow &&/||. (https://github.com/bbatsov/ruby-style-guide#if-as-a-modifier)
Style/NumericPredicate: Use new_resource.port.zero? instead of new_resource.port == 0. (https://github.com/bbatsov/ruby-style-guide#predicate-methods)
end | ||
|
||
section = {} | ||
section["address"] = new_resource.address | ||
section["port"] = new_resource.port | ||
unless new_resource.address.empty? |
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.
Style/IfUnlessModifier: Favor modifier unless usage when having a single-line body. Another good alternative is the usage of control flow &&/||. (https://github.com/bbatsov/ruby-style-guide#if-as-a-modifier)
raise "One of the servers has no name." if server["name"].nil? | ||
raise "Server #{server['name']} has no address." if server["address"].nil? | ||
raise "Server #{server['name']} has no port." if server["port"].nil? | ||
raise "Server #{server['name']} has invalid port." if (server["port"] < 1 || server["port"] > 65535) |
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.
Style/StringLiteralsInInterpolation: Prefer double-quoted strings inside interpolations. (https://github.com/SUSE/style-guides/blob/master/Ruby.md#stylestringliteralsininterpolation)
Style/ParenthesesAroundCondition: Don't use parentheses around the condition of an if. (https://github.com/bbatsov/ruby-style-guide#no-parens-around-condition)
Metrics/LineLength: Line is too long. [106/100] (https://github.com/SUSE/style-guides/blob/master/Ruby.md#metricslinelength)
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.
I disagree with Hound CI regarding Style/StringLiteralsInInterpolation
, but I agree regarding Style/ParenthesesAroundCondition
and Metrics/LineLength
.
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.
Should I change back and allow hound to complain about Style/StringLiteralsInInterpolation? Rest done.
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.
I don't think you need to change back :-) Thanks!
new_resource.servers.each do |server| | ||
raise "One of the servers has no name." if server["name"].nil? | ||
raise "Server #{server['name']} has no address." if server["address"].nil? | ||
raise "Server #{server['name']} has no port." if server["port"].nil? |
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.
Style/StringLiteralsInInterpolation: Prefer double-quoted strings inside interpolations. (https://github.com/SUSE/style-guides/blob/master/Ruby.md#stylestringliteralsininterpolation)
else | ||
new_resource.servers.each do |server| | ||
raise "One of the servers has no name." if server["name"].nil? | ||
raise "Server #{server['name']} has no address." if server["address"].nil? |
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.
Style/StringLiteralsInInterpolation: Prefer double-quoted strings inside interpolations. (https://github.com/SUSE/style-guides/blob/master/Ruby.md#stylestringliteralsininterpolation)
raise "Server #{server['name']} has no address." if server["address"].nil? | ||
raise "Server #{server['name']} has no port." if server["port"].nil? | ||
raise "Server #{server['name']} has invalid port." if (server["port"] < 1 || server["port"] > 65535) | ||
if new_resource.type != "frontend" |
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.
Style/IfUnlessModifier: Favor modifier if usage when having a single-line body. Another good alternative is the usage of control flow &&/||. (https://github.com/bbatsov/ruby-style-guide#if-as-a-modifier)
@@ -23,30 +23,42 @@ | |||
# While there is no way to have an include directive for haproxy | |||
# configuration file, this provider will only modify attributes ! | |||
|
|||
if new_resource.port < 1 || new_resource.port > 65535 | |||
raise "Invalid port: #{new_resource.port}." | |||
if ! new_resource.port == 0 && new_resource.type == "backend" |
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.
Style/NumericPredicate: Use ! new_resource.port.zero? instead of ! new_resource.port == 0. (https://github.com/bbatsov/ruby-style-guide#predicate-methods)
Style/SpaceAfterNot: Do not leave space between ! and its argument. (https://github.com/bbatsov/ruby-style-guide#no-space-bang)
b2c5a7e
to
46dde2e
Compare
9b14da3
to
a9d0618
Compare
a9d0618
to
bc4402e
Compare
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.
Looks OK modulo the Hound CI style warnings.
attribute :options, kind_of: Array, default: [] | ||
attribute :servers, kind_of: Array, default: [] | ||
attribute :name, kind_of: String, name_attribute: true | ||
attribute :type, kind_of: String, default: "listen", equal_to: ["listen", "backend", "frontend"] |
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.
Any chance you could break the equal_to: ...
onto a continuation line?
attribute :address, kind_of: String, default: "0.0.0.0" | ||
attribute :port, kind_of: Integer, default: 0 | ||
attribute :mode, kind_of: String, default: "http", equal_to: ["http", "tcp", "health"] | ||
attribute :balance, kind_of: String, default: "", equal_to: ["", "roundrobin", "static-rr", "leastconn", "first", "source"] |
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.
Same here.
raise "One of the servers has no name." if server["name"].nil? | ||
raise "Server #{server['name']} has no address." if server["address"].nil? | ||
raise "Server #{server['name']} has no port." if server["port"].nil? | ||
raise "Server #{server['name']} has invalid port." if (server["port"] < 1 || server["port"] > 65535) |
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.
I disagree with Hound CI regarding Style/StringLiteralsInInterpolation
, but I agree regarding Style/ParenthesesAroundCondition
and Metrics/LineLength
.
attribute :mode, kind_of: String, default: "http", equal_to: [ | ||
"http", "tcp", "health" | ||
] | ||
attribute :balance, kind_of: String, default: "", equal_to: [ |
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.
Style/ExtraSpacing: Unnecessary spacing detected.
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.
Thanks, I can't see anything obviously wrong with the aggregate changes now. It's a bit hard for me to give a confident +1 however, as I don't know the context surrounding the PR. Normally I would get this from the PR description and the commit messages, but the functionality changes are split across several commits and there is no PR description explaining all the changes. In particular I'm a bit confused why some checks are introduced and then removed again in a later commit. Maybe someone else who knows more about the context can +1.
It was long time ago and I'm not sure who suggested me to remove this checks. I think they was removed because they are already checked/handled in |
I also wanted to have separate commits for each functionality but I can squash all if you want. |
attribute :mode, kind_of: String, default: "http", equal_to: [ | ||
"http", "tcp", "health" | ||
] | ||
attribute :balance, kind_of: String, default: "", equal_to: [ |
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.
Layout/ExtraSpacing: Unnecessary spacing detected.
@aspiers Squashed and rebased. |
Some high level context on why we need this: we configure Monasca using the ansible based |
@jgrassler Thanks a lot, that's really helpful. In the future please just add this kind of context to the PR description :-) It's hard to find it when it's buried in a stream of comments. (On this occasion I've just copied your info to the description.) |
Now it's possible to configure separately frontend and backend and hide many different services with one frontend based on access path. E.g. `/write` can go to writable backend and `/read` could go only to read-only backend. Add `acl`, `use_backend` and `default_backend` to configurable attributes. Does not require server for frontend and does not require bind configuration, frontent services does not need to bind to any address when they are only used for backend services.
Rebased. |
I no longer actively work on this so closing. |
We configure Monasca using the ansible-based
monasca-installer
, which is run from Crowbar. This means that the Monasca API services we want to put behindhaproxy
are not directly under Crowbar's aegis. To put them behind Crowbar-managedhaproxy
instances we need these new options.