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

Handle selectors correctly in VersionedParams(). #17836

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 36 additions & 2 deletions pkg/client/unversioned/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,42 @@ func (r *Request) VersionedParams(obj runtime.Object, convertor runtime.ObjectCo
return r
}
for k, v := range params {
for _, vv := range v {
r.setParam(k, vv)
for _, value := range v {
// TODO: Move it to setParam method, once we get rid of
// FieldSelectorParam & LabelSelectorParam methods.
if k == unversioned.LabelSelectorQueryParam(r.apiVersion) && value == "" {
// Don't set an empty selector for backward compatibility.
Copy link
Member

Choose a reason for hiding this comment

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

I see. Perhaps we need to fix the converter or make something into a pointer so we can tell the difference between unspecified and deliberately set to ""? I don't think we make a distinction in query parameters, but we do for the label selectors in e.g. service objects-- unset means nothing and set-but-empty means everything. So this may be important to get right, or at least expand the comment?

Copy link
Member Author

Choose a reason for hiding this comment

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

The issue here is that in golang there is no way to differ "" and unspecified string.
I will expand this comment.

Copy link
Member

Choose a reason for hiding this comment

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

Right, and this may not be a big deal-- but you'd probably have to fix this a level up by making unversioned.ListOptions distinguish between unset selector and set-but-empty (by making it a pointer, if necessary).

Copy link
Member Author

Choose a reason for hiding this comment

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

Can we do it in a separate PR?
This PR is not introducing any regression.

Copy link
Member

Choose a reason for hiding this comment

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

Sure, that's fine.

On Mon, Nov 30, 2015 at 11:52 AM, Wojciech Tyczynski <
notifications@github.com> wrote:

In pkg/client/unversioned/request.go
#17836 (comment)
:

@@ -427,8 +427,36 @@ func (r *Request) VersionedParams(obj runtime.Object, convertor runtime.ObjectCo
return r
}
for k, v := range params {

  •   for _, vv := range v {
    
  •       r.setParam(k, vv)
    
  •   for _, value := range v {
    
  •       // TODO: Move it to setParam method, once we get rid of
    
  •       // FieldSelectorParam & LabelSelectorParam methods.
    
  •       if k == unversioned.LabelSelectorQueryParam(r.apiVersion) && value == "" {
    
  •           // Don't set an empty selector for backward compatibility.
    

Can we do it in a separate PR?
This PR is not introducing any regression.


Reply to this email directly or view it on GitHub
https://github.com/kubernetes/kubernetes/pull/17836/files#r46193654.

Copy link
Contributor

Choose a reason for hiding this comment

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

ListOPtions should be versioned is my argument. Seeing this code, seeing
the field transformation code, it's basically versioning. The API for that
object has to be stable, which is the whole point of what we had "internal"
objects before. The rest of the path is wire transformation - saying that
there is no wire transformation for ListOptions is silly. Creating a
different way of handling list options from all the other options is
basically creating an extra code path, not removing a code path.

On Wed, Dec 9, 2015 at 11:13 AM, Wojciech Tyczynski <
notifications@github.com> wrote:

In pkg/client/unversioned/request.go
#17836 (comment)
:

@@ -427,8 +427,36 @@ func (r *Request) VersionedParams(obj runtime.Object, convertor runtime.ObjectCo
return r
}
for k, v := range params {

  •   for _, vv := range v {
    
  •       r.setParam(k, vv)
    
  •   for _, value := range v {
    
  •       // TODO: Move it to setParam method, once we get rid of
    
  •       // FieldSelectorParam & LabelSelectorParam methods.
    
  •       if k == unversioned.LabelSelectorQueryParam(r.apiVersion) && value == "" {
    
  •           // Don't set an empty selector for backward compatibility.
    

Yes - but we can move it to converter, without getting back to versioned
ListOptions, I think.


Reply to this email directly or view it on GitHub
https://github.com/kubernetes/kubernetes/pull/17836/files#r47111463.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not saying that we shouldn't get back to versioned ListOptions.

What I'm saying is that we already had exactly the same code in Request::LabelSelector() and Request::FieldSelector before. So this code wasn't created - it was move from one place to the other.

That said - I agree it shouldn't be here. We should basically move "fieldmappig" to some more generic places (conversion-related) and once this is done, we can also move this code there.
So in my opinion, cleaning up this code is unrelated to getting back to ListOptions...

Copy link
Member Author

Choose a reason for hiding this comment

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

So in other words - we should definitely clean this up, even before getting back to versioned ListOptions - because those are orthogonal problems.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes they are orthogonal, but related in the sense of location.

There should be conversion functions for field selectors that know how to
target the field selectors. The hard problem is that the type of the field
selector is a dynamic input, not a static input. We may need to support
conversion options to Convert that define additional metadata that allows
the field selector conversion to target base on the input metadata
(essentially an object reference). One scheme is not guaranteed to hold
all conversions either - so there's an inside out problem here we may have
to solve in the future.

On Wed, Dec 9, 2015 at 12:00 PM, Wojciech Tyczynski <
notifications@github.com> wrote:

In pkg/client/unversioned/request.go
#17836 (comment)
:

@@ -427,8 +427,36 @@ func (r *Request) VersionedParams(obj runtime.Object, convertor runtime.ObjectCo
return r
}
for k, v := range params {

  •   for _, vv := range v {
    
  •       r.setParam(k, vv)
    
  •   for _, value := range v {
    
  •       // TODO: Move it to setParam method, once we get rid of
    
  •       // FieldSelectorParam & LabelSelectorParam methods.
    
  •       if k == unversioned.LabelSelectorQueryParam(r.apiVersion) && value == "" {
    
  •           // Don't set an empty selector for backward compatibility.
    

So in other words - we should definitely clean this up, even before
getting back to versioned ListOptions - because those are orthogonal
problems.


Reply to this email directly or view it on GitHub
https://github.com/kubernetes/kubernetes/pull/17836/files#r47118963.

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree with the first part.

One scheme is not guaranteed to hold
all conversions either - so there's an inside out problem here we may have
to solve in the future.

If that's the case, we will need to change this code too, because currently we only have one convertor here.

Sorry - I probably don't see some consequence that you can see, so I'm trying to understand them (also note that I'm not opting for not changing it back to versioned - I'm just trying to understand what it would give us now...)

// Since there is no way to get the difference between empty
// and unspecified string, we don't set it to avoid having
// labelSelector= param in every request.
continue
}
if k == unversioned.FieldSelectorQueryParam(r.apiVersion) {
if value == "" {
// Don't set an empty selector for backward compatibility.
// Since there is no way to get the difference between empty
// and unspecified string, we don't set it to avoid having
// fieldSelector= param in every request.
continue
}
// TODO: Filtering should be handled somewhere else.
selector, err := fields.ParseSelector(value)
if err != nil {
r.err = fmt.Errorf("unparsable field selector: %v", err)
return r
}
filteredSelector, err := selector.Transform(
func(field, value string) (newField, newValue string, err error) {
return fieldMappings.filterField(r.apiVersion, r.resource, field, value)
})
if err != nil {
r.err = fmt.Errorf("untransformable field selector: %v", err)
return r
}
value = filteredSelector.String()
}

r.setParam(k, value)
}
}
return r
Expand Down