fix: backend name for stateful service and more.
This commit is contained in:
parent
89c3930b28
commit
1f3fc8a366
5 changed files with 81 additions and 70 deletions
7
Gopkg.lock
generated
7
Gopkg.lock
generated
|
@ -263,8 +263,8 @@
|
||||||
[[projects]]
|
[[projects]]
|
||||||
name = "github.com/containous/traefik-extra-service-fabric"
|
name = "github.com/containous/traefik-extra-service-fabric"
|
||||||
packages = ["."]
|
packages = ["."]
|
||||||
revision = "503022efdc178146d598911092af75690510a80c"
|
revision = "7366770ee1d09b828d58e08b78898e2e39448328"
|
||||||
version = "v1.1.3"
|
version = "v1.1.4"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
name = "github.com/coreos/bbolt"
|
name = "github.com/coreos/bbolt"
|
||||||
|
@ -761,7 +761,6 @@
|
||||||
version = "v1.3.7"
|
version = "v1.3.7"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "master"
|
|
||||||
name = "github.com/jjcollinge/servicefabric"
|
name = "github.com/jjcollinge/servicefabric"
|
||||||
packages = ["."]
|
packages = ["."]
|
||||||
revision = "8eebe170fa1ba25d3dfb928b3f86a7313b13b9fe"
|
revision = "8eebe170fa1ba25d3dfb928b3f86a7313b13b9fe"
|
||||||
|
@ -1675,6 +1674,6 @@
|
||||||
[solve-meta]
|
[solve-meta]
|
||||||
analyzer-name = "dep"
|
analyzer-name = "dep"
|
||||||
analyzer-version = 1
|
analyzer-version = 1
|
||||||
inputs-digest = "c441208e9bf330e85e2939b383515f58a4957286960b43c444e6f512d1ff94ee"
|
inputs-digest = "ffd938a3cb26d3d0926b34a98708af0a3db49311e03edc91649ea1baad1b97e9"
|
||||||
solver-name = "gps-cdcl"
|
solver-name = "gps-cdcl"
|
||||||
solver-version = 1
|
solver-version = 1
|
||||||
|
|
|
@ -66,7 +66,7 @@
|
||||||
|
|
||||||
[[constraint]]
|
[[constraint]]
|
||||||
name = "github.com/containous/traefik-extra-service-fabric"
|
name = "github.com/containous/traefik-extra-service-fabric"
|
||||||
version = "1.1.3"
|
version = "1.1.4"
|
||||||
|
|
||||||
[[constraint]]
|
[[constraint]]
|
||||||
name = "github.com/coreos/go-systemd"
|
name = "github.com/coreos/go-systemd"
|
||||||
|
|
72
vendor/github.com/containous/traefik-extra-service-fabric/servicefabric.go
generated
vendored
72
vendor/github.com/containous/traefik-extra-service-fabric/servicefabric.go
generated
vendored
|
@ -1,7 +1,10 @@
|
||||||
package servicefabric
|
package servicefabric
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/cenk/backoff"
|
"github.com/cenk/backoff"
|
||||||
|
@ -18,6 +21,11 @@ var _ provider.Provider = (*Provider)(nil)
|
||||||
|
|
||||||
const traefikServiceFabricExtensionKey = "Traefik"
|
const traefikServiceFabricExtensionKey = "Traefik"
|
||||||
|
|
||||||
|
const (
|
||||||
|
kindStateful = "Stateful"
|
||||||
|
kindStateless = "Stateless"
|
||||||
|
)
|
||||||
|
|
||||||
// Provider holds for configuration for the provider
|
// Provider holds for configuration for the provider
|
||||||
type Provider struct {
|
type Provider struct {
|
||||||
provider.BaseProvider `mapstructure:",squash"`
|
provider.BaseProvider `mapstructure:",squash"`
|
||||||
|
@ -66,7 +74,7 @@ func (p *Provider) updateConfig(configurationChan chan<- types.ConfigMessage, po
|
||||||
log.Info("Checking service fabric config")
|
log.Info("Checking service fabric config")
|
||||||
}
|
}
|
||||||
|
|
||||||
configuration, err := p.buildConfiguration(sfClient)
|
configuration, err := p.getConfiguration(sfClient)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -90,6 +98,15 @@ func (p *Provider) updateConfig(configurationChan chan<- types.ConfigMessage, po
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *Provider) getConfiguration(sfClient sfClient) (*types.Configuration, error) {
|
||||||
|
services, err := getClusterServices(sfClient)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return p.buildConfiguration(services)
|
||||||
|
}
|
||||||
|
|
||||||
func getClusterServices(sfClient sfClient) ([]ServiceItemExtended, error) {
|
func getClusterServices(sfClient sfClient) ([]ServiceItemExtended, error) {
|
||||||
apps, err := sfClient.GetApplications()
|
apps, err := sfClient.GetApplications()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -171,11 +188,6 @@ func getValidInstances(sfClient sfClient, app sf.ApplicationItem, service sf.Ser
|
||||||
return validInstances
|
return validInstances
|
||||||
}
|
}
|
||||||
|
|
||||||
func isPrimary(instance replicaInstance) bool {
|
|
||||||
_, data := instance.GetReplicaData()
|
|
||||||
return data.ReplicaRole == "Primary"
|
|
||||||
}
|
|
||||||
|
|
||||||
func isHealthy(instanceData *sf.ReplicaItemBase) bool {
|
func isHealthy(instanceData *sf.ReplicaItemBase) bool {
|
||||||
return instanceData != nil && (instanceData.ReplicaStatus == "Ready" && instanceData.HealthState != "Error")
|
return instanceData != nil && (instanceData.ReplicaStatus == "Ready" && instanceData.HealthState != "Error")
|
||||||
}
|
}
|
||||||
|
@ -185,6 +197,54 @@ func hasHTTPEndpoint(instanceData *sf.ReplicaItemBase) bool {
|
||||||
return err == nil
|
return err == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getReplicaDefaultEndpoint(replicaData *sf.ReplicaItemBase) (string, error) {
|
||||||
|
endpoints, err := decodeEndpointData(replicaData.Address)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
var defaultHTTPEndpoint string
|
||||||
|
for _, v := range endpoints {
|
||||||
|
if strings.Contains(v, "http") {
|
||||||
|
defaultHTTPEndpoint = v
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(defaultHTTPEndpoint) == 0 {
|
||||||
|
return "", errors.New("no default endpoint found")
|
||||||
|
}
|
||||||
|
return defaultHTTPEndpoint, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func decodeEndpointData(endpointData string) (map[string]string, error) {
|
||||||
|
var endpointsMap map[string]map[string]string
|
||||||
|
|
||||||
|
if endpointData == "" {
|
||||||
|
return nil, errors.New("endpoint data is empty")
|
||||||
|
}
|
||||||
|
|
||||||
|
err := json.Unmarshal([]byte(endpointData), &endpointsMap)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
endpoints, endpointsExist := endpointsMap["Endpoints"]
|
||||||
|
if !endpointsExist {
|
||||||
|
return nil, errors.New("endpoint doesn't exist in endpoint data")
|
||||||
|
}
|
||||||
|
|
||||||
|
return endpoints, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func isStateful(service ServiceItemExtended) bool {
|
||||||
|
return service.ServiceKind == kindStateful
|
||||||
|
}
|
||||||
|
|
||||||
|
func isStateless(service ServiceItemExtended) bool {
|
||||||
|
return service.ServiceKind == kindStateless
|
||||||
|
}
|
||||||
|
|
||||||
// Return a set of labels from the Extension and Property manager
|
// Return a set of labels from the Extension and Property manager
|
||||||
// Allow Extension labels to disable importing labels from the property manager.
|
// Allow Extension labels to disable importing labels from the property manager.
|
||||||
func getLabels(sfClient sfClient, service *sf.ServiceItem, app *sf.ApplicationItem) (map[string]string, error) {
|
func getLabels(sfClient sfClient, service *sf.ServiceItem, app *sf.ApplicationItem) (map[string]string, error) {
|
||||||
|
|
57
vendor/github.com/containous/traefik-extra-service-fabric/servicefabric_config.go
generated
vendored
57
vendor/github.com/containous/traefik-extra-service-fabric/servicefabric_config.go
generated
vendored
|
@ -1,7 +1,6 @@
|
||||||
package servicefabric
|
package servicefabric
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"errors"
|
"errors"
|
||||||
"math"
|
"math"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -14,12 +13,7 @@ import (
|
||||||
sf "github.com/jjcollinge/servicefabric"
|
sf "github.com/jjcollinge/servicefabric"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (p *Provider) buildConfiguration(sfClient sfClient) (*types.Configuration, error) {
|
func (p *Provider) buildConfiguration(services []ServiceItemExtended) (*types.Configuration, error) {
|
||||||
services, err := getClusterServices(sfClient)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var sfFuncMap = template.FuncMap{
|
var sfFuncMap = template.FuncMap{
|
||||||
// Services
|
// Services
|
||||||
"getServices": getServices,
|
"getServices": getServices,
|
||||||
|
@ -70,12 +64,9 @@ func (p *Provider) buildConfiguration(sfClient sfClient) (*types.Configuration,
|
||||||
return p.GetConfiguration(tmpl, sfFuncMap, templateObjects)
|
return p.GetConfiguration(tmpl, sfFuncMap, templateObjects)
|
||||||
}
|
}
|
||||||
|
|
||||||
func isStateful(service ServiceItemExtended) bool {
|
func isPrimary(instance replicaInstance) bool {
|
||||||
return service.ServiceKind == "Stateful"
|
_, data := instance.GetReplicaData()
|
||||||
}
|
return data.ReplicaRole == "Primary"
|
||||||
|
|
||||||
func isStateless(service ServiceItemExtended) bool {
|
|
||||||
return service.ServiceKind == "Stateless"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getBackendName(service ServiceItemExtended, partition PartitionItemExtended) string {
|
func getBackendName(service ServiceItemExtended, partition PartitionItemExtended) string {
|
||||||
|
@ -92,26 +83,6 @@ func getDefaultEndpoint(instance replicaInstance) string {
|
||||||
return endpoint
|
return endpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
func getReplicaDefaultEndpoint(replicaData *sf.ReplicaItemBase) (string, error) {
|
|
||||||
endpoints, err := decodeEndpointData(replicaData.Address)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
var defaultHTTPEndpoint string
|
|
||||||
for _, v := range endpoints {
|
|
||||||
if strings.Contains(v, "http") {
|
|
||||||
defaultHTTPEndpoint = v
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(defaultHTTPEndpoint) == 0 {
|
|
||||||
return "", errors.New("no default endpoint found")
|
|
||||||
}
|
|
||||||
return defaultHTTPEndpoint, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func getNamedEndpoint(instance replicaInstance, endpointName string) string {
|
func getNamedEndpoint(instance replicaInstance, endpointName string) string {
|
||||||
id, data := instance.GetReplicaData()
|
id, data := instance.GetReplicaData()
|
||||||
endpoint, err := getReplicaNamedEndpoint(data, endpointName)
|
endpoint, err := getReplicaNamedEndpoint(data, endpointName)
|
||||||
|
@ -175,26 +146,6 @@ func filterServicesByLabelValue(services []ServiceItemExtended, key, expectedVal
|
||||||
return srvWithLabel
|
return srvWithLabel
|
||||||
}
|
}
|
||||||
|
|
||||||
func decodeEndpointData(endpointData string) (map[string]string, error) {
|
|
||||||
var endpointsMap map[string]map[string]string
|
|
||||||
|
|
||||||
if endpointData == "" {
|
|
||||||
return nil, errors.New("endpoint data is empty")
|
|
||||||
}
|
|
||||||
|
|
||||||
err := json.Unmarshal([]byte(endpointData), &endpointsMap)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
endpoints, endpointsExist := endpointsMap["Endpoints"]
|
|
||||||
if !endpointsExist {
|
|
||||||
return nil, errors.New("endpoint doesn't exist in endpoint data")
|
|
||||||
}
|
|
||||||
|
|
||||||
return endpoints, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func getHeaders(service ServiceItemExtended) *types.Headers {
|
func getHeaders(service ServiceItemExtended) *types.Headers {
|
||||||
headers := &types.Headers{
|
headers := &types.Headers{
|
||||||
CustomRequestHeaders: label.GetMapValue(service.Labels, label.TraefikFrontendRequestHeaders),
|
CustomRequestHeaders: label.GetMapValue(service.Labels, label.TraefikFrontendRequestHeaders),
|
||||||
|
|
9
vendor/github.com/containous/traefik-extra-service-fabric/servicefabric_tmpl.go
generated
vendored
9
vendor/github.com/containous/traefik-extra-service-fabric/servicefabric_tmpl.go
generated
vendored
|
@ -59,7 +59,7 @@ const tmpl = `
|
||||||
{{range $instance := $partition.Instances}}
|
{{range $instance := $partition.Instances}}
|
||||||
[backends."{{ $service.Name }}".servers."{{ $instance.ID }}"]
|
[backends."{{ $service.Name }}".servers."{{ $instance.ID }}"]
|
||||||
url = "{{ getDefaultEndpoint $instance }}"
|
url = "{{ getDefaultEndpoint $instance }}"
|
||||||
weight = {{ getLabelValue $service "backend.weight" "1" }}
|
weight = {{ getWeight $service }}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{else if isStateful $service}}
|
{{else if isStateful $service}}
|
||||||
|
@ -204,12 +204,13 @@ const tmpl = `
|
||||||
{{range $partition := $service.Partitions }}
|
{{range $partition := $service.Partitions }}
|
||||||
{{ $partitionId := $partition.PartitionInformation.ID }}
|
{{ $partitionId := $partition.PartitionInformation.ID }}
|
||||||
|
|
||||||
{{if hasLabel $service "frontend.rule" }}
|
{{ $rule := getLabelValue $service (print "traefik.frontend.rule.partition." $partitionId) "" }}
|
||||||
|
{{if $rule }}
|
||||||
[frontends."{{ $service.Name }}/{{ $partitionId }}"]
|
[frontends."{{ $service.Name }}/{{ $partitionId }}"]
|
||||||
backend = "{{ getBackendName $service.Name $partition }}"
|
backend = "{{ getBackendName $service $partition }}"
|
||||||
|
|
||||||
[frontends."{{ $service.Name }}/{{ $partitionId }}".routes.default]
|
[frontends."{{ $service.Name }}/{{ $partitionId }}".routes.default]
|
||||||
rule = {{ getLabelValue $service "frontend.rule.partition.$partitionId" "" }}
|
rule = "{{ $rule }}"
|
||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue