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 --output flag to kubeadm version #43850

Merged

Conversation

xilabao
Copy link
Contributor

@xilabao xilabao commented Mar 30, 2017

ref to kubectl #39858

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Mar 30, 2017
@k8s-reviewable
Copy link

This change is Reviewable

@k8s-ci-robot
Copy link
Contributor

Hi @xilabao. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with @k8s-bot ok to test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

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.

@k8s-github-robot k8s-github-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. release-note-label-needed labels Mar 30, 2017
Copy link
Member

@luxas luxas left a comment

Choose a reason for hiding this comment

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

I'd like some changes to this PR thanks

}
fmt.Fprintln(out, string(y))
default:
return errors.New("invalid output format: " + of)
Copy link
Member

Choose a reason for hiding this comment

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

nit, use fmt.Errorf like all other errors

if cmdutil.GetFlagBool(cmd, "short") {
fmt.Fprintf(out, "Kubeadm Version: %s\n", clientVersion.GitVersion)
} else {
fmt.Fprintf(out, "Kubeadm Version: %s\n", fmt.Sprintf("%#v", clientVersion))
Copy link
Member

Choose a reason for hiding this comment

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

nit: I prefer kubeadm version: foo. We don't write Kubeadm anywhere else, I've only seen it lowercased

Copy link
Member

Choose a reason for hiding this comment

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

also, why don't just: fmt.Fprintf(out, "kubeadm version: %#v\n", *v.ClientVersion)?

"k8s.io/kubernetes/pkg/version"
)

type Version struct {
ClientVersion *apimachineryversion.Info `json:"kubeadmVersion,omitempty" yaml:"kubeadmVersion,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

Why not clientVersion in json? I don't think the extra yaml field is required.

@@ -35,10 +44,39 @@ func NewCmdVersion(out io.Writer) *cobra.Command {
kubeadmutil.CheckErr(err)
},
}
cmd.Flags().BoolP("short", "", false, "Print just the version number.")
Copy link
Member

Choose a reason for hiding this comment

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

only print the version (tag|number)

"k8s.io/kubernetes/pkg/version"
)

type Version struct {
Copy link
Member

Choose a reason for hiding this comment

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

godoc comment

Copy link
Member

Choose a reason for hiding this comment

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

ping, please add a godoc comment about this struct

return cmd
}

func RunVersion(out io.Writer, cmd *cobra.Command) error {
fmt.Fprintf(out, "kubeadm version: %#v\n", version.Get())
v := Version{}
Copy link
Member

Choose a reason for hiding this comment

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

v := Version{
    ClientVersion: &version.Get(),
}

and then use v.ClientVersion

@luxas luxas changed the title add -- output to kubeadm version add --output flag to kubeadm version Mar 31, 2017
@luxas luxas self-assigned this Mar 31, 2017
@luxas luxas added release-note-none Denotes a PR that doesn't merit a release note. and removed release-note-label-needed labels Mar 31, 2017
@xilabao xilabao force-pushed the add-output-to-kubeadm-version branch from e0aa692 to 78b017b Compare April 3, 2017 03:12
@xilabao
Copy link
Contributor Author

xilabao commented Apr 3, 2017

Done. @luxas

"k8s.io/kubernetes/pkg/version"
)

type Version struct {
Copy link
Member

Choose a reason for hiding this comment

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

ping, please add a godoc comment about this struct

switch of := cmdutil.GetFlagString(cmd, "output"); of {
case "":
if cmdutil.GetFlagBool(cmd, "short") {
fmt.Fprintf(out, "kubeadm version: %s\n", v.clientVersion.GitVersion)
Copy link
Member

Choose a reason for hiding this comment

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

if the user really wants the short version, we should probably drop kubeadm version here

@@ -35,10 +44,39 @@ func NewCmdVersion(out io.Writer) *cobra.Command {
kubeadmutil.CheckErr(err)
},
}
cmd.Flags().BoolP("short", "", false, "only print the version (tag|number)")
cmd.Flags().StringP("output", "o", "", "output format, options available are yaml and json")
Copy link
Member

Choose a reason for hiding this comment

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

didn't check how kubectl does it, but to be -o short would be better than two flags

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should we keep the same format with kubectl? I think your solution also make sense.

"k8s.io/kubernetes/pkg/version"
)

type Version struct {
// clientVersion contains the kubeadm version.
clientVersion *apimachineryversion.Info `json:"kubeadmVersion,omitempty" yaml:"kubeadmVersion,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

ping: why not clientVersion here? Also the yaml statement is unneeded, we only do json everywhere else.
(the yaml parser will work anyway)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

someone else may want the yaml statement #43750

Copy link
Member

Choose a reason for hiding this comment

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

But the yaml statement here defaults to the json value; the duplication here is unneded.
I think this should just be: clientVersion *apimachineryversion.Info json:"clientVersion"`

Copy link
Member

@luxas luxas left a comment

Choose a reason for hiding this comment

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

please address the three comments that are left

"k8s.io/kubernetes/pkg/version"
)

type Version struct {
// clientVersion contains the kubeadm version.
clientVersion *apimachineryversion.Info `json:"kubeadmVersion,omitempty" yaml:"kubeadmVersion,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

But the yaml statement here defaults to the json value; the duplication here is unneded.
I think this should just be: clientVersion *apimachineryversion.Info json:"clientVersion"`

@xilabao xilabao force-pushed the add-output-to-kubeadm-version branch from 78b017b to cc27c66 Compare April 5, 2017 11:44
Copy link
Member

@luxas luxas left a comment

Choose a reason for hiding this comment

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

Ok this LGTM now.

But I think we should discuss -o short vs --short. I'm in favor of -o short

cc @jbeda @philips @kubernetes/sig-cli-pr-reviews

@luxas
Copy link
Member

luxas commented Apr 5, 2017

(but hmm, I'd love some tests for this, please CLI tests for this in cmd/kubeadm/app/test)
After that, real LGTM.

/approve

@k8s-github-robot k8s-github-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 5, 2017
@grodrigues3 grodrigues3 added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Apr 5, 2017
@dmmcquay
Copy link
Contributor

@xilabao Can you add tests and I'll apply my lgtm.

@grodrigues3
Copy link
Contributor

@k8s-bot ok to test

@k8s-ci-robot k8s-ci-robot removed the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Apr 13, 2017
@xilabao xilabao force-pushed the add-output-to-kubeadm-version branch 2 times, most recently from 434dec8 to 38e331e Compare April 17, 2017 05:08
@xilabao
Copy link
Contributor Author

xilabao commented Apr 17, 2017

@k8s-bot verify test this

@dmmcquay
Copy link
Contributor

@xilabao Please fix errors with verification.

@luxas do we still need to discuss the -o short vs --short?

@luxas
Copy link
Member

luxas commented Apr 17, 2017 via email

@xilabao xilabao force-pushed the add-output-to-kubeadm-version branch from 38e331e to 93ab6fd Compare April 18, 2017 03:07
@dmmcquay
Copy link
Contributor

I prefer -o short as well.

@xilabao xilabao force-pushed the add-output-to-kubeadm-version branch 3 times, most recently from 6101c6c to 6039f4c Compare April 18, 2017 09:47
@dmmcquay
Copy link
Contributor

@xilabao I think this is shaping up nicely.

Do you mind writing tests that capture the output of running the test cmd and running a regex to make sure the output is sane? Something like this: https://github.com/kubernetes/kubernetes/blob/master/cmd/kubeadm/test/cmd/token_test.go

@xilabao xilabao force-pushed the add-output-to-kubeadm-version branch from 6039f4c to d26182f Compare April 19, 2017 03:24
@k8s-github-robot k8s-github-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Apr 19, 2017
@xilabao
Copy link
Contributor Author

xilabao commented Apr 19, 2017

@dmmcquay PTAL

Copy link
Contributor

@dmmcquay dmmcquay left a comment

Choose a reason for hiding this comment

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

This looks much better. Just small comment about the tests.

const (
ShortExpectedRegex = "^v.+\n$"
JsonExpectedRegex = "^{\"kubeadmVersion\":{\"major\":\".+\",\"minor\":\".+\",\"gitVersion\":\".+\",\"gitCommit\":\".+\",\"gitTreeState\":\".+\",\"buildDate\":\".+\",\"goVersion\":\".+\",\"compiler\":\".+\",\"platform\":\".+\"}}\n$"
YamlExpectedRegex = "^kubeadmVersion:\n\\s+buildDate:.+\n\\s+compiler:.+\n\\s+gitCommit:.+\n\\s+gitTreeState:.+\n\\s+gitVersion:.+\n\\s+goVersion:.+\n\\s+major:.+\n\\s+minor:.+\n\\s+platform:.+\n\n$"
Copy link
Contributor

Choose a reason for hiding this comment

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

I think instead of having a regex for json and yaml, you could just marshal it and check it that way? The json and yaml regex seems a bit intense.

@xilabao xilabao force-pushed the add-output-to-kubeadm-version branch from d26182f to bb15fec Compare April 20, 2017 03:14
@xilabao
Copy link
Contributor Author

xilabao commented Apr 20, 2017

@dmmcquay PTAL

@dmmcquay
Copy link
Contributor

/lgtm

thanks for going back and forth on this one.

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 20, 2017
Copy link
Member

@luxas luxas left a comment

Choose a reason for hiding this comment

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

LGTM other than kubeadmVersion, I still think that should be clientVersion

cc @kubernetes/sig-cli-pr-reviews

"k8s.io/kubernetes/pkg/version"
)

// Version provides the version information of kubeadm.
type Version struct {
ClientVersion *apimachineryversion.Info `json:"kubeadmVersion"`
Copy link
Member

Choose a reason for hiding this comment

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

still I don't understand why this is kubeadmVersion instead of clientVersion?
kubeadm is a client and I think it's easiest if it has the same schema as kubectl

Copy link
Contributor Author

Choose a reason for hiding this comment

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

kubectl version -o json use clientVersion to keep consistent with kubectl version . I saw the output of kubeadm version is kubeadm version... Should we change all of them?

Copy link
Member

Choose a reason for hiding this comment

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

I mean that I think this line should be

ClientVersion *apimachineryversion.Info `json:"clientVersion"`

@luxas luxas added the do-not-merge DEPRECATED. Indicates that a PR should not merge. Label can only be manually applied/removed. label Apr 20, 2017
@xilabao xilabao force-pushed the add-output-to-kubeadm-version branch from bb15fec to 3719840 Compare April 26, 2017 08:51
@k8s-github-robot k8s-github-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 26, 2017
Copy link
Member

@luxas luxas left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@luxas
Copy link
Member

luxas commented Apr 26, 2017

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 26, 2017
@luxas luxas removed the do-not-merge DEPRECATED. Indicates that a PR should not merge. Label can only be manually applied/removed. label Apr 26, 2017
@k8s-github-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dmmcquay, luxas, xilabao

Needs approval from an approver in each of these OWNERS Files:

You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@k8s-github-robot
Copy link

Automatic merge from submit-queue

@k8s-github-robot k8s-github-robot merged commit eb0bc85 into kubernetes:master Apr 26, 2017
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

7 participants