lib/hako/schedulers/ecs.rb in hako-0.15.3 vs lib/hako/schedulers/ecs.rb in hako-0.16.0

- old
+ new

@@ -17,10 +17,11 @@ def configure(options) @cluster = options.fetch('cluster', DEFAULT_CLUSTER) @desired_count = options.fetch('desired_count', nil) @region = options.fetch('region') { validation_error!('region must be set') } @role = options.fetch('role', nil) + @task_role_arn = options.fetch('task_role_arn', nil) @ecs_elb_options = options.fetch('elb', nil) @started_at = nil @container_instance_arn = nil end @@ -187,12 +188,18 @@ # @return [nil] def remove service = describe_service if service - ecs_client.delete_service(cluster: @cluster, service: @app_id) - Hako.logger.info "#{service.service_arn} is deleted" + if @dry_run + Hako.logger.info "ecs_client.update_service(cluster: #{@cluster}, service: #{@app_id}, desired_count: 0)" + Hako.logger.info "ecs_client.delete_service(cluster: #{@cluster}, service: #{@app_id})" + else + ecs_client.update_service(cluster: @cluster, service: @app_id, desired_count: 0) + ecs_client.delete_service(cluster: @cluster, service: @app_id) + Hako.logger.info "#{service.service_arn} is deleted" + end else puts "Service #{@app_id} doesn't exist" end ecs_elb_client.destroy @@ -210,11 +217,11 @@ @ec2_client ||= Aws::EC2::Client.new(region: @region) end # @return [EcsElb] def ecs_elb_client - @ecs_elb_client ||= EcsElb.new(@app_id, Aws::ElasticLoadBalancing::Client.new(region: @region), @ecs_elb_options) + @ecs_elb_client ||= EcsElb.new(@app_id, Aws::ElasticLoadBalancing::Client.new(region: @region), @ecs_elb_options, dry_run: @dry_run) end # @return [Aws::ECS::Types::Service, nil] def describe_service service = ecs_client.describe_services(cluster: @cluster, services: [@app_id]).services[0] @@ -282,10 +289,13 @@ container_definitions = {} task_definition.container_definitions.each do |c| container_definitions[c.name] = c end + if task_definition.task_role_arn != @task_role_arn + return true + end if different_volumes?(task_definition.volumes) return true end if definitions.any? { |definition| different_definition?(definition, container_definitions.delete(definition[:name])) } return true @@ -326,10 +336,11 @@ # @return [Aws::ECS::Types::TaskDefinition, Symbol] def register_task_definition(definitions) if task_definition_changed?(@app_id, definitions) ecs_client.register_task_definition( family: @app_id, + task_role_arn: @task_role_arn, container_definitions: definitions, volumes: volumes_definition, ).task_definition else :noop @@ -349,9 +360,10 @@ def register_task_definition_for_oneshot(definitions) family = "#{@app_id}-oneshot" if task_definition_changed?(family, definitions) ecs_client.register_task_definition( family: "#{@app_id}-oneshot", + task_role_arn: @task_role_arn, container_definitions: definitions, volumes: volumes_definition, ).task_definition else :noop