@@ -266,7 +266,7 @@ func (s *Service) Up() error {
266
266
return nil
267
267
}
268
268
269
- func (s * Service ) buildUpdateServiceInput (count int64 , serviceName , taskDefinition string ) (* ecs.UpdateServiceInput , error ) {
269
+ func (s * Service ) buildUpdateServiceInput (count * int64 , serviceName , taskDefinition string ) (* ecs.UpdateServiceInput , error ) {
270
270
cluster := s .Context ().CommandConfig .Cluster
271
271
deploymentConfig := s .DeploymentConfig ()
272
272
forceDeployment := s .Context ().CLIContext .Bool (flags .ForceDeploymentFlag )
@@ -276,7 +276,7 @@ func (s *Service) buildUpdateServiceInput(count int64, serviceName, taskDefiniti
276
276
}
277
277
278
278
input := & ecs.UpdateServiceInput {
279
- DesiredCount : aws . Int64 ( count ) ,
279
+ DesiredCount : count ,
280
280
Service : aws .String (serviceName ),
281
281
Cluster : aws .String (cluster ),
282
282
DeploymentConfiguration : deploymentConfig ,
@@ -303,6 +303,11 @@ func (s *Service) updateService(ecsService *ecs.Service, newTaskDefinition *ecs.
303
303
return fmt .Errorf ("Service Discovery can not be enabled on an existing ECS Service" )
304
304
}
305
305
306
+ schedulingStrategy := strings .ToUpper (s .Context ().CLIContext .String (flags .SchedulingStrategyFlag ))
307
+ if schedulingStrategy != "" && schedulingStrategy != aws .StringValue (ecsService .SchedulingStrategy ) {
308
+ return fmt .Errorf ("Scheduling Strategy cannot be updated on an existing ECS Service" )
309
+ }
310
+
306
311
ecsServiceName := aws .StringValue (ecsService .ServiceName )
307
312
if s .loadBalancer != nil {
308
313
log .WithFields (log.Fields {
@@ -312,22 +317,27 @@ func (s *Service) updateService(ecsService *ecs.Service, newTaskDefinition *ecs.
312
317
313
318
oldCount := aws .Int64Value (ecsService .DesiredCount )
314
319
newCount := int64 (1 )
320
+ count := & newCount
315
321
if oldCount != 0 {
316
- newCount = oldCount // get the current non-zero count
322
+ count = & oldCount // get the current non-zero count
317
323
}
318
324
319
325
// if both the task definitions are the same, call update with the new count
320
326
oldTaskDefinitionId := entity .GetIdFromArn (ecsService .TaskDefinition )
321
327
newTaskDefinitionId := entity .GetIdFromArn (newTaskDefinition .TaskDefinitionArn )
322
328
329
+ if aws .StringValue (ecsService .SchedulingStrategy ) == ecs .SchedulingStrategyDaemon {
330
+ count = nil
331
+ }
332
+
323
333
if oldTaskDefinitionId == newTaskDefinitionId {
324
- return s .updateServiceCount (newCount )
334
+ return s .updateServiceCount (count )
325
335
}
326
336
327
337
// if the task definitions were different, updateService with new task definition
328
338
// this creates a deployment in ECS and slowly takes down the containers with old ones and starts new ones
329
339
330
- updateServiceInput , err := s .buildUpdateServiceInput (newCount , ecsServiceName , newTaskDefinitionId )
340
+ updateServiceInput , err := s .buildUpdateServiceInput (count , ecsServiceName , newTaskDefinitionId )
331
341
if err != nil {
332
342
return err
333
343
}
@@ -338,7 +348,7 @@ func (s *Service) updateService(ecsService *ecs.Service, newTaskDefinition *ecs.
338
348
}
339
349
340
350
message := "Updated the ECS service with a new task definition. " +
341
- "Old containers will be stopped automatically, and replaced with new ones"
351
+ "Old containers will be stopped automatically, and replaced with new ones"
342
352
s .logUpdateService (updateServiceInput , message )
343
353
344
354
return waitForServiceTasks (s , ecsServiceName )
@@ -354,13 +364,13 @@ func (s *Service) Info(filterProjectTasks bool) (project.InfoSet, error) {
354
364
355
365
// Scale the service desired count to be the specified count
356
366
func (s * Service ) Scale (count int ) error {
357
- return s .updateServiceCount (int64 (count ))
367
+ return s .updateServiceCount (aws . Int64 ( int64 (count ) ))
358
368
}
359
369
360
370
// Stop stops all the containers in the service by calling ECS.UpdateService(count=0)
361
371
// TODO, Store the current desiredCount in a cache, so that number of tasks(group of containers) can be started again
362
372
func (s * Service ) Stop () error {
363
- return s .updateServiceCount (int64 (0 ))
373
+ return s .updateServiceCount (aws . Int64 (0 ))
364
374
}
365
375
366
376
// Down stops any running containers(tasks) by calling Stop() and deletes an active ECS Service
@@ -382,7 +392,7 @@ func (s *Service) Down() error {
382
392
}
383
393
384
394
// stop any running tasks
385
- if aws .Int64Value (ecsService .DesiredCount ) != 0 {
395
+ if aws .Int64Value (ecsService .DesiredCount ) != 0 && aws . StringValue ( ecsService . SchedulingStrategy ) != ecs . SchedulingStrategyDaemon {
386
396
if err = s .Stop (); err != nil {
387
397
return err
388
398
}
@@ -434,6 +444,7 @@ func (s *Service) buildCreateServiceInput(serviceName, taskDefName string) (*ecs
434
444
launchType := s .Context ().CommandConfig .LaunchType
435
445
cluster := s .Context ().CommandConfig .Cluster
436
446
ecsParams := s .ecsContext .ECSParams
447
+ schedulingStrategy := strings .ToUpper (s .Context ().CLIContext .String (flags .SchedulingStrategyFlag ))
437
448
438
449
networkConfig , err := composeutils .ConvertToECSNetworkConfiguration (ecsParams )
439
450
if err != nil {
@@ -458,7 +469,7 @@ func (s *Service) buildCreateServiceInput(serviceName, taskDefName string) (*ecs
458
469
}
459
470
460
471
createServiceInput := & ecs.CreateServiceInput {
461
- DesiredCount : aws .Int64 (0 ), // Required
472
+ DesiredCount : aws .Int64 (0 ), // Required unless DAEMON schedulingStrategy
462
473
ServiceName : aws .String (serviceName ), // Required
463
474
TaskDefinition : aws .String (taskDefName ), // Required
464
475
Cluster : aws .String (cluster ),
@@ -467,6 +478,13 @@ func (s *Service) buildCreateServiceInput(serviceName, taskDefName string) (*ecs
467
478
Role : aws .String (s .role ),
468
479
}
469
480
481
+ if schedulingStrategy != "" {
482
+ createServiceInput .SchedulingStrategy = aws .String (schedulingStrategy )
483
+ if schedulingStrategy == ecs .SchedulingStrategyDaemon {
484
+ createServiceInput .DesiredCount = nil
485
+ }
486
+ }
487
+
470
488
if s .healthCheckGP != nil {
471
489
createServiceInput .HealthCheckGracePeriodSeconds = aws .Int64 (* s .healthCheckGP )
472
490
}
@@ -582,32 +600,40 @@ func (s *Service) startService() error {
582
600
}
583
601
return err
584
602
}
603
+
604
+ serviceName := aws .StringValue (ecsService .ServiceName )
585
605
desiredCount := aws .Int64Value (ecsService .DesiredCount )
586
606
forceDeployment := s .Context ().CLIContext .Bool (flags .ForceDeploymentFlag )
587
- if desiredCount != 0 {
588
- serviceName := aws . StringValue ( ecsService . ServiceName )
607
+ schedulingStrategy := aws . StringValue ( ecsService . SchedulingStrategy )
608
+ if desiredCount != 0 || schedulingStrategy == ecs . SchedulingStrategyDaemon {
589
609
if forceDeployment {
590
610
log .WithFields (log.Fields {
591
- "serviceName" : serviceName ,
592
- "desiredCount" : desiredCount ,
593
- "force-deployment" : strconv .FormatBool (forceDeployment ),
611
+ "serviceName" : serviceName ,
612
+ "desiredCount" : desiredCount ,
613
+ "schedulingStrategy" : schedulingStrategy ,
614
+ "force-deployment" : strconv .FormatBool (forceDeployment ),
594
615
}).Info ("Forcing new deployment of running ECS Service" )
595
- return s .updateServiceCount (desiredCount )
616
+ count := aws .Int64 (desiredCount )
617
+ if schedulingStrategy == ecs .SchedulingStrategyDaemon {
618
+ count = nil
619
+ }
620
+ return s .updateServiceCount (count )
596
621
}
597
622
//NoOp
598
623
log .WithFields (log.Fields {
599
- "serviceName" : serviceName ,
600
- "desiredCount" : desiredCount ,
624
+ "serviceName" : serviceName ,
625
+ "desiredCount" : desiredCount ,
626
+ "schedulingStrategy" : schedulingStrategy ,
601
627
}).Info ("ECS Service is already running" )
602
628
603
629
return waitForServiceTasks (s , serviceName )
604
630
}
605
- return s .updateServiceCount (int64 (1 ))
631
+ return s .updateServiceCount (aws . Int64 (1 ))
606
632
}
607
633
608
634
// updateServiceCount calls the underlying ECS.UpdateService with the specified count
609
635
// NOTE: If network configuration has changed in ECS Params, this will also be updated
610
- func (s * Service ) updateServiceCount (count int64 ) error {
636
+ func (s * Service ) updateServiceCount (count * int64 ) error {
611
637
serviceName := entity .GetServiceName (s )
612
638
613
639
updateServiceInput , err := s .buildUpdateServiceInput (count , serviceName , "" )
@@ -626,7 +652,7 @@ func (s *Service) updateServiceCount(count int64) error {
626
652
627
653
func (s * Service ) logUpdateService (input * ecs.UpdateServiceInput , message string ) {
628
654
fields := log.Fields {
629
- "service" : aws .StringValue (input .Service ),
655
+ "service" : aws .StringValue (input .Service ),
630
656
"desiredCount" : aws .Int64Value (input .DesiredCount ),
631
657
}
632
658
if s .deploymentConfig != nil && s .deploymentConfig .MaximumPercent != nil {
0 commit comments