-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Revise router customization documentation #3779
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
Conversation
@rajatchopra @ramr @JacobTanenbaum @imcsk8 |
@ahardin-rh I am thinking of further revisions to the router docs beyond this. Do you know of any work that is being done on router docs? I would like to coordinate what I do to make things flow easier. I can delay doing anything while the docs team is making changes. Thanks! |
setup to xref:using-stick-tables[use stick-tables] that synchronizes between | ||
peers. The router plug-in provides all the facilities necessary to make this | ||
customization. | ||
The default haproxy router is intended to satisfy the needs of most users. |
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.
HAProxy
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 will change it everywhere.
xref:using-stick-tables[stick-tables] that synchronizes between peers. The | ||
router plug-in provides all the facilities necessary to make this customization. | ||
|
||
The router pod uses a template file to create the needed HAProxy config file. |
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.
s/config/configuration
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.
OK, went through and fixed them all.
endif::[] | ||
ifdef::openshift-origin[] | ||
# docker run --rm --interactive=true --tty --entrypoint=cat \ | ||
openshift/origin-haproxy-router haproxy-config.template | ||
endif::[] | ||
---- | ||
|
||
Where the image name is from "docker images" | ||
or by running this on master referencing the router pod: |
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.
master, referencing
The default haproxy router is intended to satisfy the needs of most users. | ||
However, it does not expose all of the capability of HAProxy and users | ||
may need to modify the router for their own needs. Here is how to go | ||
about customizing the router. |
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 we remove this last line (Here is how...) and perhaps rename this section to be Customizing the Router?
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.
Deleted the last sentence. The whole section is how to do this.
may need to modify the router for their own needs. Here is how to go | ||
about customizing the router. | ||
|
||
One common need might be implementing new features within the |
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 may need to implement new features within the application back-ends, or modify the current operation.
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.
Changed. Nice wording.
The router pod uses a template file to create the needed HAProxy config file. | ||
The template file is a | ||
link:http://golang.org/pkg/text/template/[*golang* template]. | ||
When processing the template the router has access to {product-title} |
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.
template, the router has access to {product-title} information, including the router's deployment configuration, the set of admitted routes, and some helper functions.
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 yes, the missing comma
information including the router's deployment configuration, | ||
the set of admitted routes and some helper functions. | ||
|
||
When the router pod starts and every time it reloads it creates a HAProxy |
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.
reloads, it creates an HAProxy configuration file, and then
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.
Fixed
configuration file. | ||
|
||
A *ConfigMap* can be used to add the new template to the router pod. With | ||
this approach the router deployment configuration is modified mount the |
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.
approach, the router
is modified and mounts?
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 forgot some words here. modified to mount
this approach the router deployment configuration is modified mount the | ||
xref:using-configmap-replace-template[*configMap*] as a volume in the router | ||
pod. The *TEMPLATE_FILE* environment | ||
varuable is set to the full path name of the file in the router pod. |
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.
`TEMPLATE_FILE` environment variable
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 will change all environment variables to this markup VAR
.
configuration *image:* field is updated with the new name. When the cluster is | ||
updated the image needs to be rebuilt and pushed. | ||
|
||
In either case it starts with the template file. |
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.
In either case, the process starts with the template file ?
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.
Changed
|
||
[[obtaining-router-configuration-template]] | ||
== Obtaining the Router Configuration Template | ||
|
||
You can obtain a new *_haproxy-config.template_* file from the latest router | ||
image by running: | ||
The HAProxy template file is fairly large and complex. For some changes it may |
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.
changes, it may
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.
fixed
As the template is processed anything not surrounded by "{{" something "}}" | ||
is directly copied to the config file. Passages that are surrounded by "{{" | ||
something "}}" are evaluated and the resulting text, if any, is copied to the | ||
config file. |
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.
s/config/configuration
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.
fixed
@pecameron Thanks! I started to make a few comments, but I can always follow-up with some edits in a separate PR. @aheslin Do you know of any planned docs work regarding router content? |
=== Go Template Constructs | ||
|
||
The following excerpts are from the | ||
link:https://golang.org/pkg/text/template/[go template] |
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.
@aheslin any thoughts on how we should handle excerpts like this?
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 did copy from the referenced doc, just giving credit and pointing to a more through discussion.
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.
@ahardin-rh
Does this come across clearly? Could you use it to actually customize the router? I can rewrite whatever is needed to improve this.
The default haproxy router is intended to satisfy the needs of most users. | ||
However, it does not expose all of the capability of HAProxy and users | ||
may need to modify the router for their own needs. Here is how to go | ||
about customizing the router. |
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.
Deleted the last sentence. The whole section is how to do this.
may need to modify the router for their own needs. Here is how to go | ||
about customizing the router. | ||
|
||
One common need might be implementing new features within the |
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.
Changed. Nice wording.
xref:using-stick-tables[stick-tables] that synchronizes between peers. The | ||
router plug-in provides all the facilities necessary to make this customization. | ||
|
||
The router pod uses a template file to create the needed HAProxy config file. |
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.
OK, went through and fixed them all.
The router pod uses a template file to create the needed HAProxy config file. | ||
The template file is a | ||
link:http://golang.org/pkg/text/template/[*golang* template]. | ||
When processing the template the router has access to {product-title} |
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 yes, the missing comma
information including the router's deployment configuration, | ||
the set of admitted routes and some helper functions. | ||
|
||
When the router pod starts and every time it reloads it creates a HAProxy |
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.
Fixed
this approach the router deployment configuration is modified mount the | ||
xref:using-configmap-replace-template[*configMap*] as a volume in the router | ||
pod. The *TEMPLATE_FILE* environment | ||
varuable is set to the full path name of the file in the router pod. |
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 will change all environment variables to this markup VAR
.
configuration *image:* field is updated with the new name. When the cluster is | ||
updated the image needs to be rebuilt and pushed. | ||
|
||
In either case it starts with the template file. |
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.
Changed
|
||
[[obtaining-router-configuration-template]] | ||
== Obtaining the Router Configuration Template | ||
|
||
You can obtain a new *_haproxy-config.template_* file from the latest router | ||
image by running: | ||
The HAProxy template file is fairly large and complex. For some changes it may |
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.
fixed
As the template is processed anything not surrounded by "{{" something "}}" | ||
is directly copied to the config file. Passages that are surrounded by "{{" | ||
something "}}" are evaluated and the resulting text, if any, is copied to the | ||
config file. |
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.
fixed
=== Go Template Constructs | ||
|
||
The following excerpts are from the | ||
link:https://golang.org/pkg/text/template/[go template] |
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 did copy from the referenced doc, just giving credit and pointing to a more through discussion.
The HAProxy template file is fairly large and complex. For some changes, it may | ||
be easier to modify the existing template rather than writing a complete | ||
replacement. You can obtain a *_haproxy-config.template_* file from a running | ||
router by logging onto the node that is running the router: |
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 always do a 'oc rsh' to view any files on a running router. Much easier. May want to add that as an on option.
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.
@rajatchopra reversed docker/oc examples.
|
||
---- | ||
ifdef::openshift-enterprise[] | ||
# docker run --rm --interactive=true --tty --entrypoint=cat \ | ||
registry.access.redhat.com/openshift3/ose-haproxy-router:v3.0.2.0 haproxy-config.template | ||
registry.access.redhat.com/openshift3/ose-haproxy-router:v3.5.0.0 haproxy-config.template |
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.
Write $version here instead, maybe?
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.
Yeah, its easier to just get it from a current running pod and use the oc
set. Maybe:
oc rsh <router-pod-name> cat haproxy-config.template > localdir/haproxy-config.template
?
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.
Aah, never mind see that you have it below.
balance $balanceAlgo | ||
{{ end }} | ||
---- | ||
Here when $balanceAlgo is not *nill*, "balance $balanceAlgo" is copied to the |
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.
*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.
Fixed
---- | ||
matchPattern "[1-9][0-9]*(us|ms|s|m|h|d)?" $value | ||
---- | ||
This would accept "5000ms" but not "7y". This results can be used in a test. |
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.
'The results' or 'This result' or 'The result'
- the nitpicker :)
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.
Fixed (love to fix nit picks)
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.
Minor comments - LGTM
|
||
An alternative approach is to modify the *haproxy-template.config* file | ||
and xref:rebuilding-your-router[rebuild] the router image. The new image | ||
is pushed to the the cluster repositiory and the routers deployment |
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.
typo: repository
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.
Fixed
|
||
---- | ||
ifdef::openshift-enterprise[] | ||
# docker run --rm --interactive=true --tty --entrypoint=cat \ | ||
registry.access.redhat.com/openshift3/ose-haproxy-router:v3.0.2.0 haproxy-config.template | ||
registry.access.redhat.com/openshift3/ose-haproxy-router:v3.5.0.0 haproxy-config.template |
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.
Yeah, its easier to just get it from a current running pod and use the oc
set. Maybe:
oc rsh <router-pod-name> cat haproxy-config.template > localdir/haproxy-config.template
?
|
||
---- | ||
ifdef::openshift-enterprise[] | ||
# docker run --rm --interactive=true --tty --entrypoint=cat \ | ||
registry.access.redhat.com/openshift3/ose-haproxy-router:v3.0.2.0 haproxy-config.template | ||
registry.access.redhat.com/openshift3/ose-haproxy-router:v3.5.0.0 haproxy-config.template |
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.
Aah, never mind see that you have it below.
|`*endpointsForAlias*` | returns the list of valid endpoints | ||
|`*env*` | tries to get the named environment variable from the pod if it | ||
can't it returns the second argument. | ||
|`*matchPattern*` | the firt argument is a string that contains the regular |
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.
typo: first
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.
fixed
|`*genCertificateHostName*` | generates host name to use for serving/matching | ||
certificates. First argument is the host name and the second is the wildcard | ||
bolean. | ||
|=== |
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.
Wonder if providing like a function signature out here would be useful - that way the arguments/return types are shown/readable?
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.
genCertificateHostName is only used in writing the "/var/lib/haproxy/conf/cert_config.map" file.
{{ define "/var/lib/haproxy/conf/cert_config.map" }}
{{ $workingDir := .WorkingDir }}
{{ range $idx, $cfg := .State }}
{{ if and (ne $cfg.Host "") (or (eq $cfg.TLSTermination "edge") (eq $cfg.TLSTermination "reencrypt")) }}
{{ $cert := index $cfg.Certificates $cfg.Host }}
{{ if ne $cert.Contents "" }}
{{$workingDir}}/certs/{{$idx}}.pem {{genCertificateHostName $cfg.Host $cfg.IsWildcard}}
{{ end }}
{{ end }}
{{ end }}
{{ end }}{{/* end cert_config map template */}}
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.
No I meant like a golang function signature for all the helper functions ala:
func env(name, defaultValue string) string
func matchPattern(pattern, s string) bool
etc. and add some info re: the function (or just point to the examples you have below) ... might be a good resource for someone who understands golang.
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 agree with ramr
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.
OK, I was concerned that the func strings would be too long and distort the table.
|
||
Route Annotations, *$cfg.Annotations*, is also a map with the annotation | ||
name as the key and the content string as the value. The route can have | ||
as many annotitions as desired and the use is defined by the developer. |
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.
typo: annotations
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.
fixed
@pecameron this is great info. 👍 |
@ramr @rajatchopra Thenks for the review. I made the suggested changes. @ahardin-rh PTAL |
@openshift/team-documentation tech review complete PTAL |
@ahardin-rh Is this ready to merge? |
@pecameron Yes, if I have any other nits, I will follow up in a separate follow-up PR. Can you clarify the time-frame for this? Should this be targeting OCP 3.5, or is it okay to get pulled in now to 3.4 and 3.3? I can adjust my labels/milestone accordingly. |
@knobunc I think the template descriptions can go in 3.4 do you think it can go in 3.3? It has Jake's route annotations. Not sure where they went in. |
@ahardin-rh This can go in 3.3, 3.4, 3.5 |
Thank you, all! |
[rev_history] |
OSE 3.5 (May end up in 3.4, 3.3)
General revision of the router customization doc,
Add section on how to work with the template.
Signed-off-by: Phil Cameron [email protected]