-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Dash is considered as a field instead as separator #7524
Conversation
Hi @vvejell1. Thanks for your PR. I'm waiting for a containerd member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
Let's follow the terminology in parser.go. Lines 26 to 48 in 766e933
The change is making |
Also please write some unit tests for the change. |
filters/parser.go
Outdated
@@ -41,7 +41,7 @@ The formal grammar is as follows: | |||
selectors := selector ("," selector)* | |||
selector := fieldpath (operator value) | |||
fieldpath := field ('.' field)* | |||
field := quoted | [A-Za-z] [A-Za-z0-9_]+ | |||
field := quoted | [A-Za-z-] [A-Za-z0-9_]+ |
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.
Would a field start from -
?
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 think 'dash' that separates two words is taken as a field/value. Also, hyphen(-) is accepted in regex. Here an example [-A-z0-9]+, [a-Za-9-]+, [a-z-0-9]+, and [a-z-0-9]+ are all similar.
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.
Before your change, hello
, hello1
and hello_1
are all valid fields, but 1hello
and _hello
are not.
The comment after your change indicates, _hello
is still invalid but -hello
is valid. Is that what you want to propose?
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.
Using an '-' or '_' whenever possible to avoid positional dependencies and making the sentences less complex and valid. In my view, there may be a better way to write some of the special characters like 1hello
, they must absolutely consider in certain situations.
91c4f50
to
6efbbb9
Compare
7ae1cd0
to
34cf495
Compare
Signed-off-by: Vaishnavi Vejella <vvejella@amazon.com>
@@ -138,6 +138,10 @@ chomp: | |||
return pos, tokenValue, s.input[pos:s.ppos] | |||
case isFieldRune(ch): | |||
s.scanField() | |||
if ch == '-' || isDigitRune(ch) { // illegal token if it starts with '-' or any digit | |||
s.error("illegal token field") |
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.
@dmcgowan / @estesp - The implementation was less strict than the syntax here. Do we want to make this change in 1.x?
Lines 39 to 47 in b2a01ee
The formal grammar is as follows: | |
selectors := selector ("," selector)* | |
selector := fieldpath (operator value) | |
fieldpath := field ('.' field)* | |
field := quoted | [A-Za-z] [A-Za-z0-9_]+ | |
operator := "==" | "!=" | "~=" | |
value := quoted | [^\s,]+ | |
quoted := <go string syntax> |
If we follow the syntax and update the implementation;
- It would be better to explain why this is illegal in the error itself.
- It should handle
_
as well.
The situation is messier than I initially thought. First, our implementation doesn't follow the grammar in the code comment. If not quoted, only Second, our implementation matches neither http://label-schema.org/rc1/ nor https://docs.docker.com/config/labels-custom-metadata/#key-format-recommendations. Both allows Third, neither http://label-schema.org/rc1/ nor https://docs.docker.com/config/labels-custom-metadata/#key-format-recommendations follow https://www.ietf.org/rfc/rfc2119.txt. For example,
Are they MUST, should or may? :) |
I synced-up offline with @vvejell1, @dims and @estesp and but want to hear thoughts from @thaJeztah, @stevvooe and @dmcgowan. Especially since containerd has been around for years and the grammar is only in the code comment, I don't want to make the implementation more strict, especially in 1.x series. The ship has sailed. Accepting Thoughts? |
This change is only changing the grammar of the filters, which is intentionally limited and has quotes to express any value. If this change is only necessary to avoid quoting the value when providing a filter, then the dash seems like an arbitrary addition. Is there a case which is not working today when quoted or is this mostly about adding the case for CLI users? |
I think that quotes are necessary for the label. This implementation only allows the |
The point is that the quotes make this change unnecessary. In the unit test example, |
If I recall correctly, the idea behind labels being bookended by a non-separator was to prevent ambiguity when using these on the command-line; e.g., a label named |
Perhaps the choice of wording on that page in our docs is a bit poor;
So yes, the key (name) may contain periods and hyphens, but enclosed between alpha-numeric characters (original version, which got somewhat rewritten in docker/docs@67610e9). Some of the wording wasn't written in strict MUST/SHOULD conventions (I think as there was still some debate about enforcing or not). |
PR needs rebase. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
The syntax limitation comes from Protobuf's fieldpath syntax. I cannot find a link, since the containerd implementation comes up. The "fields" in fieldpath are limited to valid protobuf IDENT character set, which typically doesn't include "-". To make filters work on user specific input, quotes were added as a general escape hatch. This might be an ok change but we need a few things:
I can make a PR for this, as the change is slightly subtle. |
This PR is stale because it has been open 90 days with no activity. This PR will be closed in 7 days unless new comments are made or the stale label is removed. |
This PR was closed because it has been stalled for 7 days with no activity. |
Signed-off-by: Vaishnavi Vejella vvejella@amazon.com
Description #5642:
Containers have labels and they act as filters when querying the containers. So, while checking a label with the 'dash' which is failing because '-' is interpreting here as an operator and it is not considering as a part of token field.
Solution:
This problem can be solved by treating
-
as a component of the field rather than a separator.Also, it appears that there are some places where it is assumed that
.
is the only separator in a fieldpath.[e.g]
containerd/metadata/adaptors.go
Line 175 in 9022126