mirror of
https://github.com/containers/podman.git
synced 2025-06-21 17:38:12 +08:00
Merge pull request #6148 from jwhonce/wip/version
V2 Implement tunnelled podman version
This commit is contained in:
@ -8,12 +8,10 @@ import (
|
|||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/containers/buildah/pkg/formats"
|
|
||||||
"github.com/containers/libpod/cmd/podman/registry"
|
"github.com/containers/libpod/cmd/podman/registry"
|
||||||
"github.com/containers/libpod/cmd/podman/validate"
|
"github.com/containers/libpod/cmd/podman/validate"
|
||||||
"github.com/containers/libpod/libpod/define"
|
"github.com/containers/libpod/libpod/define"
|
||||||
"github.com/containers/libpod/pkg/domain/entities"
|
"github.com/containers/libpod/pkg/domain/entities"
|
||||||
"github.com/pkg/errors"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -23,18 +21,10 @@ var (
|
|||||||
Args: validate.NoArgs,
|
Args: validate.NoArgs,
|
||||||
Short: "Display the Podman Version Information",
|
Short: "Display the Podman Version Information",
|
||||||
RunE: version,
|
RunE: version,
|
||||||
Annotations: map[string]string{
|
|
||||||
registry.ParentNSRequired: "",
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
versionFormat string
|
versionFormat string
|
||||||
)
|
)
|
||||||
|
|
||||||
type versionStruct struct {
|
|
||||||
Client define.Version
|
|
||||||
Server define.Version
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.Commands = append(registry.Commands, registry.CliCommand{
|
registry.Commands = append(registry.Commands, registry.CliCommand{
|
||||||
Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
|
Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
|
||||||
@ -45,68 +35,44 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func version(cmd *cobra.Command, args []string) error {
|
func version(cmd *cobra.Command, args []string) error {
|
||||||
var (
|
versions, err := registry.ContainerEngine().Version(registry.Context())
|
||||||
v versionStruct
|
|
||||||
err error
|
|
||||||
)
|
|
||||||
v.Client, err = define.GetVersion()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "unable to determine version")
|
|
||||||
}
|
|
||||||
// TODO we need to discuss how to implement
|
|
||||||
// this more. current endpoints dont have a
|
|
||||||
// version endpoint. maybe we use info?
|
|
||||||
// if remote {
|
|
||||||
// v.Server, err = getRemoteVersion(c)
|
|
||||||
// if err != nil {
|
|
||||||
// return err
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
v.Server = v.Client
|
|
||||||
// }
|
|
||||||
|
|
||||||
versionOutputFormat := versionFormat
|
|
||||||
if versionOutputFormat != "" {
|
|
||||||
if strings.Join(strings.Fields(versionOutputFormat), "") == "{{json.}}" {
|
|
||||||
versionOutputFormat = formats.JSONString
|
|
||||||
}
|
|
||||||
var out formats.Writer
|
|
||||||
switch versionOutputFormat {
|
|
||||||
case formats.JSONString:
|
|
||||||
out = formats.JSONStruct{Output: v}
|
|
||||||
return out.Out()
|
|
||||||
default:
|
|
||||||
out = formats.StdoutTemplate{Output: v, Template: versionOutputFormat}
|
|
||||||
err := out.Out()
|
|
||||||
if err != nil {
|
|
||||||
// On Failure, assume user is using older version of podman version --format and check client
|
|
||||||
out = formats.StdoutTemplate{Output: v.Client, Template: versionOutputFormat}
|
|
||||||
if err1 := out.Out(); err1 != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch {
|
||||||
|
case versionFormat == "json", versionFormat == "{{ json .}}":
|
||||||
|
s, err := json.MarshalToString(versions)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = io.WriteString(os.Stdout, s)
|
||||||
|
return err
|
||||||
|
case cmd.Flag("format").Changed:
|
||||||
|
if !strings.HasSuffix(versionFormat, "\n") {
|
||||||
|
versionFormat += "\n"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
|
||||||
}
|
|
||||||
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
|
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
|
||||||
defer w.Flush()
|
defer w.Flush()
|
||||||
|
|
||||||
if registry.IsRemote() {
|
if versions.Server != nil {
|
||||||
if _, err := fmt.Fprintf(w, "Client:\n"); err != nil {
|
if _, err := fmt.Fprintf(w, "Client:\n"); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
formatVersion(w, v.Client)
|
formatVersion(w, versions.Client)
|
||||||
if _, err := fmt.Fprintf(w, "\nServer:\n"); err != nil {
|
if _, err := fmt.Fprintf(w, "\nServer:\n"); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
formatVersion(w, v.Server)
|
formatVersion(w, versions.Server)
|
||||||
} else {
|
} else {
|
||||||
formatVersion(w, v.Client)
|
formatVersion(w, versions.Client)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func formatVersion(writer io.Writer, version define.Version) {
|
func formatVersion(writer io.Writer, version *define.Version) {
|
||||||
fmt.Fprintf(writer, "Version:\t%s\n", version.Version)
|
fmt.Fprintf(writer, "Version:\t%s\n", version.Version)
|
||||||
fmt.Fprintf(writer, "RemoteAPI Version:\t%d\n", version.RemoteAPIVersion)
|
fmt.Fprintf(writer, "RemoteAPI Version:\t%d\n", version.RemoteAPIVersion)
|
||||||
fmt.Fprintf(writer, "Go Version:\t%s\n", version.GoVersion)
|
fmt.Fprintf(writer, "Go Version:\t%s\n", version.GoVersion)
|
||||||
|
@ -10,6 +10,7 @@ import (
|
|||||||
"github.com/containers/libpod/libpod/define"
|
"github.com/containers/libpod/libpod/define"
|
||||||
"github.com/containers/libpod/pkg/api/handlers"
|
"github.com/containers/libpod/pkg/api/handlers"
|
||||||
"github.com/containers/libpod/pkg/api/handlers/utils"
|
"github.com/containers/libpod/pkg/api/handlers/utils"
|
||||||
|
"github.com/containers/libpod/pkg/domain/entities"
|
||||||
docker "github.com/docker/docker/api/types"
|
docker "github.com/docker/docker/api/types"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
@ -46,7 +47,7 @@ func VersionHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
|
|
||||||
utils.WriteResponse(w, http.StatusOK, handlers.Version{Version: docker.Version{
|
utils.WriteResponse(w, http.StatusOK, entities.ComponentVersion{Version: docker.Version{
|
||||||
Platform: struct {
|
Platform: struct {
|
||||||
Name string
|
Name string
|
||||||
}{
|
}{
|
||||||
|
@ -71,10 +71,6 @@ type Container struct {
|
|||||||
docker.ContainerCreateConfig
|
docker.ContainerCreateConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
type Version struct {
|
|
||||||
docker.Version
|
|
||||||
}
|
|
||||||
|
|
||||||
type DiskUsage struct {
|
type DiskUsage struct {
|
||||||
docker.DiskUsage
|
docker.DiskUsage
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,28 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (s *APIServer) registerVersionHandlers(r *mux.Router) error {
|
func (s *APIServer) registerVersionHandlers(r *mux.Router) error {
|
||||||
|
// swagger:operation GET /version compat CompatSystemVersion
|
||||||
|
// ---
|
||||||
|
// summary: Component Version information
|
||||||
|
// tags:
|
||||||
|
// - system (compat)
|
||||||
|
// produces:
|
||||||
|
// - application/json
|
||||||
|
// responses:
|
||||||
|
// 200:
|
||||||
|
// $ref: "#/responses/Version"
|
||||||
r.Handle("/version", s.APIHandler(compat.VersionHandler)).Methods(http.MethodGet)
|
r.Handle("/version", s.APIHandler(compat.VersionHandler)).Methods(http.MethodGet)
|
||||||
r.Handle(VersionedPath("/version"), s.APIHandler(compat.VersionHandler)).Methods(http.MethodGet)
|
r.Handle(VersionedPath("/version"), s.APIHandler(compat.VersionHandler)).Methods(http.MethodGet)
|
||||||
|
// swagger:operation GET /libpod/version libpod SystemVersion
|
||||||
|
// ---
|
||||||
|
// summary: Component Version information
|
||||||
|
// tags:
|
||||||
|
// - system
|
||||||
|
// produces:
|
||||||
|
// - application/json
|
||||||
|
// responses:
|
||||||
|
// 200:
|
||||||
|
// $ref: "#/responses/Version"
|
||||||
|
r.Handle(VersionedPath("/libpod/version"), s.APIHandler(compat.VersionHandler)).Methods(http.MethodGet)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -181,3 +181,12 @@ type swagHealthCheckRunResponse struct {
|
|||||||
define.HealthCheckResults
|
define.HealthCheckResults
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Version
|
||||||
|
// swagger:response Version
|
||||||
|
type swagVersion struct {
|
||||||
|
// in:body
|
||||||
|
Body struct {
|
||||||
|
entities.SystemVersionReport
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -3,11 +3,14 @@ package system
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/containers/libpod/libpod/define"
|
||||||
"github.com/containers/libpod/pkg/bindings"
|
"github.com/containers/libpod/pkg/bindings"
|
||||||
"github.com/containers/libpod/pkg/domain/entities"
|
"github.com/containers/libpod/pkg/domain/entities"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
@ -83,3 +86,38 @@ func Prune(ctx context.Context, all, volumes *bool) (*entities.SystemPruneReport
|
|||||||
}
|
}
|
||||||
return &report, response.Process(&report)
|
return &report, response.Process(&report)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Version(ctx context.Context) (*entities.SystemVersionReport, error) {
|
||||||
|
var report entities.SystemVersionReport
|
||||||
|
var component entities.ComponentVersion
|
||||||
|
|
||||||
|
version, err := define.GetVersion()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
report.Client = &version
|
||||||
|
|
||||||
|
conn, err := bindings.GetClient(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
response, err := conn.DoRequest(nil, http.MethodGet, "/version", nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = response.Process(&component); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
f, _ := strconv.ParseFloat(component.APIVersion, 64)
|
||||||
|
b, _ := time.Parse(time.RFC3339, component.BuildTime)
|
||||||
|
report.Server = &define.Version{
|
||||||
|
RemoteAPIVersion: int64(f),
|
||||||
|
Version: component.Version.Version,
|
||||||
|
GoVersion: component.GoVersion,
|
||||||
|
GitCommit: component.GitCommit,
|
||||||
|
Built: b.Unix(),
|
||||||
|
OsArch: fmt.Sprintf("%s/%s", component.Os, component.Arch),
|
||||||
|
}
|
||||||
|
return &report, err
|
||||||
|
}
|
||||||
|
@ -73,6 +73,7 @@ type ContainerEngine interface {
|
|||||||
SystemDf(ctx context.Context, options SystemDfOptions) (*SystemDfReport, error)
|
SystemDf(ctx context.Context, options SystemDfOptions) (*SystemDfReport, error)
|
||||||
Unshare(ctx context.Context, args []string) error
|
Unshare(ctx context.Context, args []string) error
|
||||||
VarlinkService(ctx context.Context, opts ServiceOptions) error
|
VarlinkService(ctx context.Context, opts ServiceOptions) error
|
||||||
|
Version(ctx context.Context) (*SystemVersionReport, error)
|
||||||
VolumeCreate(ctx context.Context, opts VolumeCreateOptions) (*IdOrNameResponse, error)
|
VolumeCreate(ctx context.Context, opts VolumeCreateOptions) (*IdOrNameResponse, error)
|
||||||
VolumeInspect(ctx context.Context, namesOrIds []string, opts VolumeInspectOptions) ([]*VolumeInspectReport, error)
|
VolumeInspect(ctx context.Context, namesOrIds []string, opts VolumeInspectOptions) ([]*VolumeInspectReport, error)
|
||||||
VolumeList(ctx context.Context, opts VolumeListOptions) ([]*VolumeListReport, error)
|
VolumeList(ctx context.Context, opts VolumeListOptions) ([]*VolumeListReport, error)
|
||||||
|
@ -3,6 +3,8 @@ package entities
|
|||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/containers/libpod/libpod/define"
|
||||||
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -83,3 +85,15 @@ type SystemDfVolumeReport struct {
|
|||||||
type SystemResetOptions struct {
|
type SystemResetOptions struct {
|
||||||
Force bool
|
Force bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SystemVersionReport describes version information about the running Podman service
|
||||||
|
type SystemVersionReport struct {
|
||||||
|
// Always populated
|
||||||
|
Client *define.Version `json:",omitempty"`
|
||||||
|
// May be populated, when in tunnel mode
|
||||||
|
Server *define.Version `json:",omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ComponentVersion struct {
|
||||||
|
types.Version
|
||||||
|
}
|
||||||
|
@ -407,3 +407,13 @@ func (ic *ContainerEngine) Unshare(ctx context.Context, args []string) error {
|
|||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
return cmd.Run()
|
return cmd.Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ic ContainerEngine) Version(ctx context.Context) (*entities.SystemVersionReport, error) {
|
||||||
|
var report entities.SystemVersionReport
|
||||||
|
v, err := define.GetVersion()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
report.Client = &v
|
||||||
|
return &report, err
|
||||||
|
}
|
||||||
|
@ -34,3 +34,7 @@ func (ic *ContainerEngine) SystemDf(ctx context.Context, options entities.System
|
|||||||
func (ic *ContainerEngine) Unshare(ctx context.Context, args []string) error {
|
func (ic *ContainerEngine) Unshare(ctx context.Context, args []string) error {
|
||||||
return errors.New("unshare is not supported on remote clients")
|
return errors.New("unshare is not supported on remote clients")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ic ContainerEngine) Version(ctx context.Context) (*entities.SystemVersionReport, error) {
|
||||||
|
return system.Version(ic.ClientCxt)
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user