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
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
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/cenk/backoff"
|
||||
|
@ -18,6 +21,11 @@ var _ provider.Provider = (*Provider)(nil)
|
|||
|
||||
const traefikServiceFabricExtensionKey = "Traefik"
|
||||
|
||||
const (
|
||||
kindStateful = "Stateful"
|
||||
kindStateless = "Stateless"
|
||||
)
|
||||
|
||||
// Provider holds for configuration for the provider
|
||||
type Provider struct {
|
||||
provider.BaseProvider `mapstructure:",squash"`
|
||||
|
@ -66,7 +74,7 @@ func (p *Provider) updateConfig(configurationChan chan<- types.ConfigMessage, po
|
|||
log.Info("Checking service fabric config")
|
||||
}
|
||||
|
||||
configuration, err := p.buildConfiguration(sfClient)
|
||||
configuration, err := p.getConfiguration(sfClient)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -90,6 +98,15 @@ func (p *Provider) updateConfig(configurationChan chan<- types.ConfigMessage, po
|
|||
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) {
|
||||
apps, err := sfClient.GetApplications()
|
||||
if err != nil {
|
||||
|
@ -171,11 +188,6 @@ func getValidInstances(sfClient sfClient, app sf.ApplicationItem, service sf.Ser
|
|||
return validInstances
|
||||
}
|
||||
|
||||
func isPrimary(instance replicaInstance) bool {
|
||||
_, data := instance.GetReplicaData()
|
||||
return data.ReplicaRole == "Primary"
|
||||
}
|
||||
|
||||
func isHealthy(instanceData *sf.ReplicaItemBase) bool {
|
||||
return instanceData != nil && (instanceData.ReplicaStatus == "Ready" && instanceData.HealthState != "Error")
|
||||
}
|
||||
|
@ -185,6 +197,54 @@ func hasHTTPEndpoint(instanceData *sf.ReplicaItemBase) bool {
|
|||
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
|
||||
// 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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue