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