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

Update get.go to use server-side printing #55637

Conversation

juanvallejo
Copy link
Contributor

@juanvallejo juanvallejo commented Nov 13, 2017

Addresses part of #58536
Adds support for server-side changes implemented in #40848 and updated in #59059

@deads2k per our discussion, opening this as a separate PR.
This wires through a per-request use of as=Table;... header parameters
using the resource builder from the kube get command.

Items to consider going forward:

  • Figure out how to handle sorting when dealing with multiple Table objects from the server
  • Figure out sorting when dealing with a mixed response from the server consisting of Tables and normal resources (--sort-by is handled in this PR by falling back to old behavior)
  • Filtering: How should we filter Table objects? Separate filter for rows? Filter on jsonpath? We have access to partial object metadata for each table row - not enough to know how to filter pods, for example but we could request that the original object be included along with each Table.Row by adding an includeObject param in the client request.

Resources that do not yet support Table output

Release note:

NONE

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Nov 13, 2017
@juanvallejo juanvallejo changed the title prototype use of tabular json response [WIP] prototype use of tabular json response Nov 13, 2017
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 13, 2017
table := &metav1alpha1.Table{}
err := req.
AsTable(metav1.GroupVersion{}).
Do().Into(table)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@deads2k I'm thinking it'd be best to just have a codec that handles this, however I'm not too familiar with this part of the codebase: https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/apimachinery/pkg/runtime/serializer/negotiated_codec.go#L34

@@ -162,6 +163,26 @@ func (r *Request) Suffix(segments ...string) *Request {
return r
}

// AsTable adds the "as=Table;v=v1alpha1;g=meta.k8s.io" parameter to the Accept header
Copy link
Contributor

Choose a reason for hiding this comment

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

Note that this method is simply a pretty skin for SetHeader

tableParam := fmt.Sprintf(";as=Table;v=%s;g=%s", gv.Version, gv.Group)

if len(r.content.AcceptContentTypes) > 0 {
r.SetHeader("Accept", r.content.AcceptContentTypes+tableParam)
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, it's not. It seems like we'll eventually want a way to add or set content types, but this could hold for a while.

@@ -63,7 +64,7 @@ func (m *Helper) Get(namespace, name string, export bool) (runtime.Object, error
return req.Do().Get()
}

func (m *Helper) List(namespace, apiVersion string, export bool, options *metav1.ListOptions) (runtime.Object, error) {
func (m *Helper) List(namespace, apiVersion string, export, requestTable bool, options *metav1.ListOptions) (runtime.Object, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

You'll need this for Get too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, wired it through to Get as well

Copy link
Contributor

Choose a reason for hiding this comment

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

No. Yuck. This should be a separate flag on Helper that changes the request type. We'll have other things we change to, like PartialObjectMetadata.

You also shouldn't have to be parsing into things, you just need to add the table type to the scheme

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Regarding setting this, we should be transforming request like c672a85#diff-b5780bd984478baab9841efd2c817719R267

And then handling the presence of a Table gracefully in the returned get.go code.

@@ -162,6 +163,26 @@ func (r *Request) Suffix(segments ...string) *Request {
return r
}

// AsTable adds the "as=Table;v=v1alpha1;g=meta.k8s.io" parameter to the Accept header
func (r *Request) AsTable(gv metav1.GroupVersion) *Request {
Copy link
Contributor

Choose a reason for hiding this comment

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

@smarterclayton this looks like the correct spot to set the options, since I wouldn't want an entirely new client for one request. The rest of the pull seems to flow from here. In the builder, we could argue things like enum over bool and the like, but given how get.go works, we need to set the value from pkg/kubectl/resource/helper.go

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think request should know anything about Table. This should just be SetHeader, only higher levels know about Tables. PartialObjectMetadata will also come through this path and I don't want AsPartialObjectMetadata

@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 19, 2017
@fabianofranz
Copy link
Contributor

/unassign

@soltysh
Copy link
Contributor

soltysh commented Jan 22, 2018

/assign

@juanvallejo juanvallejo force-pushed the jvallejo/kubectl-get-table-response-proto-v2 branch from cee04e7 to c6c4b79 Compare January 30, 2018 15:44
@kubernetes kubernetes deleted a comment from k8s-github-robot Jan 30, 2018
@k8s-github-robot k8s-github-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 30, 2018
@juanvallejo juanvallejo changed the title [WIP] prototype use of tabular json response prototype use of tabular json response Jan 30, 2018
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jan 30, 2018
@juanvallejo
Copy link
Contributor Author

@soltysh this has been rebased.
Intend to use it to implement client-side items from: #58536

@soltysh
Copy link
Contributor

soltysh commented Feb 22, 2018

With a simple check like this (you'd need to add nice error handling):

   b := f.NewBuilder()....Flatten()

    clientset, _ := f.ClientSet()
    version, _ := clientset.Discovery().ServerVersion()
    minor, _ := strconv.Atoi(version.Minor)
    if minor > 10 {
        b = b.TransformRequests(func(req *rest.Request) {...}
    }
    r := b.Do()
...

this will work nicely with 1.8 and 1.7.

@juanvallejo juanvallejo force-pushed the jvallejo/kubectl-get-table-response-proto-v2 branch from 4879c87 to 55deab7 Compare February 22, 2018 15:13
@smarterclayton
Copy link
Contributor

Please don't do version checking like that.

If this is something we can backport to 1.8 (it's probably the fall through version checking) that's better.

@soltysh
Copy link
Contributor

soltysh commented Feb 22, 2018

@smarterclayton we've discussed this in length during scrum, the 2 requests I've proposed is the way to go.

@juanvallejo juanvallejo force-pushed the jvallejo/kubectl-get-table-response-proto-v2 branch 3 times, most recently from 012804e to 50c30cd Compare February 22, 2018 16:55
@juanvallejo juanvallejo force-pushed the jvallejo/kubectl-get-table-response-proto-v2 branch from 50c30cd to fc14bb8 Compare February 23, 2018 15:21
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 23, 2018
@juanvallejo juanvallejo force-pushed the jvallejo/kubectl-get-table-response-proto-v2 branch 2 times, most recently from f9db9c1 to a21bb3f Compare February 23, 2018 15:32
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 23, 2018
This patch adds support for the "server-side GET operation"
introduced by pull/40848 and proposed by kubernetes/community#363.
@juanvallejo juanvallejo force-pushed the jvallejo/kubectl-get-table-response-proto-v2 branch from a21bb3f to 9946374 Compare February 23, 2018 15:41
Copy link
Contributor

@soltysh soltysh left a comment

Choose a reason for hiding this comment

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

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 23, 2018
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: deads2k, juanvallejo, soltysh

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-github-robot
Copy link

/test all [submit-queue is verifying that this PR is safe to merge]

@k8s-github-robot
Copy link

Automatic merge from submit-queue (batch tested with PRs 55637, 57461, 60268, 60290, 60210). If you want to cherry-pick this change to another branch, please follow the instructions here.

@k8s-github-robot k8s-github-robot merged commit 9116cb8 into kubernetes:master Feb 23, 2018
@k8s-ci-robot
Copy link
Contributor

k8s-ci-robot commented Feb 23, 2018

@juanvallejo: The following test failed, say /retest to rerun them all:

Test name Commit Details Rerun command
pull-kubernetes-unit 9946374 link /test pull-kubernetes-unit

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

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. I understand the commands that are listed here.

@juanvallejo juanvallejo deleted the jvallejo/kubectl-get-table-response-proto-v2 branch February 23, 2018 19:04
@smarterclayton
Copy link
Contributor

Sorting and printing should be using the table but with full objects returned via the print API (?includeObject=Object) and then doing the sort on nested, as should custom columns.

k8s-github-robot pushed a commit that referenced this pull request Feb 26, 2018
…nt-in-get

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

enable server-printing in tests

**Release note**:
```release-note
NONE
```

Depends on #55637

Separate pull to test the `--experimental-server-print` flag in test-cmd-util tests introduced in #55637

cc @soltysh
@soltysh
Copy link
Contributor

soltysh commented Feb 26, 2018

@smarterclayton I've added a point about that to the general server side printing issue.

k8s-github-robot pushed a commit that referenced this pull request Mar 28, 2018
Automatic merge from submit-queue (batch tested with PRs 61842, 61477, 61777). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

Turn server-print on by default in kubectl

**What this PR does / why we need it**:
#55637 introduced `-experimental-server-print` that enabled users to opt-in to user server-side printing. This is a followup which enables this functionality by default, with the ability to fallback not to do it with `--server-print=false`. 

/assign @smarterclayton @juanvallejo 

**Release note**:
```release-note
Enable server-side print in kubectl by default, with the ability to turn it off with --server-print=false
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants