1
0
Fork 0

Support Nomad canary deployment

Co-authored-by: Kevin Pollet <pollet.kevin@gmail.com>
Co-authored-by: Mathieu Lonjaret <mathieu.lonjaret@gmail.com>
This commit is contained in:
Romain 2022-08-01 17:52:08 +02:00 committed by GitHub
parent ab94bbaece
commit 2a2ea759d1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 593 additions and 51 deletions

View file

@ -185,19 +185,25 @@ func createClient(namespace string, endpoint *EndpointConfig) (*api.Client, erro
// configuration contains information from the service's tags that are globals
// (not specific to the dynamic configuration).
type configuration struct {
Enable bool // <prefix>.enable
Enable bool // <prefix>.enable is the corresponding label.
Canary bool // <prefix>.nomad.canary is the corresponding label.
}
// globalConfig returns a configuration with settings not specific to the dynamic configuration (i.e. "<prefix>.enable").
func (p *Provider) globalConfig(tags []string) configuration {
enabled := p.ExposedByDefault
// getExtraConf returns a configuration with settings which are not part of the dynamic configuration (e.g. "<prefix>.enable").
func (p *Provider) getExtraConf(tags []string) configuration {
labels := tagsToLabels(tags, p.Prefix)
enabled := p.ExposedByDefault
if v, exists := labels["traefik.enable"]; exists {
enabled = strings.EqualFold(v, "true")
}
return configuration{Enable: enabled}
var canary bool
if v, exists := labels["traefik.nomad.canary"]; exists {
canary = strings.EqualFold(v, "true")
}
return configuration{Enable: enabled, Canary: canary}
}
func (p *Provider) getNomadServiceData(ctx context.Context) ([]item, error) {
@ -216,8 +222,8 @@ func (p *Provider) getNomadServiceData(ctx context.Context) ([]item, error) {
for _, service := range stub.Services {
logger := log.FromContext(log.With(ctx, log.Str("serviceName", service.ServiceName)))
globalCfg := p.globalConfig(service.Tags)
if !globalCfg.Enable {
extraConf := p.getExtraConf(service.Tags)
if !extraConf.Enable {
logger.Debug("Filter Nomad service that is not enabled")
continue
}
@ -248,7 +254,7 @@ func (p *Provider) getNomadServiceData(ctx context.Context) ([]item, error) {
Address: i.Address,
Port: i.Port,
Tags: i.Tags,
ExtraConf: p.globalConfig(i.Tags),
ExtraConf: p.getExtraConf(i.Tags),
})
}
}