summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2019-05-09 17:02:58 +0200
committerGitHub <noreply@github.com>2019-05-09 17:02:58 +0200
commitd8a065dab377a7bf48680d53d0839b2c7f62d003 (patch)
treec7912491d050ecac2eb673e341f726bdcd3d63c2
parent627dbd49c5a80146e5806797243b63d0bd157760 (diff)
parentd202e010af95b79230e5aaf88eb04168e73fac95 (diff)
downloadpodman-d8a065dab377a7bf48680d53d0839b2c7f62d003.tar.gz
podman-d8a065dab377a7bf48680d53d0839b2c7f62d003.tar.bz2
podman-d8a065dab377a7bf48680d53d0839b2c7f62d003.zip
Merge pull request #3087 from jwhonce/wip/version
Add information when running `podman version` on client
-rw-r--r--cmd/podman/version.go50
-rw-r--r--pkg/adapter/runtime.go8
-rw-r--r--pkg/adapter/runtime_remote.go37
-rw-r--r--test/e2e/version_test.go4
4 files changed, 81 insertions, 18 deletions
diff --git a/cmd/podman/version.go b/cmd/podman/version.go
index e964bdbb5..439a1cca6 100644
--- a/cmd/podman/version.go
+++ b/cmd/podman/version.go
@@ -2,6 +2,7 @@ package main
import (
"fmt"
+ "io"
"os"
"strings"
"text/tabwriter"
@@ -10,6 +11,7 @@ import (
"github.com/containers/buildah/pkg/formats"
"github.com/containers/libpod/cmd/podman/cliconfig"
"github.com/containers/libpod/libpod"
+ "github.com/containers/libpod/pkg/adapter"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
@@ -38,7 +40,7 @@ func init() {
// versionCmd gets and prints version info for version command
func versionCmd(c *cliconfig.VersionValues) error {
- output, err := libpod.GetVersion()
+ clientVersion, err := libpod.GetVersion()
if err != nil {
errors.Wrapf(err, "unable to determine version")
}
@@ -51,25 +53,49 @@ func versionCmd(c *cliconfig.VersionValues) error {
var out formats.Writer
switch versionOutputFormat {
case formats.JSONString:
- out = formats.JSONStruct{Output: output}
+ out = formats.JSONStruct{Output: clientVersion}
default:
- out = formats.StdoutTemplate{Output: output, Template: versionOutputFormat}
+ out = formats.StdoutTemplate{Output: clientVersion, Template: versionOutputFormat}
}
return formats.Writer(out).Out()
}
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
defer w.Flush()
- fmt.Fprintf(w, "Version:\t%s\n", output.Version)
- fmt.Fprintf(w, "RemoteAPI Version:\t%d\n", output.RemoteAPIVersion)
- fmt.Fprintf(w, "Go Version:\t%s\n", output.GoVersion)
- if output.GitCommit != "" {
- fmt.Fprintf(w, "Git Commit:\t%s\n", output.GitCommit)
+
+ if remote {
+ fmt.Fprintf(w, "Client:\n")
+ }
+ formatVersion(w, clientVersion)
+
+ if remote {
+ fmt.Fprintf(w, "\nService:\n")
+
+ runtime, err := adapter.GetRuntime(getContext(), nil)
+ if err != nil {
+ return errors.Wrapf(err, "could not get runtime")
+ }
+ defer runtime.Shutdown(false)
+
+ serviceVersion, err := runtime.GetVersion()
+ if err != nil {
+ return err
+ }
+ formatVersion(w, serviceVersion)
+ }
+ return nil
+}
+
+func formatVersion(writer io.Writer, version libpod.Version) {
+ fmt.Fprintf(writer, "Version:\t%s\n", version.Version)
+ fmt.Fprintf(writer, "RemoteAPI Version:\t%d\n", version.RemoteAPIVersion)
+ fmt.Fprintf(writer, "Go Version:\t%s\n", version.GoVersion)
+ if version.GitCommit != "" {
+ fmt.Fprintf(writer, "Git Commit:\t%s\n", version.GitCommit)
}
// Prints out the build time in readable format
- if output.Built != 0 {
- fmt.Fprintf(w, "Built:\t%s\n", time.Unix(output.Built, 0).Format(time.ANSIC))
+ if version.Built != 0 {
+ fmt.Fprintf(writer, "Built:\t%s\n", time.Unix(version.Built, 0).Format(time.ANSIC))
}
- fmt.Fprintf(w, "OS/Arch:\t%s\n", output.OsArch)
- return nil
+ fmt.Fprintf(writer, "OS/Arch:\t%s\n", version.OsArch)
}
diff --git a/pkg/adapter/runtime.go b/pkg/adapter/runtime.go
index 0d840d65b..21613c425 100644
--- a/pkg/adapter/runtime.go
+++ b/pkg/adapter/runtime.go
@@ -5,12 +5,13 @@ package adapter
import (
"bufio"
"context"
- "github.com/containers/libpod/cmd/podman/shared"
"io"
"io/ioutil"
"os"
"text/template"
+ "github.com/containers/libpod/cmd/podman/shared"
+
"github.com/containers/buildah"
"github.com/containers/buildah/imagebuildah"
"github.com/containers/buildah/pkg/parse"
@@ -392,3 +393,8 @@ func (r *LocalRuntime) GetPodsByStatus(statuses []string) ([]*libpod.Pod, error)
return pods, nil
}
+
+// GetVersion is an alias to satisfy interface{}
+func (r *LocalRuntime) GetVersion() (libpod.Version, error) {
+ return libpod.GetVersion()
+}
diff --git a/pkg/adapter/runtime_remote.go b/pkg/adapter/runtime_remote.go
index 8803a26fb..e86287462 100644
--- a/pkg/adapter/runtime_remote.go
+++ b/pkg/adapter/runtime_remote.go
@@ -9,12 +9,13 @@ import (
"fmt"
"io"
"io/ioutil"
- v1 "k8s.io/api/core/v1"
"os"
"strings"
"text/template"
"time"
+ v1 "k8s.io/api/core/v1"
+
"github.com/containers/buildah/imagebuildah"
"github.com/containers/image/docker/reference"
"github.com/containers/image/types"
@@ -415,19 +416,19 @@ func (r *LocalRuntime) Build(ctx context.Context, c *cliconfig.BuildValues, opti
Compression: string(options.Compression),
DefaultsMountFilePath: options.DefaultMountsFilePath,
Dockerfiles: dockerfiles,
- //Err: string(options.Err),
+ // Err: string(options.Err),
ForceRmIntermediateCtrs: options.ForceRmIntermediateCtrs,
Iidfile: options.IIDFile,
Label: options.Labels,
Layers: options.Layers,
Nocache: options.NoCache,
- //Out:
+ // Out:
Output: options.Output,
OutputFormat: options.OutputFormat,
PullPolicy: options.PullPolicy.String(),
Quiet: options.Quiet,
RemoteIntermediateCtrs: options.RemoveIntermediateCtrs,
- //ReportWriter:
+ // ReportWriter:
RuntimeArgs: options.RuntimeArgs,
SignaturePolicyPath: options.SignaturePolicyPath,
Squash: options.Squash,
@@ -611,7 +612,7 @@ func (r *LocalRuntime) InspectVolumes(ctx context.Context, c *cliconfig.VolumeIn
return varlinkVolumeToVolume(r, reply), nil
}
-//Volumes returns a slice of adapter.volumes based on information about libpod
+// Volumes returns a slice of adapter.volumes based on information about libpod
// volumes over a varlink connection
func (r *LocalRuntime) Volumes(ctx context.Context) ([]*Volume, error) {
reply, err := iopodman.GetVolumes().Call(r.Conn, []string{}, true)
@@ -907,3 +908,29 @@ func (r *LocalRuntime) GetContainersByContext(all bool, latest bool, namesOrIDs
}
return containers, nil
}
+
+// GetVersion returns version information from service
+func (r *LocalRuntime) GetVersion() (libpod.Version, error) {
+ version, goVersion, gitCommit, built, osArch, apiVersion, err := iopodman.GetVersion().Call(r.Conn)
+ if err != nil {
+ return libpod.Version{}, errors.Wrapf(err, "Unable to obtain server version information")
+ }
+
+ var buildTime int64
+ if built != "" {
+ t, err := time.Parse(time.RFC3339, built)
+ if err != nil {
+ return libpod.Version{}, nil
+ }
+ buildTime = t.Unix()
+ }
+
+ return libpod.Version{
+ RemoteAPIVersion: apiVersion,
+ Version: version,
+ GoVersion: goVersion,
+ GitCommit: gitCommit,
+ Built: buildTime,
+ OsArch: osArch,
+ }, nil
+}
diff --git a/test/e2e/version_test.go b/test/e2e/version_test.go
index f546158a9..35ee21e49 100644
--- a/test/e2e/version_test.go
+++ b/test/e2e/version_test.go
@@ -31,6 +31,7 @@ var _ = Describe("Podman version", func() {
})
It("podman version", func() {
+ SkipIfRemote()
session := podmanTest.Podman([]string{"version"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
@@ -38,6 +39,7 @@ var _ = Describe("Podman version", func() {
})
It("podman version --format json", func() {
+ SkipIfRemote()
session := podmanTest.Podman([]string{"version", "--format", "json"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
@@ -45,6 +47,7 @@ var _ = Describe("Podman version", func() {
})
It("podman version --format json", func() {
+ SkipIfRemote()
session := podmanTest.Podman([]string{"version", "--format", "{{ json .}}"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
@@ -52,6 +55,7 @@ var _ = Describe("Podman version", func() {
})
It("podman version --format GO template", func() {
+ SkipIfRemote()
session := podmanTest.Podman([]string{"version", "--format", "{{ .Version }}"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))