ECS provider refactoring

This commit is contained in:
Michael 2017-09-06 12:10:05 +02:00 committed by Traefiker
parent b0a0e16136
commit 9ce4f94818
4 changed files with 420 additions and 183 deletions

View file

@ -409,7 +409,7 @@ func (p *Provider) lookupTaskDefinitions(ctx context.Context, client *awsClient,
return taskDefinitions, nil
}
func (i ecsInstance) label(k string) string {
func (p *Provider) label(i ecsInstance, k string) string {
if v, found := i.containerDefinition.DockerLabels[k]; found {
return *v
}
@ -439,7 +439,7 @@ func (p *Provider) filterInstance(i ecsInstance) bool {
return false
}
label := i.label(types.LabelEnable)
label := p.label(i, types.LabelEnable)
enabled := p.ExposedByDefault && label != "false" || label == "true"
if !enabled {
log.Debugf("Filtering disabled ecs instance %s (%s) (traefik.enabled = '%s')", i.Name, i.ID, label)
@ -463,7 +463,7 @@ func (p *Provider) filterFrontends(instances []ecsInstance) []ecsInstance {
}
func (p *Provider) getFrontendRule(i ecsInstance) string {
if label := i.label(types.LabelFrontendRule); label != "" {
if label := p.label(i, types.LabelFrontendRule); label != "" {
return label
}
return "Host:" + strings.ToLower(strings.Replace(i.Name, "_", "-", -1)) + "." + p.Domain
@ -471,7 +471,7 @@ func (p *Provider) getFrontendRule(i ecsInstance) string {
func (p *Provider) getLoadBalancerSticky(instances []ecsInstance) string {
if len(instances) > 0 {
label := instances[0].label(types.LabelBackendLoadbalancerSticky)
label := p.label(instances[0], types.LabelBackendLoadbalancerSticky)
if label != "" {
return label
}
@ -481,7 +481,7 @@ func (p *Provider) getLoadBalancerSticky(instances []ecsInstance) string {
func (p *Provider) getLoadBalancerMethod(instances []ecsInstance) string {
if len(instances) > 0 {
label := instances[0].label(types.LabelBackendLoadbalancerMethod)
label := p.label(instances[0], types.LabelBackendLoadbalancerMethod)
if label != "" {
return label
}
@ -505,44 +505,44 @@ func (p *Provider) chunkedTaskArns(tasks []*string) [][]*string {
return chunkedTasks
}
func (i ecsInstance) Protocol() string {
if label := i.label(types.LabelProtocol); label != "" {
func (p *Provider) getProtocol(i ecsInstance) string {
if label := p.label(i, types.LabelProtocol); label != "" {
return label
}
return "http"
}
func (i ecsInstance) Host() string {
func (p *Provider) getHost(i ecsInstance) string {
return *i.machine.PrivateIpAddress
}
func (i ecsInstance) Port() string {
func (p *Provider) getPort(i ecsInstance) string {
return strconv.FormatInt(*i.container.NetworkBindings[0].HostPort, 10)
}
func (i ecsInstance) Weight() string {
if label := i.label(types.LabelWeight); label != "" {
func (p *Provider) getWeight(i ecsInstance) string {
if label := p.label(i, types.LabelWeight); label != "" {
return label
}
return "0"
}
func (i ecsInstance) PassHostHeader() string {
if label := i.label(types.LabelFrontendPassHostHeader); label != "" {
func (p *Provider) getPassHostHeader(i ecsInstance) string {
if label := p.label(i, types.LabelFrontendPassHostHeader); label != "" {
return label
}
return "true"
}
func (i ecsInstance) Priority() string {
if label := i.label(types.LabelFrontendPriority); label != "" {
func (p *Provider) getPriority(i ecsInstance) string {
if label := p.label(i, types.LabelFrontendPriority); label != "" {
return label
}
return "0"
}
func (i ecsInstance) EntryPoints() []string {
if label := i.label(types.LabelFrontendEntryPoints); label != "" {
func (p *Provider) getEntryPoints(i ecsInstance) []string {
if label := p.label(i, types.LabelFrontendEntryPoints); label != "" {
return strings.Split(label, ",")
}
return []string{}