Browse Source

Merge pull request #27294 from mlaventure/hide-unused-volume-fields

Move types.Volumes optional fields under a new type
Sebastiaan van Stijn 8 years ago
parent
commit
a7db0a8402

+ 7 - 2
api/types/types.go

@@ -433,6 +433,12 @@ type MountPoint struct {
 	Propagation mount.Propagation
 }
 
+// VolumeUsageData holds information regarding the volume usage
+type VolumeUsageData struct {
+	Size     int64 // Size holds how much disk space is used by the (local driver only). Sets to -1 if not provided.
+	RefCount int   // RefCount holds the number of containers having this volume attached to them. Sets to -1 if not provided.
+}
+
 // Volume represents the configuration of a volume for the remote API
 type Volume struct {
 	Name       string                 // Name is the name of the volume
@@ -441,8 +447,7 @@ type Volume struct {
 	Status     map[string]interface{} `json:",omitempty"` // Status provides low-level status information about the volume
 	Labels     map[string]string      // Labels is metadata specific to the volume
 	Scope      string                 // Scope describes the level at which the volume exists (e.g. `global` for cluster-wide or `local` for machine level)
-	Size       int64                  // Size holds how much disk space is used by the (local driver only). Sets to -1 if not provided.
-	RefCount   int                    // RefCount holds the number of containers having this volume attached to them. Sets to -1 if not provided.
+	UsageData  *VolumeUsageData       `json:",omitempty"`
 }
 
 // VolumesListResponse contains the response for the remote API:

+ 7 - 7
cli/command/formatter/disk_usage.go

@@ -288,7 +288,7 @@ func (c *diskUsageVolumesContext) Active() string {
 
 	used := 0
 	for _, v := range c.volumes {
-		if v.RefCount > 0 {
+		if v.UsageData.RefCount > 0 {
 			used++
 		}
 	}
@@ -301,8 +301,8 @@ func (c *diskUsageVolumesContext) Size() string {
 
 	c.AddHeader(sizeHeader)
 	for _, v := range c.volumes {
-		if v.Size != -1 {
-			size += v.Size
+		if v.UsageData.Size != -1 {
+			size += v.UsageData.Size
 		}
 	}
 
@@ -315,11 +315,11 @@ func (c *diskUsageVolumesContext) Reclaimable() string {
 
 	c.AddHeader(reclaimableHeader)
 	for _, v := range c.volumes {
-		if v.Size != -1 {
-			if v.RefCount == 0 {
-				reclaimable += v.Size
+		if v.UsageData.Size != -1 {
+			if v.UsageData.RefCount == 0 {
+				reclaimable += v.UsageData.Size
 			}
-			totalSize += v.Size
+			totalSize += v.UsageData.Size
 		}
 	}
 

+ 4 - 4
cli/command/formatter/volume.go

@@ -101,16 +101,16 @@ func (c *volumeContext) Label(name string) string {
 
 func (c *volumeContext) Links() string {
 	c.AddHeader(linksHeader)
-	if c.v.Size == -1 {
+	if c.v.UsageData == nil {
 		return "N/A"
 	}
-	return fmt.Sprintf("%d", c.v.RefCount)
+	return fmt.Sprintf("%d", c.v.UsageData.RefCount)
 }
 
 func (c *volumeContext) Size() string {
 	c.AddHeader(sizeHeader)
-	if c.v.Size == -1 {
+	if c.v.UsageData == nil {
 		return "N/A"
 	}
-	return units.HumanSize(float64(c.v.Size))
+	return units.HumanSize(float64(c.v.UsageData.Size))
 }

+ 1 - 2
daemon/disk_usage.go

@@ -56,13 +56,12 @@ func (daemon *Daemon) SystemDiskUsage() (*types.DiskUsage, error) {
 		refs := daemon.volumes.Refs(v)
 
 		tv := volumeToAPIType(v)
-		tv.RefCount = len(refs)
 		sz, err := directory.Size(v.Path())
 		if err != nil {
 			logrus.Warnf("failed to determine size of volume %v", name)
 			sz = -1
 		}
-		tv.Size = sz
+		tv.UsageData = &types.VolumeUsageData{Size: sz, RefCount: len(refs)}
 		allVolumes = append(allVolumes, tv)
 
 		return nil

+ 2 - 4
daemon/volumes.go

@@ -29,10 +29,8 @@ type mounts []container.Mount
 // volumeToAPIType converts a volume.Volume to the type used by the remote API
 func volumeToAPIType(v volume.Volume) *types.Volume {
 	tv := &types.Volume{
-		Name:     v.Name(),
-		Driver:   v.DriverName(),
-		Size:     -1,
-		RefCount: -1,
+		Name:   v.Name(),
+		Driver: v.DriverName(),
 	}
 	if v, ok := v.(volume.LabeledVolume); ok {
 		tv.Labels = v.Labels()