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

Print Stack API and Kubernetes versions in version command #898

Merged

Conversation

silvin-lubecki
Copy link
Contributor

@silvin-lubecki silvin-lubecki commented Feb 22, 2018

- What I did
This pull request adds the Stack API resolution mechanism and print the selected version into the version command. It lays the foundation for a following one #899, which adds the v1beta2 version of the Stack API. It's extracted from the PR #854 .

- How I did it

  • Resolve Stack API using Kubernetes discovering API
  • Refactor Kubernetes flags parsing

- How to verify it
Execute a docker version command against latest docker for mac, it should output at the end:

 Orchestrator:
   Kubernetes:  v1.9.2
   Stack:       v1beta1

- Description for the changelog

  • Add Stack API and Kubernetes versions in version command

- A picture of a cute animal (not mandatory but encouraged)

image

@codecov-io
Copy link

codecov-io commented Feb 22, 2018

Codecov Report

Merging #898 into master will decrease coverage by 0.05%.
The diff coverage is 23.91%.

@@            Coverage Diff            @@
##           master    #898      +/-   ##
=========================================
- Coverage   53.26%   53.2%   -0.06%     
=========================================
  Files         258     259       +1     
  Lines       16357   16415      +58     
=========================================
+ Hits         8712    8734      +22     
- Misses       7081    7117      +36     
  Partials      564     564

{{- if .KubernetesOK}}{{with .Kubernetes}}
Orchestrator:
Kubernetes: {{.Kubernetes}}
Stack: {{.StackAPI}}{{- end}}{{end}}`
Copy link
Collaborator

Choose a reason for hiding this comment

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

What if there is multiple API version available ? Should we display sthg a bit like docker api versions (version negociated vs min version) or a list of version, of just the version used ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't see the benefits of listing all the versions? At least with just the version used, there is no ambiguity.

)

// GetAPIVersion returns the most recent stack API installed.
func GetAPIVersion(kubeConfig *restclient.Config) (StackVersion, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We may want to use GetStackAPIVersion here, as it's only the Stack api version we're getting here. We could have more api extension in the future, and kubernetes.GetAPIVersion kinda makes think it's the kubernetes api (server) version.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

@silvin-lubecki
Copy link
Contributor Author

@vdemeester PTAL

Copy link
Collaborator

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

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

LGTM 🐯

Copy link
Contributor

@dnephin dnephin left a comment

Choose a reason for hiding this comment

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

Thanks! This is looking good, just a couple small nits on the template format.

clients, err := kubernetes.NewForConfig(kubeConfig)
if err != nil {
return "", err
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This function could accept clients instead of a config. The client is being created twice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, fixed.


func getKubernetesServerVersion(kubeConfig *restclient.Config) string {
version := "Unknown"
kubeClient, err := kubernetesClient.NewForConfig(kubeConfig)
Copy link
Contributor

Choose a reason for hiding this comment

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

Could accept kubeClient instead of config, so the client can be passed to GetStackAPIVersion as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

{{- end}}{{- end}}
{{- if .KubernetesOK}}{{with .Kubernetes}}
Orchestrator:
Kubernetes: {{.Kubernetes}}
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor naming nit: I assume in the future we will need to change "Server" to "Engine".

Maybe this should be formatted as:

Kubernetes:
  Version: {{.Kubernetes}}
  Stack API: {{.StackAPI}}

I think that would be more consistent with the other sections. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My first thought was to generalize this section to all orchestrators, but finally it seems that we don't have much things to print from swarm, and also this section seems very specific to Kubernetes. So I'm with renaming it.

{{- if .KubernetesOK}}{{with .Kubernetes}}
Orchestrator:
Kubernetes: {{.Kubernetes}}
Stack: {{.StackAPI}}{{- end}}{{end}}`
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor formatting nit: the {{- end}}{{end}} can go on a new line so that the template reads a bit better.

- in a template means "remove all whitespace before this token, so the trailing newline wont exist in the final rendered string.

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 wasn't aware of that, fixed.

@@ -20,7 +20,7 @@ func newDeployCommand(dockerCli command.Cli) *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
opts.Namespace = args[0]
if dockerCli.ClientInfo().HasKubernetes() {
kli, err := kubernetes.WrapCli(dockerCli, cmd)
kli, err := kubernetes.WrapCli(dockerCli, kubernetes.NewOptions(cmd.Flags()))
Copy link
Contributor

Choose a reason for hiding this comment

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

I hope that in the future when we add kube to more commands we can have this accept an Options struct instead of cmd.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.

Ok I'll refactor that in a future PR.

* Resolve Stack API using Kubernetes discovering API
* Refactor Kubernetes flags parsing

Signed-off-by: Silvin Lubecki <silvin.lubecki@docker.com>
@silvin-lubecki
Copy link
Contributor Author

PTAL @dnephin

Copy link
Contributor

@dnephin dnephin left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM

@vdemeester vdemeester merged commit 2851c00 into docker:master Feb 27, 2018
@GordonTheTurtle GordonTheTurtle added this to the 18.04.0 milestone Feb 27, 2018
@silvin-lubecki silvin-lubecki deleted the add-stack-to-version-command branch February 28, 2018 22:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants