-
Notifications
You must be signed in to change notification settings - Fork 40.1k
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
add jsonpath to kubectl #12202
Conversation
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)) |
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.
if err := j.Parse(string(tmpl)); err != nil {
return nil, err
}
Small comments, basically LGTM. You need to run |
I would add the jsonpath documentation to |
Can something exercise this in |
579246e
to
daa36df
Compare
@derekwaynecarr Yes, I will add some tests to |
@@ -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 {} |
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.
Is it too late to argue for -o jsonpath="template string" and -o template="template string".
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.
Not too late. See:
https://github.com/GoogleCloudPlatform/kubernetes/pull/12220/files#r36381964
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.
that's fine with me too.
@daizuozhuo do you want to do a separate PR to do that?
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.
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.
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.
Yes, I would do this in a separate RP.
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.
@bgrant0607 Good Suggestions!
The command-line args LGTM. Please address comments from @brendandburns and @derekwaynecarr. |
LGTM. Needs rebase due to the grand rename. |
@brendandburns Rebased |
@derekwaynecarr How to make hack/test-cmd.sh run? It reports error like:
|
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. |
I will change it to |
@brendandburns I added |
54183c2
to
b786fc9
Compare
@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}") |
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 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.
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.
Thanks. I changed it and moved several other test function into the table.
I still see one comment that hasn't been addressed, can you take a look at it? |
@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) |
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.
@brendandburns print rawTemplate here
cc @kubernetes/kubectl |
LGTM |
Rebase needed, removing LGTM for now |
@saad-ali Rebased, thanks. |
Tests are flaking:
|
@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. |
@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?