Skip to content

Commit 588b149

Browse files
committed
Merge pull request google#587 from rjnagal/docker
Add alias and namespace information to /spec endpoint
2 parents 7d27bf2 + 53d25cc commit 588b149

File tree

3 files changed

+38
-27
lines changed

3 files changed

+38
-27
lines changed

api/versions.go

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,7 @@ func (self *version2_0) HandleRequest(requestType string, request []string, m ma
368368
if err != nil {
369369
return err
370370
}
371-
specV2 := convertSpec(spec)
372-
return writeResult(specV2, w)
371+
return writeResult(spec, w)
373372
case storageApi:
374373
var err error
375374
fi := []v2.FsInfo{}
@@ -393,26 +392,6 @@ func (self *version2_0) HandleRequest(requestType string, request []string, m ma
393392
}
394393
}
395394

396-
// Convert container spec from v1 to v2.
397-
func convertSpec(specV1 info.ContainerSpec) v2.ContainerSpec {
398-
specV2 := v2.ContainerSpec{
399-
CreationTime: specV1.CreationTime,
400-
HasCpu: specV1.HasCpu,
401-
HasMemory: specV1.HasMemory,
402-
}
403-
if specV1.HasCpu {
404-
specV2.Cpu.Limit = specV1.Cpu.Limit
405-
specV2.Cpu.MaxLimit = specV1.Cpu.MaxLimit
406-
specV2.Cpu.Mask = specV1.Cpu.Mask
407-
}
408-
if specV1.HasMemory {
409-
specV2.Memory.Limit = specV1.Memory.Limit
410-
specV2.Memory.Reservation = specV1.Memory.Reservation
411-
specV2.Memory.SwapLimit = specV1.Memory.SwapLimit
412-
}
413-
return specV2
414-
}
415-
416395
func convertStats(cont *info.ContainerInfo) []v2.ContainerStats {
417396
stats := []v2.ContainerStats{}
418397
for _, val := range cont.Stats {

info/v2/container.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ type ContainerSpec struct {
5151
// Time at which the container was created.
5252
CreationTime time.Time `json:"creation_time,omitempty"`
5353

54+
// Other names by which the container is known within a certain namespace.
55+
// This is unique within that namespace.
56+
Aliases []string `json:"aliases,omitempty"`
57+
58+
// Namespace under which the aliases of a container are unique.
59+
// An example of a namespace is "docker" for Docker containers.
60+
Namespace string `json:"namespace,omitempty"`
61+
5462
HasCpu bool `json:"has_cpu"`
5563
Cpu CpuSpec `json:"cpu,omitempty"`
5664

manager/manager.go

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ type Manager interface {
6464
DockerContainer(dockerName string, query *info.ContainerInfoRequest) (info.ContainerInfo, error)
6565

6666
// Gets spec for a container.
67-
GetContainerSpec(containerName string) (info.ContainerSpec, error)
67+
GetContainerSpec(containerName string) (v2.ContainerSpec, error)
6868

6969
// Get derived stats for a container.
7070
GetContainerDerivedStats(containerName string) (v2.DerivedStats, error)
@@ -297,16 +297,40 @@ func (self *manager) getContainerData(containerName string) (*containerData, err
297297
return cont, nil
298298
}
299299

300-
func (self *manager) GetContainerSpec(containerName string) (info.ContainerSpec, error) {
300+
func (self *manager) GetContainerSpec(containerName string) (v2.ContainerSpec, error) {
301301
cont, err := self.getContainerData(containerName)
302302
if err != nil {
303-
return info.ContainerSpec{}, err
303+
return v2.ContainerSpec{}, err
304304
}
305305
cinfo, err := cont.GetInfo()
306306
if err != nil {
307-
return info.ContainerSpec{}, err
307+
return v2.ContainerSpec{}, err
308308
}
309-
return self.getAdjustedSpec(cinfo), nil
309+
spec := self.getV2Spec(cinfo)
310+
return spec, nil
311+
}
312+
313+
// Get V2 container spec from v1 container info.
314+
func (self *manager) getV2Spec(cinfo *containerInfo) v2.ContainerSpec {
315+
specV1 := self.getAdjustedSpec(cinfo)
316+
specV2 := v2.ContainerSpec{
317+
CreationTime: specV1.CreationTime,
318+
HasCpu: specV1.HasCpu,
319+
HasMemory: specV1.HasMemory,
320+
}
321+
if specV1.HasCpu {
322+
specV2.Cpu.Limit = specV1.Cpu.Limit
323+
specV2.Cpu.MaxLimit = specV1.Cpu.MaxLimit
324+
specV2.Cpu.Mask = specV1.Cpu.Mask
325+
}
326+
if specV1.HasMemory {
327+
specV2.Memory.Limit = specV1.Memory.Limit
328+
specV2.Memory.Reservation = specV1.Memory.Reservation
329+
specV2.Memory.SwapLimit = specV1.Memory.SwapLimit
330+
}
331+
specV2.Aliases = cinfo.Aliases
332+
specV2.Namespace = cinfo.Namespace
333+
return specV2
310334
}
311335

312336
func (self *manager) getAdjustedSpec(cinfo *containerInfo) info.ContainerSpec {

0 commit comments

Comments
 (0)