Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
WIP on making SF labels match docker provider
Browse files Browse the repository at this point in the history
  • Loading branch information
lawrencegripper committed Dec 15, 2017
1 parent 5fcc062 commit f8b299d
Show file tree
Hide file tree
Showing 5 changed files with 252 additions and 87 deletions.
4 changes: 2 additions & 2 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 26 additions & 2 deletions labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,38 @@ func getFuncBoolLabel(labelName string, defaultValue bool) func(service ServiceI
}
}

func getFuncServiceStringLabel(service ServiceItemExtended, labelName string, defaultValue string) string {
func getServiceStringLabel(service ServiceItemExtended, labelName string, defaultValue string) string {
return label.GetStringValue(service.Labels, labelName, defaultValue)
}

func hasFuncService(service ServiceItemExtended, labelName string) bool {
func getFuncServiceStringLabel(labelName string, defaultValue string) func(service ServiceItemExtended) string {
return func(service ServiceItemExtended) string {
return label.GetStringValue(service.Labels, labelName, defaultValue)
}
}

func hasService(service ServiceItemExtended, labelName string) bool {
return label.Has(service.Labels, labelName)
}

func hasFuncService(labelName string) func(service ServiceItemExtended) bool {
return func(service ServiceItemExtended) bool {
return label.Has(service.Labels, labelName)
}
}

func getFuncServiceSliceStringLabel(labelName string) func(service ServiceItemExtended) []string {
return func(service ServiceItemExtended) []string {
return label.GetSliceStringValue(service.Labels, labelName)
}
}

func getFuncServiceMapLabel(labelName string) func(service ServiceItemExtended) map[string]string {
return func(service ServiceItemExtended) map[string]string {
return label.GetMapValue(service.Labels, labelName)
}
}

func getServiceLabelsWithPrefix(service ServiceItemExtended, prefix string) map[string]string {
results := make(map[string]string)
for k, v := range service.Labels {
Expand Down
13 changes: 10 additions & 3 deletions servicefabric.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/containous/traefik/job"
"github.com/containous/traefik/log"
"github.com/containous/traefik/provider"
"github.com/containous/traefik/provider/label"
"github.com/containous/traefik/safe"
"github.com/containous/traefik/types"
sf "github.com/jjcollinge/servicefabric"
Expand Down Expand Up @@ -96,17 +97,23 @@ func (p *Provider) updateConfig(configurationChan chan<- types.ConfigMessage, po
func (p *Provider) buildConfiguration(sfClient sfClient) (*types.Configuration, error) {
var sfFuncMap = template.FuncMap{
"getServices": getServices,
"hasLabel": hasFuncService,
"getLabelValue": getFuncServiceStringLabel,
"hasLabel": hasService,
"getLabelValue": getServiceStringLabel,
"getLabelsWithPrefix": getServiceLabelsWithPrefix,
"isPrimary": isPrimary,
"isExposed": getFuncBoolLabel("expose", false),
"isEnabled": getFuncBoolLabel(label.SuffixEnable, false),
"getBackendName": getBackendName,
"getDefaultEndpoint": getDefaultEndpoint,
"getNamedEndpoint": getNamedEndpoint, // FIXME unused
"getApplicationParameter": getApplicationParameter, // FIXME unused
"doesAppParamContain": doesAppParamContain, // FIXME unused
"filterServicesByLabelValue": filterServicesByLabelValue, // FIXME unused

"getPassTLSCert": getFuncBoolLabel(label.SuffixFrontendPassTLSCert, false),
"hasRequestHeaders": hasFuncService(label.SuffixFrontendRequestHeaders),
"getRequestHeaders": getFuncServiceMapLabel(label.SuffixFrontendRequestHeaders),
"hasFrameDenyHeaders": hasFuncService(label.SuffixFrontendHeadersFrameDeny),
"getFrameDenyHeaders": getFuncBoolLabel(label.SuffixFrontendHeadersFrameDeny, false),
}

services, err := getClusterServices(sfClient)
Expand Down
Loading

0 comments on commit f8b299d

Please sign in to comment.