kn version command to list supported serving versions and APIs (#370)

Fixes #369

 - Replace `Dependencies:` with `Support:`
 - Add list of supported Serving versions kn can work with
 - Add list of supported Serving APIs kn can work with

 ```
 ✗ ./kn version
Version:      v20190816-local-e36089f-dirty
Build Date:   2019-08-16 13:08:26
Git Revision: e36089f
Support:
- Serving: v0.8.0  v0.7.1
- API(s):  v1alpha1

 ```
This commit is contained in:
Navid Shaikh 2019-08-20 03:55:59 +05:30 committed by Knative Prow Robot
parent e36089f260
commit dccaf36611
3 changed files with 45 additions and 21 deletions

View File

@ -46,6 +46,9 @@
| Support traffic splitting and tagging targets
| https://github.com/knative/client/pull/345[#345]
| 🎁
| kn version command shows supported Serving and API versions
| https://github.com/knative/client/pull/370[#370]
|===

View File

@ -16,6 +16,7 @@ package commands
import (
"fmt"
"strings"
"github.com/spf13/cobra"
)
@ -25,6 +26,18 @@ var BuildDate string
var GitRevision string
var ServingVersion string
// VersionsAPIs hold the list of supported versions and APIs for component kn can work with
type VersionsAPIs struct {
Versions, APIs []string
}
// update this var as we increase the serving version in go.mod
var knServingDep = "v0.8.0"
var supportMatrix = map[string]*VersionsAPIs{
knServingDep: {[]string{"v0.8.0", "v0.7.1"}, []string{"v1alpha1"}},
}
// NewVersionCommand implements 'kn version' command
func NewVersionCommand(p *KnParams) *cobra.Command {
versionCmd := &cobra.Command{
Use: "version",
@ -33,8 +46,15 @@ func NewVersionCommand(p *KnParams) *cobra.Command {
fmt.Printf("Version: %s\n", Version)
fmt.Printf("Build Date: %s\n", BuildDate)
fmt.Printf("Git Revision: %s\n", GitRevision)
fmt.Printf("Dependencies:\n")
fmt.Printf("- serving: %s\n", ServingVersion)
fmt.Printf("Support:\n")
if m, ok := supportMatrix[ServingVersion]; ok {
fmt.Printf("- Serving: %s\n", strings.Join(m.Versions, " "))
fmt.Printf("- API(s): %s\n", strings.Join(m.APIs, " "))
} else {
// ensure the go build works when we update,
// but version command tests fails to prevent shipping
fmt.Printf("- Serving: %s\n", ServingVersion)
}
return nil
},
}

View File

@ -24,24 +24,24 @@ import (
)
type versionOutput struct {
Version string
BuildDate string
GitRevision string
ServingVersion string
Version string
BuildDate string
GitRevision string
VersionsAPIs *VersionsAPIs
}
var versionOutputTemplate = `Version: {{.Version}}
Build Date: {{.BuildDate}}
Git Revision: {{.GitRevision}}
Dependencies:
- serving: {{.ServingVersion}}
Support:
- Serving: {{index .VersionsAPIs.Versions 0}} {{index .VersionsAPIs.Versions 1}}
- API(s): {{index .VersionsAPIs.APIs 0}}
`
const (
fakeVersion = "fake-version"
fakeBuildDate = "fake-build-date"
fakeGitRevision = "fake-git-revision"
fakeServingVersion = "fake-serving-version"
fakeVersion = "fake-version"
fakeBuildDate = "fake-build-date"
fakeGitRevision = "fake-git-revision"
)
func TestVersion(t *testing.T) {
@ -55,14 +55,14 @@ func TestVersion(t *testing.T) {
Version = fakeVersion
BuildDate = fakeBuildDate
GitRevision = fakeGitRevision
ServingVersion = fakeServingVersion
ServingVersion = knServingDep
expectedVersionOutput = genVersionOuput(t, versionOutputTemplate,
versionOutput{
Version: fakeVersion,
BuildDate: fakeBuildDate,
GitRevision: fakeGitRevision,
ServingVersion: fakeServingVersion})
fakeVersion,
fakeBuildDate,
fakeGitRevision,
supportMatrix[ServingVersion]})
knParams = &KnParams{}
versionCmd = NewVersionCommand(knParams)
@ -78,26 +78,27 @@ func TestVersion(t *testing.T) {
assert.Assert(t, versionCmd.RunE != nil)
})
t.Run("prints version, build date, git revision, and serving version string", func(t *testing.T) {
t.Run("prints version, build date, git revision, supported serving version and APIs", func(t *testing.T) {
setup()
CaptureStdout(t)
defer ReleaseStdout(t)
err := versionCmd.RunE(nil, []string{})
assert.Assert(t, err == nil)
assert.NilError(t, err)
assert.Equal(t, ReadStdout(t), expectedVersionOutput)
})
}
// Private
func genVersionOuput(t *testing.T, templ string, vOutput versionOutput) string {
tmpl, err := template.New("versionOutput").Parse(versionOutputTemplate)
assert.Assert(t, err == nil)
assert.NilError(t, err)
buf := bytes.Buffer{}
err = tmpl.Execute(&buf, vOutput)
assert.Assert(t, err == nil)
assert.NilError(t, err)
return buf.String()
}