@@ -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
312336func (self * manager ) getAdjustedSpec (cinfo * containerInfo ) info.ContainerSpec {
0 commit comments