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 a short and a json output option for kubectl version #39427

Closed
n-rook opened this issue Jan 4, 2017 · 7 comments · Fixed by #39858
Closed

Add a short and a json output option for kubectl version #39427

n-rook opened this issue Jan 4, 2017 · 7 comments · Fixed by #39858
Labels
area/kubectl sig/cli Categorizes an issue or PR as relevant to SIG CLI.

Comments

@n-rook
Copy link

n-rook commented Jan 4, 2017

Is this a request for help? (If yes, you should use our troubleshooting guide and community support channels, see http://kubernetes.io/docs/troubleshooting/.):
no

What keywords did you search in Kubernetes issues before filing this one? (If you have found any duplicates, you should instead reply there.):
"kubectl version", "kubectl version" json


Is this a BUG REPORT or FEATURE REQUEST? (choose one): Feature request

Kubernetes version (use kubectl version):
$ kubectl version --client
Client Version: version.Info{Major:"1", Minor:"4", GitVersion:"v1.4.6", GitCommit:"e569a27d02001e343cb68086bc06d47804f62af6", GitTreeState:"clean", BuildDate:"2016-11-12T05:22:15Z", GoVersion:"go1.7.1", Compiler:"gc", Platform:"darwin/amd64"}

Environment:

  • Cloud provider or hardware configuration:
    GKE
  • OS (e.g. from /etc/os-release):
    MacOS 10.12.2

I find it difficult to parse the output of kubectl version programmatically. I have to use a YAML parser to do it. I'd prefer to use JSON, or to be given just the string v1.4.6 and asked to parse it with a regex.

This is obviously a relatively low-priority request.

@alejandroEsc
Copy link
Contributor

I wouldnt mind helping out on this, if there are no objections?

@ReneSaenz
Copy link
Contributor

@alejandroEsc are you working on this? If not, I would like to work on it.

@alejandroEsc
Copy link
Contributor

@ReneSaenz I plan to, but if i'll keep you posted if i get too delayed.

@ReneSaenz
Copy link
Contributor

@alejandroEsc How can I direct message you?

@alejandroEsc
Copy link
Contributor

@ReneSaenz didnt see this till now, felt bad i had not kept up on this so i decided to just push through it. If my email is not available in my profile, please let me know, otherwise jaescobar.cell AT gmail would be the best way to contact me.

alejandroEsc added a commit to alejandroEsc/kubernetes that referenced this issue Jan 13, 2017
@n-rook
Copy link
Author

n-rook commented Jan 13, 2017

Thanks!

@alejandroEsc
Copy link
Contributor

alejandroEsc commented Jan 13, 2017

@n-rook
Included below are some examples. Let me know what you think, my only concern is the the original output of kubectl version included the key Client Version and then the object type version.Info{ ... } which is a little strange. Note the output flag is optional so we don't break previous behavior and contract, which is now baked and part of e2e testing.

here are the couple of samples:

./cluster/kubectl.sh version --output json | toJson
{
    "Client Version": {
        "buildDate": "2017-01-13T19:38:11Z",
        "compiler": "gc",
        "gitCommit": "e52615ddd2f80ebf62c5dce82f2b720b8b786223",
        "gitTreeState": "dirty",
        "gitVersion": "v1.6.0-alpha.0.3197+e52615ddd2f80e-dirty",
        "goVersion": "go1.7.4",
        "major": "1",
        "minor": "6+",
        "platform": "darwin/amd64"
    },
    "Server Version": {
        "buildDate": "2017-01-13T19:38:11Z",
        "compiler": "gc",
        "gitCommit": "e52615ddd2f80ebf62c5dce82f2b720b8b786223",
        "gitTreeState": "dirty",
        "gitVersion": "v1.6.0-alpha.0.3197+e52615ddd2f80e-dirty",
        "goVersion": "go1.7.4",
        "major": "1",
        "minor": "6+",
        "platform": "darwin/amd64"
    }
}
./cluster/kubectl.sh version --output yaml
{v1.6.0-alpha.0.3197+e52615ddd2f80e-dirty v1.6.0-alpha.0.3197+e52615ddd2f80e-dirty}
Client Version:
  buildDate: 2017-01-13T19:38:11Z
  compiler: gc
  gitCommit: e52615ddd2f80ebf62c5dce82f2b720b8b786223
  gitTreeState: dirty
  gitVersion: v1.6.0-alpha.0.3197+e52615ddd2f80e-dirty
  goVersion: go1.7.4
  major: "1"
  minor: 6+
  platform: darwin/amd64
Server Version:
  buildDate: 2017-01-13T19:38:11Z
  compiler: gc
  gitCommit: e52615ddd2f80ebf62c5dce82f2b720b8b786223
  gitTreeState: dirty
  gitVersion: v1.6.0-alpha.0.3197+e52615ddd2f80e-dirty
  goVersion: go1.7.4
  major: "1"
  minor: 6+
  platform: darwin/amd64

alejandroEsc added a commit to alejandroEsc/kubernetes that referenced this issue Jan 17, 2017
… either json or yaml.

updating with PR changes requested.
latest changes to having short for human readable only, and error cases moved a bit to the end.
@bgrant0607 bgrant0607 added area/kubectl sig/cli Categorizes an issue or PR as relevant to SIG CLI. labels Mar 9, 2017
alejandroEsc added a commit to alejandroEsc/kubernetes that referenced this issue Mar 28, 2017
… either json or yaml.

updating with PR changes requested.

latest changes to having short for human readable only, and error cases moved a bit to the end.

rebase fixes

latest pr. changes.

small change moving return nil out of switch.

updated the nil check for the error in the humanreadable case.

more optimization in humanreadable code.

pushed up current test changes, this is purely temporary

finished writing tests

updated test and function names.

changed output extensions from .sh to output.

updated version, version struct now just called Version and not VersionObj.

made a few changes to testing.

fixed testing issues, created better test and cleanup

go format change.
alejandroEsc added a commit to alejandroEsc/kubernetes that referenced this issue Mar 28, 2017
… either json or yaml.

updating with PR changes requested.

latest changes to having short for human readable only, and error cases moved a bit to the end.

rebase fixes

latest pr. changes.

small change moving return nil out of switch.

updated the nil check for the error in the humanreadable case.

more optimization in humanreadable code.

pushed up current test changes, this is purely temporary

finished writing tests

updated test and function names.

changed output extensions from .sh to output.

updated version, version struct now just called Version and not VersionObj.

made a few changes to testing.

fixed testing issues, created better test and cleanup

go format change.
k8s-github-robot pushed a commit that referenced this issue Mar 28, 2017
Automatic merge from submit-queue

addressing issue #39427 adding a flag --output to 'kubectl version'

**What this PR does / why we need it**:
Addressing Issue #39427 we all

**Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes #39427 


**Release note**:
```
kubectl version has new flag --output (=json or yaml) allowing result of the command to be parsed in either json format or yaml. 
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/kubectl sig/cli Categorizes an issue or PR as relevant to SIG CLI.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants