Skip to content

Commit 53d25cc

Browse files
committed
Add alias and namespace information to /spec endpoint
1 parent 7a6f5dd commit 53d25cc

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)
@@ -290,16 +290,40 @@ func (self *manager) getContainerData(containerName string) (*containerData, err
290290
return cont, nil
291291
}
292292

293-
func (self *manager) GetContainerSpec(containerName string) (info.ContainerSpec, error) {
293+
func (self *manager) GetContainerSpec(containerName string) (v2.ContainerSpec, error) {
294294
cont, err := self.getContainerData(containerName)
295295
if err != nil {
296-
return info.ContainerSpec{}, err
296+
return v2.ContainerSpec{}, err
297297
}
298298
cinfo, err := cont.GetInfo()
299299
if err != nil {
300-
return info.ContainerSpec{}, err
300+
return v2.ContainerSpec{}, err
301301
}
302-
return self.getAdjustedSpec(cinfo), nil
302+
spec := self.getV2Spec(cinfo)
303+
return spec, nil
304+
}
305+
306+
// Get V2 container spec from v1 container info.
307+
func (self *manager) getV2Spec(cinfo *containerInfo) v2.ContainerSpec {
308+
specV1 := self.getAdjustedSpec(cinfo)
309+
specV2 := v2.ContainerSpec{
310+
CreationTime: specV1.CreationTime,
311+
HasCpu: specV1.HasCpu,
312+
HasMemory: specV1.HasMemory,
313+
}
314+
if specV1.HasCpu {
315+
specV2.Cpu.Limit = specV1.Cpu.Limit
316+
specV2.Cpu.MaxLimit = specV1.Cpu.MaxLimit
317+
specV2.Cpu.Mask = specV1.Cpu.Mask
318+
}
319+
if specV1.HasMemory {
320+
specV2.Memory.Limit = specV1.Memory.Limit
321+
specV2.Memory.Reservation = specV1.Memory.Reservation
322+
specV2.Memory.SwapLimit = specV1.Memory.SwapLimit
323+
}
324+
specV2.Aliases = cinfo.Aliases
325+
specV2.Namespace = cinfo.Namespace
326+
return specV2
303327
}
304328

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

0 commit comments

Comments
 (0)