MCPcopy
hub / github.com/moby/moby / transform

Method transform

daemon/container/view.go:293–427  ·  view source on GitHub ↗

transform maps a (deep) copied Container object to what queries need. A lock on the Container is not held because these are immutable deep copies.

(ctr *Container)

Source from the content-addressed store, hash-verified

291// transform maps a (deep) copied Container object to what queries need.
292// A lock on the Container is not held because these are immutable deep copies.
293func (v *View) transform(ctr *Container) *Snapshot {
294 health := container.NoHealthcheck
295 failingStreak := 0
296 if ctr.State.Health != nil {
297 health = ctr.State.Health.Status()
298 failingStreak = ctr.State.Health.Health.FailingStreak
299 }
300
301 snapshot := &Snapshot{
302 Summary: container.Summary{
303 ID: ctr.ID,
304 Names: v.getNames(ctr.ID),
305 ImageID: ctr.ImageID.String(),
306 Ports: []container.PortSummary{},
307 Mounts: ctr.GetMountPoints(),
308 State: ctr.State.State(),
309 Status: ctr.State.String(),
310 Health: &container.HealthSummary{
311 Status: health,
312 FailingStreak: failingStreak,
313 },
314 Created: ctr.Created.Unix(),
315 },
316 CreatedAt: ctr.Created,
317 StartedAt: ctr.State.StartedAt,
318 Name: ctr.Name,
319 Pid: ctr.State.Pid,
320 Managed: ctr.Managed,
321 ExposedPorts: make(network.PortSet),
322 PortBindings: make(network.PortSet),
323 Health: health,
324 Running: ctr.State.Running,
325 Paused: ctr.State.Paused,
326 ExitCode: ctr.State.ExitCode,
327 }
328
329 if snapshot.Names == nil {
330 // Dead containers will often have no name, so make sure the response isn't null
331 snapshot.Names = []string{}
332 }
333
334 if ctr.HostConfig != nil {
335 snapshot.Summary.HostConfig.NetworkMode = string(ctr.HostConfig.NetworkMode)
336 snapshot.Summary.HostConfig.Annotations = maps.Clone(ctr.HostConfig.Annotations)
337 snapshot.HostConfig.Isolation = string(ctr.HostConfig.Isolation)
338 for binding := range ctr.HostConfig.PortBindings {
339 snapshot.PortBindings[binding] = struct{}{}
340 }
341 }
342
343 if ctr.Config != nil {
344 snapshot.Image = ctr.Config.Image
345 snapshot.Labels = ctr.Config.Labels
346 for exposed := range ctr.Config.ExposedPorts {
347 snapshot.ExposedPorts[exposed] = struct{}{}
348 }
349 }
350

Callers 2

AllMethod · 0.95
GetMethod · 0.95

Calls 11

getNamesMethod · 0.95
NumMethod · 0.80
StatusMethod · 0.65
StringMethod · 0.65
JoinMethod · 0.65
StartMethod · 0.65
GetMountPointsMethod · 0.45
StateMethod · 0.45
CloneMethod · 0.45
ContainsMethod · 0.45
ProtoMethod · 0.45

Tested by

no test coverage detected