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

add jsonpath to kubectl #12202

Merged
merged 2 commits into from
Aug 20, 2015
Merged

add jsonpath to kubectl #12202

merged 2 commits into from
Aug 20, 2015

Conversation

daizuozhuo
Copy link
Contributor

@brendandburns I add jsonpath as an output option for kubectl. And I think I should make a page to tell people the jsonpath syntax. Where should I put it?

@k8s-bot
Copy link

k8s-bot commented Aug 4, 2015

Can one of the admins verify that this patch is reasonable to test? (reply "ok to test", or if you trust the user, reply "add to whitelist")

If this message is too spammy, please complain to ixdy.


func NewJSONPathPrinter(tmpl []byte) (*JSONPathPrinter, error) {
j := jsonpath.New("out")
err := j.Parse(string(tmpl))
Copy link
Contributor

Choose a reason for hiding this comment

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

if err := j.Parse(string(tmpl)); err != nil {
   return nil, err
}

@brendandburns
Copy link
Contributor

Small comments, basically LGTM.

You need to run ./hack/run-gendoc.sh to regenerate kubectl docs.

@brendandburns
Copy link
Contributor

I would add the jsonpath documentation to docs/user-guide/... and add a link in the kubectl help docs.

@derekwaynecarr
Copy link
Member

Can something exercise this in hack/test-cmd.sh?

@daizuozhuo daizuozhuo force-pushed the kubectl branch 2 times, most recently from 579246e to daa36df Compare August 6, 2015 00:56
@daizuozhuo
Copy link
Contributor Author

@derekwaynecarr Yes, I will add some tests to hack/test.cmd.sh.

@@ -69,10 +69,11 @@ $ kubectl expose rc streamer --port=4100 --protocol=udp --name=video-stream
--dry-run=false: If true, only print the object that would be sent, without creating it.
--generator="service/v2": The name of the API generator to use. There are 2 generators: 'service/v1' and 'service/v2'. The only difference between them is that service port in v1 is named 'default', while it is left unnamed in v2. Default is 'service/v2'.
-h, --help=false: help for expose
-j, --jsonpath="": JSONPath template string to use when -o=jsonpath. The jsonpath template is composed of jsonpath expressions enclosed by {}
Copy link
Member

Choose a reason for hiding this comment

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

Is it too late to argue for -o jsonpath="template string" and -o template="template string".

Copy link
Member

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.

that's fine with me too.

@daizuozhuo do you want to do a separate PR to do that?

Copy link
Member

Choose a reason for hiding this comment

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

If you want to do that as a separate PR, then in this one we should:

a) Keep the jsonpath output format
b) Drop the new jsonpath flag and reuse the existing template flag, just interpreting it based on the requested output format.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I would do this in a separate RP.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bgrant0607 Good Suggestions!

@bgrant0607
Copy link
Member

The command-line args LGTM. Please address comments from @brendandburns and @derekwaynecarr.

@brendandburns
Copy link
Contributor

LGTM. Needs rebase due to the grand rename.

@daizuozhuo
Copy link
Contributor Author

@brendandburns Rebased

@daizuozhuo
Copy link
Contributor Author

@derekwaynecarr How to make hack/test-cmd.sh run? It reports error like:

/Users/daizuozhuo/goproj/src/github.com/GoogleCloudPlatform/kubernetes/_output/local/bin/darwin/amd64/kubelet --really-crash-for-testing=true --root-dir=/tmp/kubelet.31768 --cert-dir=/var/folders/81/n6gk7mk1279_b4x2vqdcp1680000gn/T/ --docker-endpoint=fake:// --hostname-override=127.0.0.1 --address=127.0.0.1 --port=10250 --healthz-port=10248
I0810 11:25:08.464685   31811 plugins.go:70] No cloud provider specified.
W0810 11:25:08.464920   31811 server.go:407] setting OOM scores is unsupported in this build
W0810 11:25:08.465017   31811 server.go:639] No api server defined - no events will be sent to API server.
failed to create kubelet: cAdvisor is unsupported in this build
!!! [0810 11:25:20] Timed out waiting for kubelet(masterless) to answer at http://127.0.0.1:10248/healthz; tried 25 waiting 0.5 between each
!!! Error in ./test-cmd.sh:121
  'return 1' exited with status 1
Call stack:
  1: ./test-cmd.sh:121 main(...)

@daizuozhuo
Copy link
Contributor Author

Comments are addressed. By the way, I noticed that hack/test-cmd.sh is not working in Mac OS, So I tested it in Linux.

@daizuozhuo
Copy link
Contributor Author

I will change it to -o go-template=... , -o go-template-file=... and -o jsonpath=... in another PR.

@daizuozhuo
Copy link
Contributor Author

@brendandburns I added jsonpath.md. Please comment if it has any problem.

@daizuozhuo daizuozhuo force-pushed the kubectl branch 2 times, most recently from 54183c2 to b786fc9 Compare August 16, 2015 13:49
@daizuozhuo
Copy link
Contributor Author

@brendandburns @bgrant0607 When will it be merged?

@@ -164,6 +164,23 @@ func TestPrintTemplate(t *testing.T) {
}
}

func TestPrintJSONPath(t *testing.T) {
buf := bytes.NewBuffer([]byte{})
printer, found, err := GetPrinter("jsonpath", "{.metadata.name}")
Copy link
Member

Choose a reason for hiding this comment

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

I understand that this is patterned after TestPrintTemplate, but what I'd like to see is a table-driven test that exercises more cases than just a single field.

An example of a table-driven test:
https://github.com/kubernetes/kubernetes/blob/master/pkg/kubectl/generate_test.go#L52

The test could be expanded in a subsequent PR, though.

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. I changed it and moved several other test function into the table.

@brendandburns
Copy link
Contributor

I still see one comment that hasn't been addressed, can you take a look at it?

@daizuozhuo
Copy link
Contributor Author

@brendandburns I use rawTemplate to print debug message now.

}
if err = j.JSONPath.Execute(w, out); err != nil {
fmt.Fprintf(w, "Error executing template: %v\n", err)
fmt.Fprintf(w, "template was:\n\t%v\n", j.rawTemplate)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@brendandburns print rawTemplate here

@bgrant0607
Copy link
Member

cc @kubernetes/kubectl

@brendandburns brendandburns added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 19, 2015
@brendandburns
Copy link
Contributor

LGTM

@saad-ali
Copy link
Member

Rebase needed, removing LGTM for now

@saad-ali saad-ali removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 19, 2015
@daizuozhuo
Copy link
Contributor Author

@saad-ali Rebased, thanks.

@saad-ali saad-ali added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 20, 2015
saad-ali added a commit that referenced this pull request Aug 20, 2015
@saad-ali saad-ali merged commit 489e75e into kubernetes:master Aug 20, 2015
@smarterclayton
Copy link
Contributor

Tests are flaking:

ok k8s.io/kubernetes/pkg/util/flushwriter   1.041s  coverage: 100.0% of statements
--- FAIL: TestKubenates (0.02 seconds)
jsonpath_test.go:47: in recursive name, expect to get "127.0.0.1 127.0.0.2 myself e2e", got "myself e2e 127.0.0.1 127.0.0.2"
FAIL
coverage: 90.2% of statements
FAIL k8s.io/kubernetes/pkg/util/jsonpath 0.129s
ok k8s.io/kubernetes/pkg/util/mount 1.033s coverage: 25.5% of statements
ok k8s.io/kubernetes/pkg/util/config 1.069s coverage: 92.9% of statements
ok k8s.io/kubernetes/pkg/storage    1.284s  coverage: 89.0% of statements

@daizuozhuo
Copy link
Contributor Author

@smarterclayton Since the JSON input is a map, JSONPath may iterate it in unknown order. Sorry, I will change the test method in next PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/kubectl lgtm "Looks good to me", indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants