Skip to content

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

Merged
merged 1 commit into from
Apr 11, 2017

Conversation

pecameron
Copy link

@pecameron pecameron commented Feb 17, 2017

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]

@pecameron
Copy link
Author

pecameron commented Feb 17, 2017

@rajatchopra @ramr @JacobTanenbaum @imcsk8
Here is the first pass at describing how to work with templates. PTAL

@pecameron
Copy link
Author

@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!
PTAL if you have the time.

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.
Copy link
Contributor

Choose a reason for hiding this comment

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

HAProxy

Copy link
Author

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.
Copy link
Contributor

Choose a reason for hiding this comment

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

s/config/configuration

Copy link
Author

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:
Copy link
Contributor

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.
Copy link
Contributor

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?

Copy link
Author

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
Copy link
Contributor

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.

Copy link
Author

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}
Copy link
Contributor

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.

Copy link
Author

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
Copy link
Contributor

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

Copy link
Author

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
Copy link
Contributor

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?

Copy link
Author

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.
Copy link
Contributor

Choose a reason for hiding this comment

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

`TEMPLATE_FILE` environment variable

Copy link
Author

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.
Copy link
Contributor

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 ?

Copy link
Author

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
Copy link
Contributor

Choose a reason for hiding this comment

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

changes, it may

Copy link
Author

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.
Copy link
Contributor

Choose a reason for hiding this comment

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

s/config/configuration

Copy link
Author

Choose a reason for hiding this comment

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

fixed

@ahardin-rh
Copy link
Contributor

@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]
Copy link
Contributor

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?

Copy link
Author

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.

Copy link
Author

@pecameron pecameron left a 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.
Copy link
Author

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
Copy link
Author

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.
Copy link
Author

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}
Copy link
Author

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
Copy link
Author

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.
Copy link
Author

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.
Copy link
Author

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
Copy link
Author

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.
Copy link
Author

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]
Copy link
Author

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:

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.

Copy link
Author

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

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?

Copy link

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 ?

Copy link

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

Choose a reason for hiding this comment

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

*nil

Copy link
Author

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.

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 :)

Copy link
Author

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)

Copy link

@ramr ramr left a 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
Copy link

Choose a reason for hiding this comment

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

typo: repository

Copy link
Author

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
Copy link

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
Copy link

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
Copy link

Choose a reason for hiding this comment

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

typo: first

Copy link
Author

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.
|===
Copy link

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?

Copy link
Author

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 */}}

Copy link

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.

Choose a reason for hiding this comment

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

I agree with ramr

Copy link
Author

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.
Copy link

Choose a reason for hiding this comment

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

typo: annotations

Copy link
Author

Choose a reason for hiding this comment

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

fixed

@ramr
Copy link

ramr commented Feb 22, 2017

@pecameron this is great info. 👍

@pecameron
Copy link
Author

@ramr @rajatchopra Thenks for the review. I made the suggested changes. @ahardin-rh PTAL

@pecameron
Copy link
Author

@openshift/team-documentation tech review complete PTAL

@pecameron
Copy link
Author

@ahardin-rh Is this ready to merge?

@ahardin-rh
Copy link
Contributor

ahardin-rh commented Mar 30, 2017

@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.

@bmcelvee bmcelvee modified the milestones: Next Release, Staging Apr 3, 2017
@pecameron
Copy link
Author

@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

@pecameron
Copy link
Author

@ahardin-rh This can go in 3.3, 3.4, 3.5

@ahardin-rh
Copy link
Contributor

Thank you, all!

@ahardin-rh ahardin-rh merged commit 9cbac8e into openshift:master Apr 11, 2017
@ahardin-rh
Copy link
Contributor

[rev_history]
|xref:../architecture/core_concepts/routes.adoc#architecture-core-concepts-routes[Core Concepts -> Routes]
|Updated router customization details.
%
|xref:../install_config/router/customized_haproxy_router.adoc#install-config-router-customized-haproxy[Setting up a Router -> Deploying a Customized HAProxy Router]
|Expanded details in the xref:../install_config/router/customized_haproxy_router.adoc#rebuilding-your-router[Rebuilding Your Router] section.
%

@pecameron pecameron deleted the template branch April 11, 2017 18:33
@vikram-redhat vikram-redhat modified the milestones: Next Release, Staging, Published - 04/12/2017 Apr 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.