Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(constraints): Implementation of constraint filtering (cmd + toml + matching functions), implementation proposal with consul #342

Merged

Conversation

samber
Copy link
Contributor

@samber samber commented Apr 29, 2016

see #311

@samber samber force-pushed the TRAEFIK-311--adding-constraint-filtering branch 3 times, most recently from 6112281 to c9f11cc Compare April 30, 2016 20:33
@emilevauge
Copy link
Member

Hi @samber thanks a lot for your great work!
What do you think of simplifying this a bit by moving constraints inside GlobalConfiguration, instead of being defined in each provider?
I think constraints should be defined for the whole instance, and be used by each provider.
WDYT?
/cc @keis, @vdemeester

@keis
Copy link

keis commented May 4, 2016

@emilevauge constraints defined for the instance sounds like the right way to go.

One potential problem with that is if there is a difference in what "constraint types" the different backends support. Right now the only supported type is matching on "tags" but I guess there could be others? like the overlay network for docker but that would not make any sense for consul. But I don't think it worth worrying to much about :)

func (p *BaseProvider) matchConstraintWithAtLeastOneTag(tags []string, constraint *types.Constraint) (bool, error) {
// At the moment, it only supports tags
if constraint.Key != "tag" {
return false, errors.New("Constraint must be tag-based. Syntax: tag==us-*")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would verify this already in NewConstraint, I also think this whole function should actually be method of Constraint because that's the only instance data it operates on

@emilevauge
Copy link
Member

@keis, you're right, maybe we could keep the providers constraints and add global constraints?
I think that global constraints are much simpler in the multiple traefik instances per environment use case :)

@samber samber changed the title feat(constraints): Implementation of constraint filtering (cmd + toml + matching functions), implementation proposal with consul [WIP] feat(constraints): Implementation of constraint filtering (cmd + toml + matching functions), implementation proposal with consul May 9, 2016
@samber samber force-pushed the TRAEFIK-311--adding-constraint-filtering branch from c9f11cc to 23c077f Compare May 9, 2016 15:12
@samber
Copy link
Contributor Author

samber commented May 9, 2016

Improvement in the last commit:

@emilevauge : global constraints + provider-specific constraints
@keis : refactored ;-)

Please note that MatchConstraints returns a new variable: failingConstraint (or nil), for logging purpose.

@emilevauge
Copy link
Member

@samber validation error ;)

@samber
Copy link
Contributor Author

samber commented May 12, 2016

Yes I didn't finish working on that.

if everybody agrees on implementation, it's time for me to write some tests ;-)

@vdemeester
Copy link
Contributor

vdemeester commented May 12, 2016

After reading #311 (comment) I like the idea, but as @emilevauge I like the idea of having global constaints to (no matter the provider used) and maybe merge them.

On the implementation side, for docker, the way to filter the contstaint would definitely be labels (but with a mix of container labels and node/host labels).

I agree with the design, and it's probably easier for now (and for the scope of this PR) to not implement global constraint right away 😉

@emilevauge
Copy link
Member

OK thanks @vdemeester!
@samber I think everybody is OK on the implementation :)

@keis
Copy link

keis commented May 13, 2016

Concept ACK 👍

@samber samber force-pushed the TRAEFIK-311--adding-constraint-filtering branch 4 times, most recently from b4570ba to 1f9a4dd Compare May 23, 2016 08:29
@samber samber force-pushed the TRAEFIK-311--adding-constraint-filtering branch 3 times, most recently from 5995467 to 7d14972 Compare May 25, 2016 15:54
@samber
Copy link
Contributor Author

samber commented May 25, 2016

It's alright on my side. Ready for review and merge ;-)

cc @pnegahdar

@samber samber changed the title [WIP] feat(constraints): Implementation of constraint filtering (cmd + toml + matching functions), implementation proposal with consul feat(constraints): Implementation of constraint filtering (cmd + toml + matching functions), implementation proposal with consul May 25, 2016
}

for _, constraint := range p.Constraints {
if ok := constraint.MatchConstraintWithAtLeastOneTag(tags); xor(ok == true, constraint.MustMatch == true) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bool == true is a bit redundant so this would be clearer to write as simply ok != constraint.MustMatch

Docker: &provider.Docker{
TLS: &provider.DockerTLS{},
// @todo: Docker constraints
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sed 's/@todo/TODO/g'

@emilevauge
Copy link
Member

emilevauge commented May 26, 2016

Thanks a lot @samber ! Great job :)
Few minor comments, but other than that, looks good to me.
/cc @vdemeester

@samber samber force-pushed the TRAEFIK-311--adding-constraint-filtering branch 6 times, most recently from c371c23 to 2cfa2b1 Compare May 31, 2016 10:11
@samber
Copy link
Contributor Author

samber commented May 31, 2016

I did a large refacto because of the new cli library.

Ready for review ;-)

Key string
// MustMatch is true if operator is "==" or false if operator is "!="
MustMatch bool
// TODO: support regex
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this TODO still to do ? 😛

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, today, it's only supporting globing in a string. Not using RE2 syntax

@@ -248,7 +248,7 @@ func (server *Server) startProviders() {
log.Infof("Starting provider %v %s", reflect.TypeOf(provider), jsonConf)
currentProvider := provider
safe.Go(func() {
err := currentProvider.Provide(server.configurationChan, &server.routinesPool)
err := currentProvider.Provide(server.configurationChan, &server.routinesPool, server.globalConfiguration.Constraints.Get().([]types.Constraint))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't server.globalConfiguration.Constraints sufficient instead of server.globalConfiguration.Constraints.Get().([]types.Constraint) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arf, my bad ;-)

@emilevauge
Copy link
Member

@samber impressive job 😻
Only one comment on the code.
Once rebased, LGTM!
/cc @vdemeester

@samber samber force-pushed the TRAEFIK-311--adding-constraint-filtering branch from 2cfa2b1 to d297a22 Compare June 1, 2016 08:31
@samber
Copy link
Contributor Author

samber commented Jun 1, 2016

Fixed and rebased 👍

@vdemeester
Copy link
Contributor

Very good job indeed 👍
LGTM 🐮

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants