-
Notifications
You must be signed in to change notification settings - Fork 39.3k
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
Fix kubectl sort-by metadata issue. #21694
Fix kubectl sort-by metadata issue. #21694
Conversation
@kubernetes/rh-cluster-infra |
Labelling this PR as size/S |
GCE e2e build/test failed for commit 71412f2. |
cc @kubernetes/rh-ux @kubernetes/kubectl |
if err != nil { | ||
return err | ||
} | ||
|
||
// TODO: questionable | ||
if sorter, err = kubectl.SortObjects(f.Decoder(true), objs, sorting); err != nil { |
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.
at first glance, rather than converting into versions objects, here, I think would expect to pass the output version to SortObjects
... it is taking a fieldInput, which is not really meaningful unless paired with a group version. In SortObjects
, can we decode to the specified groupversion? I'd like @smarterclayton's take on that as well...
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 expect us to be sorting based on the JSON and the field path
qualifier only, or at minimum on the map[string]interface{}. It's a
riskier change though.
On Mon, Feb 22, 2016 at 1:37 PM, Jordan Liggitt notifications@github.com
wrote:
In pkg/kubectl/cmd/get.go
#21694 (comment)
:
clientConfig, err := f.ClientConfig()
if err != nil {
return err
}
version, err := cmdutil.OutputVersion(cmd, clientConfig.GroupVersion)
if err != nil {
return err
}
objs, err = resource.AsVersionedObjects(infos, version.String(), f.JSONEncoder())
if err != nil {
return err
}
- // TODO: questionable
if sorter, err = kubectl.SortObjects(f.Decoder(true), objs, sorting); err != nil {at first glance, rather than converting into versions objects, here, I
think would expect to pass the output version to SortObjects... it is
taking a fieldInput, which is not really meaningful unless paired with a
group version. In SortObjects, can we decode to the specified
groupversion? I'd like @smarterclayton https://github.com/smarterclayton's
take on that as well...—
Reply to this email directly or view it on GitHub
https://github.com/kubernetes/kubernetes/pull/21694/files#r53669745.
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.
@liggitt I am looking into what you suggested and i think it should be possible. The only issue with that I see is that once we decode objects into specified groupversion inside SortObjects, after sorting, any caller of sort-by would have converted versioned objects and it would require handling printing of those objects in the similar way as it is done currently in kubectl get. Because as I understand, it is not possible to print versioned objects directly but only internal types objects.
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.
Or another way might be to convert sorted and decoded obejcts back to their internal types and then return them. Although I am not sure how to handle this,
e2e failed because of
|
@k8s-bot e2e test this issue: #IGNORE |
GCE e2e build/test failed for commit 71412f2. |
GCE e2e test build/test passed for commit 71412f2. |
The author of this PR is not in the whitelist for merge, can one of the admins add the 'ok-to-merge' label? |
71412f2
to
b0624ef
Compare
Labelling this PR as size/M |
b0624ef
to
01632d0
Compare
I have updated this PR and it seems to be working wth kubectl get. I am still trying to see if it could affect annotate, create, rollingupdate, expose, run, autoscale, label, although I have yet to check if these commands really need sort-by or not. |
Wouldn't anything that outputs objects potentially use SortObjects and be affected? That's why I think the work of applying the sort by field to the correct output version should be done inside the common sorting code |
GCE e2e test build/test passed for commit 01632d0f7daf16e5d37c4fb57d2112db56b49501. |
GCE e2e test build/test passed for commit b0624ef08311eacb4267f33aa4e74d2e03d1acd3. |
I think sort-by was added only for |
is it a global flag? If so, we should stop adding global flags that only apply to a single command |
@@ -63,7 +66,7 @@ func (s *SortingPrinter) sortObj(obj runtime.Object) error { | |||
return nil | |||
} | |||
|
|||
sorter, err := SortObjects(s.Decoder, objs, s.SortField) | |||
sorter, err := SortObjects(s.Decoder, objs, s.SortField, "") |
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.
We should probably never sort by the "" version or group
Wouldn't it be a lot easier to just convert to the output version to begin with, and then nothing else would need to change? |
Agreed |
this is obscure enough that it deserves at least one test, I think |
@liggitt ok will look into that. |
@aveshagarwal |
GCE e2e build/test passed for commit 5207cb5317bf81204b2c7d3930bdd80e336c365e. |
Internal types are not supposed to have json metadata (though in kubernetes they do) as it is true with openshift types. That means sort-by must work on versioned objects for sorting, otherwise it produces "error: metadata is not found" error if it sorts internal types without json metadata. This PR converts internal types objects to versioned objects and sort-by sorts them correctly without medata error, and then it prints corresponding internal objects in sorted order.
5207cb5
to
be06003
Compare
@liggitt Added a test case. PTAL. |
Labelling this PR as size/M |
GCE e2e build/test passed for commit be06003. |
LGTM |
@k8s-bot test this Tests are more than 48 hours old. Re-running tests. |
GCE e2e build/test passed for commit be06003. |
@k8s-bot test this [submit-queue is verifying that this PR is safe to merge] |
GCE e2e build/test passed for commit be06003. |
Automatic merge from submit-queue |
Auto commit by PR queue bot
Internal types are not supposed to have json metadata (though in kubernetes
they do) as it is true with openshift types. That means sort-by must work
on versioned objects for sorting, otherwise it produces "error: metadata
is not found" error if it sorts internal types without json metadata.
This PR converts internal types objects to versioned objects and sort-by
sorts them correctly without medata error, and then it prints
corresponding internal objects in sorted order.