Skip to content
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

Segment labels: Docker #3055

Merged
merged 13 commits into from
Mar 23, 2018
Merged

Segment labels: Docker #3055

merged 13 commits into from
Mar 23, 2018

Conversation

ldez
Copy link
Contributor

@ldez ldez commented Mar 20, 2018

What does this PR do?

"Service labels" become "segment labels".

Full rewrite of the template management in Docker.

  • fix some bugs

Motivation

Homogenization of the providers [part4]:ave a common way to manage segment labels.

Related to #2785

More

  • Added/updated tests
  • Added/updated documentation

Additional Notes

It's the first step, next: Marathon and Rancher.

@ldez ldez added this to the 1.6 milestone Mar 20, 2018
@ldez ldez requested a review from a team as a code owner March 20, 2018 13:21
@ldez ldez changed the title Road labels: Docker Segment labels: Docker Mar 22, 2018
@ldez ldez requested a review from a team as a code owner March 22, 2018 08:46
@ldez ldez force-pushed the refactor/service-labels branch from 575fae0 to 379fcef Compare March 22, 2018 15:14
Copy link
Member

@mmatur mmatur left a comment

Choose a reason for hiding this comment

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

LGTM
Great job @ldez 👏

Copy link
Member

@emilevauge emilevauge left a comment

Choose a reason for hiding this comment

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

Awesome job @ldez
Mostly comments on the doc :)

# For advanced users :)
#
# Optional
# - "1": previous template (must be use only with a old custom template, see "filename")
Copy link
Member

Choose a reason for hiding this comment

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

previous template version (must be used only with a older custom templates, see "filename")

#
# Optional
# - "1": previous template (must be use only with a old custom template, see "filename")
# - "2": current template (must be use to force template version when "filename" is used)
Copy link
Member

Choose a reason for hiding this comment

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

current template version (must be used to force template version when "filename" is used)

@@ -237,70 +255,71 @@ Labels can be used on containers to override default behaviour.
| `traefik.frontend.headers.referrerPolicy=VALUE` | Adds referrer policy header. |
| `traefik.frontend.headers.isDevelopment=false` | This will cause the `AllowedHosts`, `SSLRedirect`, and `STSSeconds`/`STSIncludeSubdomains` options to be ignored during development.<br>When deploying to production, be sure to set this to false. |

### On Service
### On container with multiple ports (segment label)
Copy link
Member

Choose a reason for hiding this comment

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

On containers with multiple ports (segment labels)


Services labels can be used for overriding default behaviour
Segment labels are a way to define more than one (default) port on the same container so you can create different routes to it.
Copy link
Member

Choose a reason for hiding this comment

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

Segment labels are used to define routes to a container exposing multiple ports. A segment is a group of labels that apply to a port exposed by a container. You can define as many segments as ports exposed in a container.


Services labels can be used for overriding default behaviour
Segment labels are a way to define more than one (default) port on the same container so you can create different routes to it.
Segment labels are overriding the default behavior.
Copy link
Member

@emilevauge emilevauge Mar 22, 2018

Choose a reason for hiding this comment

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

Segment labels are overrideing the default behavior.

For applications that expose multiple ports, specific labels can be used to extract one frontend/backend configuration pair per port. Each such pair is called a _service_. The (freely choosable) name of the service is an integral part of the service label name.
For applications that expose multiple ports, specific labels can be used to extract one frontend/backend configuration pair per port.
Each such pair is called a _segment_.
The (freely choosable) name of the segment is an integral part of the segment label name.
Copy link
Member

Choose a reason for hiding this comment

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

The segment labels explanation should be consistent between Docker, Marathon and Rancher documentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For now behavior, between Docker and Marathon on segment labels are not consistent (ex: Docker use container labels as default and not Marathon).

I will update the documentation when I will rewrite the Marathon provider.

ServicesPropertiesRegexp = regexp.MustCompile(`^traefik\.(?P<service_name>.+?)\.(?P<property_name>port|portIndex|weight|protocol|backend|frontend\.(.+))$`)
// SegmentPropertiesRegexp used to extract the name of the segment and the name of the property for this segment
// All properties are under the format traefik.<segment_name>.frontend.*= except the port/portIndex/weight/protocol/backend directly after traefik.<segment_name>.
SegmentPropertiesRegexp = regexp.MustCompile(`^traefik\.(?P<service_name>.+?)\.(?P<property_name>port|portIndex|weight|protocol|backend|frontend\.(.+))$`)
Copy link
Member

Choose a reason for hiding this comment

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

s/service_name/segment_name


// PortRegexp used to extract the port label of the service
// PortRegexp used to extract the port label of the segment
PortRegexp = regexp.MustCompile(`^traefik\.(?P<service_name>.+?)\.port$`)
Copy link
Member

@emilevauge emilevauge Mar 22, 2018

Choose a reason for hiding this comment

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

s/service_name/segment_name

var propertyName string
for i, name := range SegmentPropertiesRegexp.SubexpNames() {
if i != 0 {
if name == "service_name" {
Copy link
Member

Choose a reason for hiding this comment

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

s/service_name/segment_name

Copy link
Member

@emilevauge emilevauge left a comment

Choose a reason for hiding this comment

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

Almost LGTM, I would just add few comments in the code to make it easier to read later

var propertyName string
for i, name := range ServicesPropertiesRegexp.SubexpNames() {
for i, name := range SegmentPropertiesRegexp.SubexpNames() {
Copy link
Member

Choose a reason for hiding this comment

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

I would add a comment here to explain why if i != 0 {

var segmentName string
var propertyName string
for i, name := range SegmentPropertiesRegexp.SubexpNames() {
if i != 0 {
Copy link
Member

Choose a reason for hiding this comment

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

I would add a comment here to explain why if i != 0 {

}

func (s SegmentProperties) mergeDefault() {
if defaultLabels, okDefault := s[""]; okDefault {
Copy link
Member

Choose a reason for hiding this comment

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

A comment here would be welcome

@ldez ldez force-pushed the refactor/service-labels branch from 10a7bfa to a58ec45 Compare March 23, 2018 11:40
Copy link
Member

@juliens juliens left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@emilevauge emilevauge left a comment

Choose a reason for hiding this comment

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

Great job @ldez
Thanks a lot !
LGTM

@traefiker traefiker force-pushed the refactor/service-labels branch from 47432c3 to 8a14d42 Compare March 23, 2018 12:14
@traefiker traefiker merged commit 4802484 into traefik:master Mar 23, 2018
@ldez ldez deleted the refactor/service-labels branch March 23, 2018 12:40
@ldez ldez mentioned this pull request Mar 24, 2018
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants