Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support multi target group #88

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions examples/hello-lb-v2s.jsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
{
scheduler: {
type: 'ecs',
region: 'ap-northeast-1',
cluster: 'eagletmt',
desired_count: 2,
role: 'ecsServiceRole',
// dynamic_port_mapping is enabled by default with elb_v2
// dynamic_port_mapping: false,
// health_check_grace_period_seconds: 0,
elb_v2s: [{
// VPC id where the target group is located
vpc_id: 'vpc-WWWWWWWW',
// If you want internal ELB, then use 'scheme'. (ex. internal service that like microservice inside VPC)
// scheme: internal
// Health check path of the target group
health_check_path: '/site/sha',
listeners: [
{
port: 80,
protocol: 'HTTP',
},
{
port: 443,
protocol: 'HTTPS',
certificate_arn: 'arn:aws:iam::012345678901:server-certificate/hello-lb-v2.example.com',
},
],
subnets: ['subnet-XXXXXXXX', 'subnet-YYYYYYYY'],
security_groups: ['sg-ZZZZZZZZ'],
load_balancer_attributes: {
'access_logs.s3.enabled': 'true',
'access_logs.s3.bucket': 'hako-access-logs',
'access_logs.s3.prefix': 'hako-hello-lb-v2',
},
target_group_attributes: {
// http://docs.aws.amazon.com/en_us/elasticloadbalancing/latest/application/load-balancer-target-groups.html#target-group-attributes
'deregistration_delay.timeout_seconds': '20',
},
},
},
{
// VPC id where the target group is located
vpc_id: 'vpc-WWWWWWWW',
// If you want internal ELB, then use 'scheme'. (ex. internal service that like microservice inside VPC)
// scheme: internal
// Health check path of the target group
health_check_path: '/site/stats',
listeners: [
{
port: 8888,
protocol: 'HTTP',
},
],
subnets: ['subnet-XXXXXXXX', 'subnet-YYYYYYYY'],
security_groups: ['sg-ZZZZZZZZ'],
load_balancer_attributes: {
'access_logs.s3.enabled': 'true',
'access_logs.s3.bucket': 'hako-access-logs',
'access_logs.s3.prefix': 'hako-hello-lb-v2',
},
target_group_attributes: {
// http://docs.aws.amazon.com/en_us/elasticloadbalancing/latest/application/load-balancer-target-groups.html#target-group-attributes
'deregistration_delay.timeout_seconds': '20',
},
},
}],
app: {
image: 'ryotarai/hello-sinatra',
memory: 128,
cpu: 256,
env: {
PORT: '3000',
},
secrets: [{
name: 'MESSAGE',
value_from: 'arn:aws:ssm:ap-northeast-1:012345678901:parameter/hako/hello-lb-v2/secret-message',
}],
},
sidecars: {
front: {
image_tag: 'hako-nginx',
memory: 32,
cpu: 32,
},
},
scripts: [
(import 'front.libsonnet') + {
backend_port: 3000,
locations: {
'/': {
allow_only_from: ['10.0.0.0/24'],
},
},
},
],
}
25 changes: 19 additions & 6 deletions lib/hako/schedulers/ecs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
require 'hako/schedulers/ecs_definition_comparator'
require 'hako/schedulers/ecs_elb'
require 'hako/schedulers/ecs_elb_v2'
require 'hako/schedulers/ecs_elb_v2s'
require 'hako/schedulers/ecs_service_comparator'
require 'hako/schedulers/ecs_service_discovery'
require 'hako/schedulers/ecs_volume_comparator'
Expand All @@ -37,7 +38,8 @@ def configure(options)
@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
@ecs_elb_v2s_options = options.fetch('elb_v2s', nil)
if @ecs_elb_options && @ecs_elb_v2_options && @ecs_elb_v2s_options
validation_error!('Cannot specify both elb and elb_v2')
end
@network_mode = options.fetch('network_mode', nil)
Expand All @@ -47,7 +49,7 @@ def configure(options)
end
@dynamic_port_mapping = options.fetch('dynamic_port_mapping', @ecs_elb_options.nil?)
@health_check_grace_period_seconds = options.fetch('health_check_grace_period_seconds') do
@ecs_elb_options || @ecs_elb_v2_options ? 0 : nil
@ecs_elb_options || @ecs_elb_v2_options || @ecs_elb_v2s_options ? 0 : nil
end
if options.key?('autoscaling')
@autoscaling = EcsAutoscaling.new(options.fetch('autoscaling'), @region, ecs_elb_client, dry_run: @dry_run)
Expand Down Expand Up @@ -253,7 +255,11 @@ def status

unless service.load_balancers.empty?
puts 'Load balancer:'
ecs_elb_client.show_status(service.load_balancers[0])
if @elb_v2s_config
ecs_elb_client.show_status(service.load_balancers)
else
ecs_elb_client.show_status(service.load_balancers[0])
end
end

puts 'Deployments:'
Expand Down Expand Up @@ -379,13 +385,15 @@ def ssm_client
@ssm_client ||= Aws::SSM::Client.new(region: @region)
end

# @return [EcsElb, EcsElbV2]
# @return [EcsElb, EcsElbV2, EcsElbV2s]
def ecs_elb_client
@ecs_elb_client ||=
if @ecs_elb_options
EcsElb.new(@app_id, @region, @ecs_elb_options, dry_run: @dry_run)
else
elsif @ecs_elb_v2_options
EcsElbV2.new(@app_id, @region, @ecs_elb_v2_options, dry_run: @dry_run)
else
EcsElbV2s.new(@app_id, @region, @ecs_elb_v2s_options, dry_run: @dry_run)
end
end

Expand Down Expand Up @@ -891,7 +899,12 @@ def create_initial_service(task_definition_arn, front_port)
params[:desired_count] = 0
end
if ecs_elb_client.find_or_create_load_balancer(front_port)
params[:load_balancers] = [ecs_elb_client.load_balancer_params_for_service]
params[:load_balancers] =
if @ecs_elb_v2s_options
ecs_elb_client.load_balancer_params_for_services
else
[ecs_elb_client.load_balancer_params_for_service]
end
end
if @service_discovery
@service_discovery.apply
Expand Down
Loading