Marathon constraints filtering
This commit is contained in:
parent
7ddefcef72
commit
4b91204686
4 changed files with 65 additions and 20 deletions
|
@ -68,6 +68,16 @@ domain = "marathon.localhost"
|
|||
#
|
||||
# marathonLBCompatibility = true
|
||||
|
||||
# Enable filtering using Marathon constraints..
|
||||
# If enabled, Traefik will read Marathon constraints, as defined in https://mesosphere.github.io/marathon/docs/constraints.html
|
||||
# Each individual constraint will be treated as a verbatim compounded tag.
|
||||
# i.e. "rack_id:CLUSTER:rack-1", with all constraint groups concatenated together using ":"
|
||||
#
|
||||
# Optional
|
||||
# Default: false
|
||||
#
|
||||
# filterMarathonConstraints = true
|
||||
|
||||
# Enable Marathon basic authentication.
|
||||
#
|
||||
# Optional
|
||||
|
|
|
@ -44,6 +44,12 @@ func label(key, value string) func(*marathon.Application) {
|
|||
}
|
||||
}
|
||||
|
||||
func constraint(value string) func(*marathon.Application) {
|
||||
return func(app *marathon.Application) {
|
||||
app.AddConstraint(strings.Split(value, ":")...)
|
||||
}
|
||||
}
|
||||
|
||||
func labelWithService(key, value string, serviceName string) func(*marathon.Application) {
|
||||
if len(serviceName) == 0 {
|
||||
panic("serviceName can not be empty")
|
||||
|
|
|
@ -59,6 +59,7 @@ type Provider struct {
|
|||
GroupsAsSubDomains bool `description:"Convert Marathon groups to subdomains" export:"true"`
|
||||
DCOSToken string `description:"DCOSToken for DCOS environment, This will override the Authorization header" export:"true"`
|
||||
MarathonLBCompatibility bool `description:"Add compatibility with marathon-lb labels" export:"true"`
|
||||
FilterMarathonConstraints bool `description:"Enable use of Marathon constraints in constraint filtering" export:"true"`
|
||||
TLS *types.ClientTLS `description:"Enable Docker TLS support" export:"true"`
|
||||
DialerTimeout flaeg.Duration `description:"Set a non-default connection timeout for Marathon" export:"true"`
|
||||
KeepAlive flaeg.Duration `description:"Set a non-default TCP Keep Alive time in seconds" export:"true"`
|
||||
|
@ -247,6 +248,11 @@ func (p *Provider) applicationFilter(app marathon.Application) bool {
|
|||
constraintTags = append(constraintTags, label)
|
||||
}
|
||||
}
|
||||
if p.FilterMarathonConstraints && app.Constraints != nil {
|
||||
for _, constraintParts := range *app.Constraints {
|
||||
constraintTags = append(constraintTags, strings.Join(constraintParts, ":"))
|
||||
}
|
||||
}
|
||||
if ok, failingConstraint := p.MatchConstraints(constraintTags); !ok {
|
||||
if failingConstraint != nil {
|
||||
log.Debugf("Filtering Marathon application %v pruned by '%v' constraint", app.ID, failingConstraint.String())
|
||||
|
|
|
@ -522,6 +522,7 @@ func TestMarathonApplicationFilterConstraints(t *testing.T) {
|
|||
desc string
|
||||
application marathon.Application
|
||||
marathonLBCompatibility bool
|
||||
filterMarathonConstraints bool
|
||||
expected bool
|
||||
}{
|
||||
{
|
||||
|
@ -536,6 +537,27 @@ func TestMarathonApplicationFilterConstraints(t *testing.T) {
|
|||
marathonLBCompatibility: false,
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
desc: "constraint missing",
|
||||
application: application(),
|
||||
marathonLBCompatibility: false,
|
||||
filterMarathonConstraints: true,
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
desc: "constraint invalid",
|
||||
application: application(constraint("service_cluster:CLUSTER:test")),
|
||||
marathonLBCompatibility: false,
|
||||
filterMarathonConstraints: true,
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
desc: "constraint valid",
|
||||
application: application(constraint("valid")),
|
||||
marathonLBCompatibility: false,
|
||||
filterMarathonConstraints: true,
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
desc: "LB compatibility tag matching",
|
||||
application: application(
|
||||
|
@ -554,6 +576,7 @@ func TestMarathonApplicationFilterConstraints(t *testing.T) {
|
|||
provider := &Provider{
|
||||
ExposedByDefault: true,
|
||||
MarathonLBCompatibility: c.marathonLBCompatibility,
|
||||
FilterMarathonConstraints: c.filterMarathonConstraints,
|
||||
}
|
||||
constraint, err := types.NewConstraint("tag==valid")
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in a new issue