-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Conversation
6112281
to
c9f11cc
Compare
Hi @samber thanks a lot for your great work! |
@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-*") |
There was a problem hiding this comment.
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
@keis, you're right, maybe we could keep the providers constraints and add global constraints? |
c9f11cc
to
23c077f
Compare
Improvement in the last commit: @emilevauge : global constraints + provider-specific constraints Please note that |
@samber validation error ;) |
Yes I didn't finish working on that. if everybody agrees on implementation, it's time for me to write some tests ;-) |
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 😉 |
OK thanks @vdemeester! |
Concept ACK 👍 |
b4570ba
to
1f9a4dd
Compare
5995467
to
7d14972
Compare
It's alright on my side. Ready for review and merge ;-) cc @pnegahdar |
} | ||
|
||
for _, constraint := range p.Constraints { | ||
if ok := constraint.MatchConstraintWithAtLeastOneTag(tags); xor(ok == true, constraint.MustMatch == true) { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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'
Thanks a lot @samber ! Great job :) |
c371c23
to
2cfa2b1
Compare
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 |
There was a problem hiding this comment.
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 ? 😛
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Arf, my bad ;-)
@samber impressive job 😻 |
… + matching functions), implementation proposal with consul
2cfa2b1
to
d297a22
Compare
Fixed and rebased 👍 |
Very good job indeed 👍 |
see #311