Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -1975,8 +1975,6 @@ mountPoint [string](https://godoc.org/builtin#string)
driver [string](https://godoc.org/builtin#string)

options [map[string]](#map[string])

scope [string](https://godoc.org/builtin#string)
### <a name="VolumeCreateOpts"></a>type VolumeCreateOpts


Expand Down
3 changes: 1 addition & 2 deletions cmd/podman/varlink/io.podman.varlink
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ type Volume (
labels: [string]string,
mountPoint: string,
driver: string,
options: [string]string,
scope: string
options: [string]string
)

type NotImplemented (
Expand Down
1 change: 0 additions & 1 deletion cmd/podman/volume_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ func init() {
flags.StringVar(&volumeCreateCommand.Driver, "driver", "", "Specify volume driver name (default local)")
flags.StringSliceVarP(&volumeCreateCommand.Label, "label", "l", []string{}, "Set metadata for a volume (default [])")
flags.StringSliceVarP(&volumeCreateCommand.Opt, "opt", "o", []string{}, "Set driver specific options (default [])")

}

func volumeCreateCmd(c *cliconfig.VolumeCreateValues) error {
Expand Down
24 changes: 23 additions & 1 deletion cmd/podman/volume_inspect.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package main

import (
"fmt"

"github.com/containers/buildah/pkg/formats"
"github.com/containers/libpod/cmd/podman/cliconfig"
"github.com/containers/libpod/pkg/adapter"
"github.com/pkg/errors"
Expand Down Expand Up @@ -53,5 +56,24 @@ func volumeInspectCmd(c *cliconfig.VolumeInspectValues) error {
if err != nil {
return err
}
return generateVolLsOutput(vols, volumeLsOptions{Format: c.Format})

switch c.Format {
case "", formats.JSONString:
// Normal format - JSON string
jsonOut, err := json.MarshalIndent(vols, "", " ")
if err != nil {
return errors.Wrapf(err, "error marshalling inspect JSON")
}
fmt.Println(string(jsonOut))
default:
// It's a Go template.
interfaces := make([]interface{}, len(vols))
for i, vol := range vols {
interfaces[i] = vol
}
out := formats.StdoutTemplateArray{Output: interfaces, Template: c.Format}
return out.Out()
}

return nil
}
44 changes: 22 additions & 22 deletions libpod/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -1362,6 +1362,17 @@ func WithNamedVolumes(volumes []*ContainerNamedVolume) CtrCreateOption {
}
}

// WithHealthCheck adds the healthcheck to the container config
func WithHealthCheck(healthCheck *manifest.Schema2HealthConfig) CtrCreateOption {
return func(ctr *Container) error {
if ctr.valid {
return define.ErrCtrFinalized
}
ctr.config.HealthCheckConfig = healthCheck
return nil
}
}

// Volume Creation Options

// WithVolumeName sets the name of the volume.
Expand All @@ -1381,30 +1392,30 @@ func WithVolumeName(name string) VolumeCreateOption {
}
}

// WithVolumeLabels sets the labels of the volume.
func WithVolumeLabels(labels map[string]string) VolumeCreateOption {
// WithVolumeDriver sets the volume's driver.
// It is presently not implemented, but will be supported in a future Podman
// release.
func WithVolumeDriver(driver string) VolumeCreateOption {
return func(volume *Volume) error {
if volume.valid {
return define.ErrVolumeFinalized
}

volume.config.Labels = make(map[string]string)
for key, value := range labels {
volume.config.Labels[key] = value
}

return nil
return define.ErrNotImplemented
}
}

// WithVolumeDriver sets the driver of the volume.
func WithVolumeDriver(driver string) VolumeCreateOption {
// WithVolumeLabels sets the labels of the volume.
func WithVolumeLabels(labels map[string]string) VolumeCreateOption {
return func(volume *Volume) error {
if volume.valid {
return define.ErrVolumeFinalized
}

volume.config.Driver = driver
volume.config.Labels = make(map[string]string)
for key, value := range labels {
volume.config.Labels[key] = value
}

return nil
}
Expand Down Expand Up @@ -1673,14 +1684,3 @@ func WithInfraContainerPorts(bindings []ocicni.PortMapping) PodCreateOption {
return nil
}
}

// WithHealthCheck adds the healthcheck to the container config
func WithHealthCheck(healthCheck *manifest.Schema2HealthConfig) CtrCreateOption {
return func(ctr *Container) error {
if ctr.valid {
return define.ErrCtrFinalized
}
ctr.config.HealthCheckConfig = healthCheck
return nil
}
}
7 changes: 2 additions & 5 deletions libpod/runtime_volume_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"path/filepath"
"strings"
"time"

"github.com/containers/libpod/libpod/define"
"github.com/containers/libpod/libpod/events"
Expand Down Expand Up @@ -42,14 +43,10 @@ func (r *Runtime) newVolume(ctx context.Context, options ...VolumeCreateOption)
if volume.config.Name == "" {
volume.config.Name = stringid.GenerateNonCryptoID()
}
// TODO: support for other volume drivers
if volume.config.Driver == "" {
volume.config.Driver = "local"
}
// TODO: determine when the scope is global and set it to that
if volume.config.Scope == "" {
volume.config.Scope = "local"
}
volume.config.CreatedTime = time.Now()

// Create the mountpoint of this volume
volPathRoot := filepath.Join(r.config.VolumePath, volume.config.Name)
Expand Down
46 changes: 34 additions & 12 deletions libpod/volume.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package libpod

import (
"time"
)

// Volume is the type used to create named volumes
// TODO: all volumes should be created using this and the Volume API
type Volume struct {
Expand All @@ -15,10 +19,10 @@ type VolumeConfig struct {
Name string `json:"name"`

Labels map[string]string `json:"labels"`
MountPoint string `json:"mountPoint"`
Driver string `json:"driver"`
MountPoint string `json:"mountPoint"`
CreatedTime time.Time `json:"createdAt,omitempty"`
Options map[string]string `json:"options"`
Scope string `json:"scope"`
IsCtrSpecific bool `json:"ctrSpecific"`
UID int `json:"uid"`
GID int `json:"gid"`
Expand All @@ -29,6 +33,18 @@ func (v *Volume) Name() string {
return v.config.Name
}

// Driver retrieves the volume's driver.
func (v *Volume) Driver() string {
return v.config.Driver
}

// Scope retrieves the volume's scope.
// Libpod does not implement volume scoping, and this is provided solely for
// Docker compatibility. It returns only "local".
func (v *Volume) Scope() string {
return "local"
}

// Labels returns the volume's labels
func (v *Volume) Labels() map[string]string {
labels := make(map[string]string)
Expand All @@ -43,11 +59,6 @@ func (v *Volume) MountPoint() string {
return v.config.MountPoint
}

// Driver returns the volume's driver
func (v *Volume) Driver() string {
return v.config.Driver
}

// Options return the volume's options
func (v *Volume) Options() map[string]string {
options := make(map[string]string)
Expand All @@ -58,14 +69,25 @@ func (v *Volume) Options() map[string]string {
return options
}

// Scope returns the scope of the volume
func (v *Volume) Scope() string {
return v.config.Scope
}

// IsCtrSpecific returns whether this volume was created specifically for a
// given container. Images with this set to true will be removed when the
// container is removed with the Volumes parameter set to true.
func (v *Volume) IsCtrSpecific() bool {
return v.config.IsCtrSpecific
}

// UID returns the UID the volume will be created as.
func (v *Volume) UID() int {
return v.config.UID
}

// GID returns the GID the volume will be created as.
func (v *Volume) GID() int {
return v.config.GID
}

// CreatedTime returns the time the volume was created at. It was not tracked
// for some time, so older volumes may not contain one.
func (v *Volume) CreatedTime() time.Time {
return v.config.CreatedTime
}
70 changes: 70 additions & 0 deletions libpod/volume_inspect.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package libpod

import (
"time"

"github.com/containers/libpod/libpod/define"
)

// InspectVolumeData is the output of Inspect() on a volume. It is matched to
// the format of 'docker volume inspect'.
type InspectVolumeData struct {
// Name is the name of the volume.
Name string `json:"Name"`
// Driver is the driver used to create the volume.
// This will be properly implemented in a future version.
Driver string `json:"Driver"`
// Mountpoint is the path on the host where the volume is mounted.
Mountpoint string `json:"Mountpoint"`
// CreatedAt is the date and time the volume was created at. This is not
// stored for older Libpod volumes; if so, it will be omitted.
CreatedAt time.Time `json:"CreatedAt,omitempty"`
// Status is presently unused and provided only for Docker compatibility.
// In the future it will be used to return information on the volume's
// current state.
Status map[string]string `json:"Status,omitempty"`
// Labels includes the volume's configured labels, key:value pairs that
// can be passed during volume creation to provide information for third
// party tools.
Labels map[string]string `json:"Labels"`
// Scope is unused and provided solely for Docker compatibility. It is
// unconditionally set to "local".
Scope string `json:"Scope"`
// Options is a set of options that were used when creating the volume.
// It is presently not used.
Options map[string]string `json:"Options"`
// UID is the UID that the volume was created with.
UID int `json:"UID,omitempty"`
// GID is the GID that the volume was created with.
GID int `json:"GID,omitempty"`
// ContainerSpecific indicates that the volume was created as part of a
// specific container, and will be removed when that container is
// removed.
ContainerSpecific bool `json:"ContainerSpecific,omitempty"`
}

// Inspect provides detailed information about the configuration of the given
// volume.
func (v *Volume) Inspect() (*InspectVolumeData, error) {
if !v.valid {
return nil, define.ErrVolumeRemoved
}

data := new(InspectVolumeData)

data.Name = v.config.Name
data.Driver = v.config.Driver
data.Mountpoint = v.config.MountPoint
data.CreatedAt = v.config.CreatedTime
data.Labels = make(map[string]string)
for k, v := range v.config.Labels {
data.Labels[k] = v
}
data.Scope = v.Scope()
data.Options = make(map[string]string)
data.UID = v.config.UID
data.GID = v.config.GID
data.ContainerSpecific = v.config.IsCtrSpecific

return data, nil
}
19 changes: 14 additions & 5 deletions pkg/adapter/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,21 @@ package adapter
import (
"bufio"
"context"
"github.com/containers/libpod/libpod/define"
"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"
"github.com/containers/image/docker/reference"
"github.com/containers/image/types"
"github.com/containers/libpod/cmd/podman/cliconfig"
"github.com/containers/libpod/cmd/podman/libpodruntime"
"github.com/containers/libpod/cmd/podman/shared"
"github.com/containers/libpod/libpod"
"github.com/containers/libpod/libpod/define"
"github.com/containers/libpod/libpod/events"
"github.com/containers/libpod/libpod/image"
"github.com/containers/libpod/pkg/rootless"
Expand Down Expand Up @@ -209,7 +208,7 @@ 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) {
func (r *LocalRuntime) InspectVolumes(ctx context.Context, c *cliconfig.VolumeInspectValues) ([]*libpod.InspectVolumeData, error) {
var (
volumes []*libpod.Volume
err error
Expand All @@ -229,7 +228,17 @@ func (r *LocalRuntime) InspectVolumes(ctx context.Context, c *cliconfig.VolumeIn
if err != nil {
return nil, err
}
return libpodVolumeToVolume(volumes), nil

inspectVols := make([]*libpod.InspectVolumeData, 0, len(volumes))
for _, vol := range volumes {
inspectOut, err := vol.Inspect()
if err != nil {
return nil, errors.Wrapf(err, "error inspecting volume %s", vol.Name())
}
inspectVols = append(inspectVols, inspectOut)
}

return inspectVols, nil
}

// Volumes returns a slice of localruntime volumes
Expand Down
1 change: 0 additions & 1 deletion pkg/adapter/runtime_remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,6 @@ func varlinkVolumeToVolume(r *LocalRuntime, volumes []iopodman.Volume) []*Volume
MountPoint: v.MountPoint,
Driver: v.Driver,
Options: v.Options,
Scope: v.Scope,
}
n := remoteVolume{
Runtime: r,
Expand Down
2 changes: 1 addition & 1 deletion pkg/adapter/volumes_remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ func (v *Volume) MountPoint() string {

// Scope returns the scope for an adapter.volume
func (v *Volume) Scope() string {
return v.config.Scope
return "local"
}
1 change: 0 additions & 1 deletion pkg/varlinkapi/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ func (i *LibpodAPI) GetVolumes(call iopodman.VarlinkCall, args []string, all boo
MountPoint: v.MountPoint(),
Name: v.Name(),
Options: v.Options(),
Scope: v.Scope(),
}
volumes = append(volumes, newVol)
}
Expand Down