Merge pull request #4284 from mheon/fix_vol_inspect

Show volume options in 'volume inspect'
This commit is contained in:
OpenShift Merge Robot
2019-10-21 22:20:40 +02:00
committed by GitHub
6 changed files with 79 additions and 5 deletions

8
API.md
View File

@ -107,6 +107,8 @@ in the [API.md](https://github.com/containers/libpod/blob/master/API.md) file in
[func InspectPod(name: string) string](#InspectPod)
[func InspectVolume(name: string) string](#InspectVolume)
[func KillContainer(name: string, signal: int) string](#KillContainer)
[func KillPod(name: string, signal: int) string](#KillPod)
@ -804,6 +806,12 @@ method InspectPod(name: [string](https://godoc.org/builtin#string)) [string](htt
InspectPod takes the name or ID of an image and returns a string representation of data associated with the
pod. You must serialize the string into JSON to use it further. A [PodNotFound](#PodNotFound) error will
be returned if the pod cannot be found.
### <a name="InspectVolume"></a>func InspectVolume
<div style="background-color: #E8E8E8; padding: 15px; margin: 10px; border-radius: 10px;">
method InspectVolume(name: [string](https://godoc.org/builtin#string)) [string](https://godoc.org/builtin#string)</div>
InspectVolume inspects a single volume. Returns inspect JSON in the form of a
string.
### <a name="KillContainer"></a>func KillContainer
<div style="background-color: #E8E8E8; padding: 15px; margin: 10px; border-radius: 10px;">

View File

@ -1268,6 +1268,10 @@ method VolumeRemove(options: VolumeRemoveOpts) -> (successes: []string, failures
# GetVolumes gets slice of the volumes on a remote host
method GetVolumes(args: []string, all: bool) -> (volumes: []Volume)
# InspectVolume inspects a single volume. Returns inspect JSON in the form of a
# string.
method InspectVolume(name: string) -> (volume: string)
# VolumesPrune removes unused volumes on the host
method VolumesPrune() -> (prunedNames: []string, prunedErrors: []string)

View File

@ -62,6 +62,9 @@ func (v *Volume) Inspect() (*InspectVolumeData, error) {
}
data.Scope = v.Scope()
data.Options = make(map[string]string)
for k, v := range v.config.Options {
data.Options[k] = v
}
data.UID = v.config.UID
data.GID = v.config.GID
data.ContainerSpecific = v.config.IsCtrSpecific

View File

@ -659,12 +659,39 @@ func (r *LocalRuntime) Push(ctx context.Context, srcName, destination, manifestM
}
// InspectVolumes returns a slice of volumes based on an arg list or --all
func (r *LocalRuntime) InspectVolumes(ctx context.Context, c *cliconfig.VolumeInspectValues) ([]*Volume, error) {
reply, err := iopodman.GetVolumes().Call(r.Conn, c.InputArgs, c.All)
func (r *LocalRuntime) InspectVolumes(ctx context.Context, c *cliconfig.VolumeInspectValues) ([]*libpod.InspectVolumeData, error) {
var (
inspectData []*libpod.InspectVolumeData
volumes []string
)
if c.All {
allVolumes, err := r.Volumes(ctx)
if err != nil {
return nil, err
}
return varlinkVolumeToVolume(r, reply), nil
for _, vol := range allVolumes {
volumes = append(volumes, vol.Name())
}
} else {
for _, arg := range c.InputArgs {
volumes = append(volumes, arg)
}
}
for _, vol := range volumes {
jsonString, err := iopodman.InspectVolume().Call(r.Conn, vol)
if err != nil {
return nil, err
}
inspectJSON := new(libpod.InspectVolumeData)
if err := json.Unmarshal([]byte(jsonString), inspectJSON); err != nil {
return nil, errors.Wrapf(err, "error unmarshalling inspect JSON for volume %s", vol)
}
inspectData = append(inspectData, inspectJSON)
}
return inspectData, nil
}
// Volumes returns a slice of adapter.volumes based on information about libpod

View File

@ -3,6 +3,8 @@
package varlinkapi
import (
"encoding/json"
"github.com/containers/libpod/cmd/podman/shared"
"github.com/containers/libpod/cmd/podman/varlink"
"github.com/containers/libpod/libpod"
@ -80,6 +82,23 @@ func (i *LibpodAPI) GetVolumes(call iopodman.VarlinkCall, args []string, all boo
return call.ReplyGetVolumes(volumes)
}
// InspectVolume inspects a single volume, returning its JSON as a string.
func (i *LibpodAPI) InspectVolume(call iopodman.VarlinkCall, name string) error {
vol, err := i.Runtime.LookupVolume(name)
if err != nil {
return call.ReplyErrorOccurred(err.Error())
}
inspectOut, err := vol.Inspect()
if err != nil {
return call.ReplyErrorOccurred(err.Error())
}
inspectJSON, err := json.Marshal(inspectOut)
if err != nil {
return call.ReplyErrorOccurred(err.Error())
}
return call.ReplyInspectVolume(string(inspectJSON))
}
// VolumesPrune removes unused images via a varlink call
func (i *LibpodAPI) VolumesPrune(call iopodman.VarlinkCall) error {
var errs []string

View File

@ -2,6 +2,7 @@ package integration
import (
"os"
"strings"
. "github.com/containers/libpod/test/utils"
. "github.com/onsi/ginkgo"
@ -74,4 +75,16 @@ var _ = Describe("Podman volume inspect", func() {
Expect(session.OutputToStringArray()[0]).To(Equal(volName1))
Expect(session.OutputToStringArray()[1]).To(Equal(volName2))
})
It("inspect volume finds options", func() {
volName := "testvol"
session := podmanTest.Podman([]string{"volume", "create", "--opt", "type=tmpfs", volName})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
inspect := podmanTest.Podman([]string{"volume", "inspect", volName})
inspect.WaitWithDefaultTimeout()
Expect(inspect.ExitCode()).To(Equal(0))
Expect(strings.Contains(inspect.OutputToString(), "tmpfs")).To(BeTrue())
})
})