lib/hako/schedulers/ecs.rb in hako-0.19.0 vs lib/hako/schedulers/ecs.rb in hako-0.20.0

- old
+ new

@@ -3,10 +3,11 @@ require 'hako' require 'hako/error' require 'hako/scheduler' require 'hako/schedulers/ecs_definition_comparator' require 'hako/schedulers/ecs_elb' +require 'hako/schedulers/ecs_elb_v2' require 'hako/schedulers/ecs_autoscaling' module Hako module Schedulers class Ecs < Scheduler @@ -24,10 +25,15 @@ @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) + @ecs_elb_v2_options = options.fetch('elb_v2', nil) + if @ecs_elb_options && @ecs_elb_v2_options + validation_error!('Cannot specify both elb and elb_v2') + end + @dynamic_port_mapping = options.fetch('dynamic_port_mapping', @ecs_elb_options.nil?) if options.key?('autoscaling') @autoscaling = EcsAutoscaling.new(options.fetch('autoscaling'), dry_run: @dry_run) end @started_at = nil @container_instance_arn = nil @@ -152,17 +158,12 @@ puts 'Unavailable' exit 1 end unless service.load_balancers.empty? - lb = service.load_balancers[0] - lb_detail = ecs_elb_client.describe_load_balancer puts 'Load balancer:' - lb_detail.listener_descriptions.each do |ld| - l = ld.listener - puts " #{lb_detail.dns_name}:#{l.load_balancer_port} -> #{lb.container_name}:#{lb.container_port}" - end + ecs_elb_client.show_status(service.load_balancers[0]) end puts 'Deployments:' service.deployments.each do |d| abbrev_task_definition = d.task_definition.slice(%r{task-definition/(.+)\z}, 1) @@ -243,13 +244,18 @@ # @return [Aws::EC2::Client] def ec2_client @ec2_client ||= Aws::EC2::Client.new(region: @region) end - # @return [EcsElb] + # @return [EcsElb, EcsElbV2] def ecs_elb_client - @ecs_elb_client ||= EcsElb.new(@app_id, Aws::ElasticLoadBalancing::Client.new(region: @region), @ecs_elb_options, dry_run: @dry_run) + @ecs_elb_client ||= + if @ecs_elb_options + EcsElb.new(@app_id, @region, @ecs_elb_options, dry_run: @dry_run) + else + EcsElbV2.new(@app_id, @region, @ecs_elb_v2_options, dry_run: @dry_run) + end end # @return [Aws::ECS::Types::Service, nil] def describe_service service = ecs_client.describe_services(cluster: @cluster, services: [@app_id]).services[0] @@ -258,10 +264,13 @@ end end # @return [Fixnum] def determine_front_port + if @dynamic_port_mapping + return 0 + end if @dry_run return DEFAULT_FRONT_PORT end service = describe_service if service @@ -553,17 +562,12 @@ service_name: @app_id, task_definition: task_definition_arn, desired_count: @desired_count, role: @role, } - name = ecs_elb_client.find_or_create_load_balancer(front_port) - if name + if ecs_elb_client.find_or_create_load_balancer(front_port) params[:load_balancers] = [ - { - load_balancer_name: name, - container_name: 'front', - container_port: 80, - }, + @ecs_elb_client.load_balancer_params_for_service.merge(container_name: 'front', container_port: 80), ] end ecs_client.create_service(params).service else params = {