Skip to content
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
2 changes: 1 addition & 1 deletion hako.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
spec.add_dependency 'aws-sdk-cloudwatch'
spec.add_dependency 'aws-sdk-cloudwatchlogs'
spec.add_dependency 'aws-sdk-ec2'
spec.add_dependency 'aws-sdk-ecs', '>= 1.54.0'
spec.add_dependency 'aws-sdk-ecs', '>= 1.97.0'
spec.add_dependency 'aws-sdk-elasticloadbalancing'
spec.add_dependency 'aws-sdk-elasticloadbalancingv2', '>= 1.54.0'
spec.add_dependency 'aws-sdk-s3'
Expand Down
24 changes: 7 additions & 17 deletions lib/hako/schedulers/ecs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,18 +166,12 @@ def deploy(containers)
@autoscaling.apply(current_service)
end
ecs_elb_client.modify_attributes
if @service_discovery
@service_discovery.apply
end
else
Hako.logger.info "Updated service: #{service.service_arn}"
if @autoscaling
@autoscaling.apply(service)
end
ecs_elb_client.modify_attributes
if @service_discovery
@service_discovery.apply
end
unless wait_for_ready(service)
@scripts.each { |script| script.deploy_failed(containers, task_ids: @started_task_ids) }
if task_definition_changed
Expand Down Expand Up @@ -967,7 +961,13 @@ def update_service(current_service, task_definition_arn)
params[:force_new_deployment] = true
end
warn_placement_policy_change(current_service)
warn_service_registries_change(current_service)
params[:service_registries] =
if @service_discovery
@service_discovery.apply
@service_discovery.service_registries
else
[]
end
if service_changed?(current_service, params)
ecs_client.update_service(**params).service
else
Expand Down Expand Up @@ -1533,16 +1533,6 @@ def warn_placement_policy_change(service)
end
end

# @param [Aws::ECS::Types::Service] service
# @return [void]
def warn_service_registries_change(service)
actual_service_registries = service.service_registries.sort_by(&:registry_arn).map(&:to_h)
expected_service_registries = @service_discovery&.service_registries&.sort_by { |s| s[:registry_arn] } || []
if actual_service_registries != expected_service_registries
Hako.logger.warn "Ignoring updated service_registries in the configuration, because AWS doesn't allow updating them for now."
end
end

# @param [Aws::ECS::Types::TaskDefinition] task_definition
# @param [String] target_definition
# @return [nil]
Expand Down
10 changes: 10 additions & 0 deletions lib/hako/schedulers/ecs_service_comparator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def service_schema
struct.member(:platform_version, Schema::WithDefault.new(Schema::String.new, 'LATEST'))
struct.member(:network_configuration, Schema::Nullable.new(network_configuration_schema))
struct.member(:health_check_grace_period_seconds, Schema::Nullable.new(Schema::Integer.new))
struct.member(:service_registries, Schema::UnorderedArray.new(service_registry_schema))
end
end

Expand Down Expand Up @@ -59,6 +60,15 @@ def awsvpc_configuration_schema
end
end

def service_registry_schema
Schema::Structure.new.tap do |struct|
struct.member(:registry_arn, Schema::String.new)
struct.member(:container_name, Schema::String.new)
struct.member(:container_port, Schema::Integer.new)
struct.member(:port, Schema::Nullable.new(Schema::Integer.new))
end
end

def default_configuration
{
maximum_percent: 200,
Expand Down
2 changes: 2 additions & 0 deletions spec/hako/schedulers/ecs_service_comparator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
maximum_percent: 100,
minimum_healthy_percent: 0,
},
service_registries: [],
}
end
let(:actual_service) do
Expand All @@ -26,6 +27,7 @@
maximum_percent: 100,
minimum_healthy_percent: 0,
),
service_registries: [],
)
end

Expand Down
7 changes: 7 additions & 0 deletions spec/hako/schedulers/ecs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
platform_version: nil,
network_configuration: nil,
health_check_grace_period_seconds: nil,
service_registries: [],
}
end
let(:register_task_definition_params) do
Expand Down Expand Up @@ -391,6 +392,7 @@
expect(ecs_client).to receive(:update_service).with(update_service_params.merge(
task_definition: task_definition_arn,
health_check_grace_period_seconds: 0,
service_registries: [],
)).and_return(Aws::ECS::Types::UpdateServiceResponse.new(
service: Aws::ECS::Types::Service.new(
cluster_arn: cluster_arn,
Expand Down Expand Up @@ -499,6 +501,11 @@
)).once
expect(ecs_client).to receive(:update_service).with(update_service_params.merge(
task_definition: task_definition_arn,
service_registries: [{
container_name: 'app',
container_port: 80,
registry_arn: service_discovery_service_arn,
}],
)).and_return(Aws::ECS::Types::UpdateServiceResponse.new(
service: Aws::ECS::Types::Service.new(
cluster_arn: cluster_arn,
Expand Down