@@ -25,15 +25,13 @@ import (
25
25
"time"
26
26
27
27
apiappmesh "github.com/aws/amazon-ecs-agent/agent/api/appmesh"
28
- "github.com/aws/amazon-ecs-agent/agent/api/container"
29
28
apicontainer "github.com/aws/amazon-ecs-agent/agent/api/container"
30
29
apicontainerstatus "github.com/aws/amazon-ecs-agent/agent/api/container/status"
31
30
"github.com/aws/amazon-ecs-agent/agent/api/serviceconnect"
32
31
apitaskstatus "github.com/aws/amazon-ecs-agent/agent/api/task/status"
33
32
"github.com/aws/amazon-ecs-agent/agent/config"
34
33
"github.com/aws/amazon-ecs-agent/agent/dockerclient"
35
34
"github.com/aws/amazon-ecs-agent/agent/dockerclient/dockerapi"
36
- "github.com/aws/amazon-ecs-agent/agent/ecs_client/model/ecs"
37
35
"github.com/aws/amazon-ecs-agent/agent/taskresource"
38
36
"github.com/aws/amazon-ecs-agent/agent/taskresource/asmauth"
39
37
"github.com/aws/amazon-ecs-agent/agent/taskresource/asmsecret"
@@ -3527,138 +3525,3 @@ func (task *Task) IsServiceConnectConnectionDraining() bool {
3527
3525
defer task .lock .RUnlock ()
3528
3526
return task .ServiceConnectConnectionDrainingUnsafe
3529
3527
}
3530
-
3531
- // ToHostResources will convert a task to a map of resources which ECS takes into account when scheduling tasks on instances
3532
- // * CPU
3533
- // - If task level CPU is set, use that
3534
- // - Else add up container CPUs
3535
- //
3536
- // * Memory
3537
- // - If task level memory is set, use that
3538
- // - Else add up container level
3539
- // - If memoryReservation field is set, use that
3540
- // - Else use memory field
3541
- //
3542
- // * Ports (TCP/UDP)
3543
- // - Only account for hostPort
3544
- // - Don't need to account for awsvpc mode, each task gets its own namespace
3545
- //
3546
- // * GPU
3547
- // - Return num of gpus requested (len of GPUIDs field)
3548
- //
3549
- // TODO remove this once ToHostResources is used
3550
- //
3551
- //lint:file-ignore U1000 Ignore all unused code
3552
- func (task * Task ) ToHostResources () map [string ]* ecs.Resource {
3553
- resources := make (map [string ]* ecs.Resource )
3554
- // CPU
3555
- if task .CPU > 0 {
3556
- // cpu unit is vcpu at task level
3557
- // convert to cpushares
3558
- taskCPUint64 := int64 (task .CPU * 1024 )
3559
- resources ["CPU" ] = & ecs.Resource {
3560
- Name : utils .Strptr ("CPU" ),
3561
- Type : utils .Strptr ("INTEGER" ),
3562
- IntegerValue : & taskCPUint64 ,
3563
- }
3564
- } else {
3565
- // cpu unit is cpushares at container level
3566
- containerCPUint64 := int64 (0 )
3567
- for _ , container := range task .Containers {
3568
- containerCPUint64 += int64 (container .CPU )
3569
- }
3570
- resources ["CPU" ] = & ecs.Resource {
3571
- Name : utils .Strptr ("CPU" ),
3572
- Type : utils .Strptr ("INTEGER" ),
3573
- IntegerValue : & containerCPUint64 ,
3574
- }
3575
- }
3576
-
3577
- // Memory
3578
- if task .Memory > 0 {
3579
- // memory unit is MiB at task level
3580
- taskMEMint64 := task .Memory
3581
- resources ["MEMORY" ] = & ecs.Resource {
3582
- Name : utils .Strptr ("MEMORY" ),
3583
- Type : utils .Strptr ("INTEGER" ),
3584
- IntegerValue : & taskMEMint64 ,
3585
- }
3586
- } else {
3587
- containerMEMint64 := int64 (0 )
3588
- // To parse memory reservation / soft limit
3589
- hostConfig := & dockercontainer.HostConfig {}
3590
-
3591
- for _ , c := range task .Containers {
3592
- if c .DockerConfig .HostConfig != nil {
3593
- err := json .Unmarshal ([]byte (* c .DockerConfig .HostConfig ), hostConfig )
3594
- if err != nil || hostConfig .MemoryReservation <= 0 {
3595
- // container memory unit is MiB, keeping as is
3596
- containerMEMint64 += int64 (c .Memory )
3597
- } else {
3598
- // Soft limit is specified in MiB units but translated to bytes while being transferred to Agent
3599
- // Converting back to MiB
3600
- containerMEMint64 += hostConfig .MemoryReservation / (1024 * 1024 )
3601
- }
3602
- } else {
3603
- // container memory unit is MiB, keeping as is
3604
- containerMEMint64 += int64 (c .Memory )
3605
- }
3606
- }
3607
- resources ["MEMORY" ] = & ecs.Resource {
3608
- Name : utils .Strptr ("MEMORY" ),
3609
- Type : utils .Strptr ("INTEGER" ),
3610
- IntegerValue : & containerMEMint64 ,
3611
- }
3612
- }
3613
-
3614
- // PORTS_TCP and PORTS_UDP
3615
- var tcpPortSet []uint16
3616
- var udpPortSet []uint16
3617
-
3618
- // AWSVPC tasks have 'host' ports mapped to task ENI, not to host
3619
- // So don't need to keep an 'account' of awsvpc tasks with host ports fields assigned
3620
- if ! task .IsNetworkModeAWSVPC () {
3621
- for _ , c := range task .Containers {
3622
- for _ , port := range c .Ports {
3623
- hostPort := port .HostPort
3624
- protocol := port .Protocol
3625
- if hostPort > 0 && protocol == container .TransportProtocolTCP {
3626
- tcpPortSet = append (tcpPortSet , hostPort )
3627
- } else if hostPort > 0 && protocol == container .TransportProtocolUDP {
3628
- udpPortSet = append (udpPortSet , hostPort )
3629
- }
3630
- }
3631
- }
3632
- }
3633
- resources ["PORTS_TCP" ] = & ecs.Resource {
3634
- Name : utils .Strptr ("PORTS_TCP" ),
3635
- Type : utils .Strptr ("STRINGSET" ),
3636
- StringSetValue : utils .Uint16SliceToStringSlice (tcpPortSet ),
3637
- }
3638
- resources ["PORTS_UDP" ] = & ecs.Resource {
3639
- Name : utils .Strptr ("PORTS_UDP" ),
3640
- Type : utils .Strptr ("STRINGSET" ),
3641
- StringSetValue : utils .Uint16SliceToStringSlice (udpPortSet ),
3642
- }
3643
-
3644
- // GPU
3645
- var num_gpus int64
3646
- num_gpus = 0
3647
- for _ , c := range task .Containers {
3648
- num_gpus += int64 (len (c .GPUIDs ))
3649
- }
3650
- resources ["GPU" ] = & ecs.Resource {
3651
- Name : utils .Strptr ("GPU" ),
3652
- Type : utils .Strptr ("INTEGER" ),
3653
- IntegerValue : & num_gpus ,
3654
- }
3655
- logger .Debug ("Task host resources to account for" , logger.Fields {
3656
- "taskArn" : task .Arn ,
3657
- "CPU" : * resources ["CPU" ].IntegerValue ,
3658
- "MEMORY" : * resources ["MEMORY" ].IntegerValue ,
3659
- "PORTS_TCP" : resources ["PORTS_TCP" ].StringSetValue ,
3660
- "PORTS_UDP" : resources ["PORTS_UDP" ].StringSetValue ,
3661
- "GPU" : * resources ["GPU" ].IntegerValue ,
3662
- })
3663
- return resources
3664
- }
0 commit comments