-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Support regex expression for node_labels #2206
Support regex expression for node_labels #2206
Conversation
Can one of the admins verify this patch? |
Anyone? |
Thanks for your PR and your patience! We are going to review and address it after 3.0 release. |
} | ||
|
||
// matchLabels, labelsMessage := MatchLabels(role.GetNodeLabels(Deny), s.GetAllLabels()) |
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.
Delete commented out code.
if !utils.SliceContainsStr(selectorValues, Wildcard) { | ||
result, err := utils.SliceContainsRegexStr(targetVal, selectorValues) | ||
if err != nil { | ||
return false, "", trace.BadParameter(err.Error()) |
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.
return false, "", trace.Wrap(err)
matchLabels, labelsMessage := MatchLabels(role.GetNodeLabels(Deny), s.GetAllLabels()) | ||
matchLabels, labelsMessage, err := MatchLabels(role.GetNodeLabels(Deny), s.GetAllLabels()) | ||
if err != nil { | ||
return trace.CompareFailed(err.Error()) |
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 trace.CompareFailed
checked anywhere? If not, I would just trace.Wrap(err)
here as well.
matchLabels, labelsMessage := MatchLabels(role.GetNodeLabels(Allow), s.GetAllLabels()) | ||
matchLabels, labelsMessage, err := MatchLabels(role.GetNodeLabels(Allow), s.GetAllLabels()) | ||
if err != nil { | ||
return trace.CompareFailed(err.Error()) |
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 trace.CompareFailed
checked anywhere? If not, I would just trace.Wrap(err)
here as well.
@@ -46,5 +46,26 @@ func ReplaceRegexp(expression string, replaceWith string, input string) (string, | |||
return expr.ReplaceAllString(input, replaceWith), nil | |||
} | |||
|
|||
func SliceContainsRegexStr(input string, expressions []string) (bool, error) { |
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.
Missing comment explaining what the function does.
if err != nil { | ||
return false, trace.BadParameter(err.Error()) | ||
} | ||
if expr.MatchString(input) { |
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.
Add a comment that because the expression is always surrounded by ^
and $
this is an exact match for either a a plain string (for example ^hello$
) or for a regexp (for example ^hel*o$
).
@russjones thanks for your comments let me update it. |
note that we have preserved your original commit for history as well :) |
#2205