MCPcopy Create free account
hub / github.com/docker/compose / getDeployResources

Function getDeployResources

pkg/compose/create.go:635–706  ·  view source on GitHub ↗
(s types.ServiceConfig)

Source from the content-addressed store, hash-verified

633}
634
635func getDeployResources(s types.ServiceConfig) container.Resources {
636 var swappiness *int64
637 if s.MemSwappiness != 0 {
638 val := int64(s.MemSwappiness)
639 swappiness = &val
640 }
641 resources := container.Resources{
642 CgroupParent: s.CgroupParent,
643 Memory: int64(s.MemLimit),
644 MemorySwap: int64(s.MemSwapLimit),
645 MemorySwappiness: swappiness,
646 MemoryReservation: int64(s.MemReservation),
647 OomKillDisable: &s.OomKillDisable,
648 CPUCount: s.CPUCount,
649 CPUPeriod: s.CPUPeriod,
650 CPUQuota: s.CPUQuota,
651 CPURealtimePeriod: s.CPURTPeriod,
652 CPURealtimeRuntime: s.CPURTRuntime,
653 CPUShares: s.CPUShares,
654 NanoCPUs: int64(s.CPUS * 1e9),
655 CPUPercent: int64(s.CPUPercent * 100),
656 CpusetCpus: s.CPUSet,
657 DeviceCgroupRules: s.DeviceCgroupRules,
658 }
659
660 if s.PidsLimit != 0 {
661 resources.PidsLimit = &s.PidsLimit
662 }
663
664 setBlkio(s.BlkioConfig, &resources)
665
666 if s.Deploy != nil {
667 setLimits(s.Deploy.Resources.Limits, &resources)
668 setReservations(s.Deploy.Resources.Reservations, &resources)
669 }
670
671 var cdiDeviceNames []string
672 for _, device := range s.Devices {
673
674 if device.Source == device.Target && cdi.IsQualifiedName(device.Source) {
675 cdiDeviceNames = append(cdiDeviceNames, device.Source)
676 continue
677 }
678
679 resources.Devices = append(resources.Devices, container.DeviceMapping{
680 PathOnHost: device.Source,
681 PathInContainer: device.Target,
682 CgroupPermissions: device.Permissions,
683 })
684 }
685
686 if len(cdiDeviceNames) > 0 {
687 resources.DeviceRequests = append(resources.DeviceRequests, container.DeviceRequest{
688 Driver: "cdi",
689 DeviceIDs: cdiDeviceNames,
690 })
691 }
692

Callers 1

getCreateConfigsMethod · 0.85

Calls 4

setBlkioFunction · 0.85
setLimitsFunction · 0.85
setReservationsFunction · 0.85
toUlimitsFunction · 0.85

Tested by

no test coverage detected