Skip to content

Revise router template functions #5068

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

Merged
merged 1 commit into from
Aug 3, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions install_config/router/customized_haproxy_router.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -115,21 +115,24 @@ The *define* action names the file that will contain the processed template.
[cols="2*", options="header"]
|===
|Function | Meaning
|`*endpointsForAlias(alias ServiceAliasConfig, svc ServiceUnit) []Endpoint*` | Returns the list of valid endpoints.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is endpointsForAlias considered deprecated now?

Copy link
Author

Choose a reason for hiding this comment

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

I don't know. It is not currently used.

|`*env(variable, default string) string*` | Tries to get the named environment variable from the pod. Returns the second
argument if the variable cannot be read or is empty.
|`*processEndpointsForAlias(alias ServiceAliasConfig, svc ServiceUnit, action string) []Endpoint*` |
Returns the list of valid endpoints. When action is "shuffle", the order of endpoints is randomized.
|`*env(variable, default ...string) string*` | Tries to get the named environment variable from the pod.

Choose a reason for hiding this comment

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

Here should be *env(variable string, defaults ...string) string*

Copy link
Author

Choose a reason for hiding this comment

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

changed

If it is not defined or empty, it returns the optional second argument. Otherwise, it returns an empty string.
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think of this? "If the value is empty or not defined and one or more optional arguments are provided, env returns the first non-empty argument. Otherwise, it returns an empty string."

Copy link
Author

Choose a reason for hiding this comment

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

@Miciah In practice there are 0 or 1 optional values. The environment variable either has a default or it doesn't.

Copy link
Contributor

Choose a reason for hiding this comment

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

@pecameron, ah, if we want to avoid documenting (and committing to) allowing more than 2 parameters, that's fine. Never mind!

|`*matchPattern(pattern, s string) bool*` | The first argument is a string that contains the regular
expression, the second argument is the variable to test. Returns a Boolean value indicating whether the regular
expression provided as the first argument matches the string provided as the second argument.
expression, the second argument is the variable to test. Returns a Boolean value indicating whether
the regular expression provided as the first argument matches the string provided as the second argument.
|`*isInteger(s string) bool*` | Determines if a given variable is an integer.
|`*matchValues(s string, allowedValues ...string) bool*` | Compares a given string to a list of allowed strings.
|`*genSubdomainWildcardRegexp(hostname, path string, exactPath bool) string*` | Generates a regular expression matching the
subdomain for hosts (and paths) with a wildcard policy.
|`*generateRouteRegexp(hostname, path string, wildcard bool) string*` | Generates a regular expression matching the route
hosts (and paths). The first argument is the host name, the second is the path,
|`*firstMatch(s string, allowedValues ...string) bool*` | Compares a given string to a list of allowed

Choose a reason for hiding this comment

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

The first argument of firstMatch is a regular expression.

Copy link
Author

Choose a reason for hiding this comment

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

changed

strings. Returns first match scanning left to right through the list.
|`*matchValues(s string, allowedValues ...string) bool*` | Compares a given string to a list of allowed
strings. Returns "true" if the string is an allowed value, otherwise returns false.
|`*generateRouteRegexp(hostname, path string, wildcard bool) string*` | Generates a regular expression
matching the route hosts (and paths). The first argument is the host name, the second is the path,
and the third is a wildcard Boolean.
|`*genCertificateHostName(hostname string, wildcard bool) string*` | Generates host name to use for serving/matching
certificates. First argument is the host name and the second is the wildcard Boolean.
|`*genCertificateHostName(hostname string, wildcard bool) string*` | Generates host name to use for
serving/matching certificates. First argument is the host name and the second is the wildcard Boolean.
|`*isTrue(s string) bool*` | Determines if a given variable contains "true".
|===

These functions are provided by the HAProxy template router plug-in.
Expand Down