lib/hako/schedulers/ecs.rb in hako-1.3.2 vs lib/hako/schedulers/ecs.rb in hako-1.3.3

- old
+ new

@@ -355,10 +355,14 @@ # @return [Array<Boolean] def task_definition_changed?(desired_definitions, actual_definition) if @force return true end + if !actual_definition + # Initial deployment + return true + end container_definitions = {} actual_definition.container_definitions.each do |c| container_definitions[c.name] = c end @@ -370,13 +374,10 @@ end if desired_definitions.any? { |definition| different_definition?(definition, container_definitions.delete(definition[:name])) } return true end !container_definitions.empty? - rescue Aws::ECS::Errors::ClientException - # Task definition does not exist - true end # @param [Hash<String, Hash<String, String>>] actual_volumes # @return [Boolean] def different_volumes?(actual_volumes) @@ -404,11 +405,11 @@ end # @param [Array<Hash>] definitions # @return [Array<Boolean, Aws::ECS::Types::TaskDefinition>] def register_task_definition(definitions) - current_task_definition = ecs_client.describe_task_definition(task_definition: @app_id).task_definition + current_task_definition = describe_task_definition(@app_id) if task_definition_changed?(definitions, current_task_definition) new_task_definition = ecs_client.register_task_definition( family: @app_id, task_role_arn: @task_role_arn, container_definitions: definitions, @@ -430,11 +431,11 @@ # @param [Array<Hash>] definitions # @return [Array<Boolean, Aws::ECS::Types::TaskDefinition] def register_task_definition_for_oneshot(definitions) family = "#{@app_id}-oneshot" - current_task_definition = ecs_client.describe_task_definition(task_definition: family).task_definition + current_task_definition = describe_task_definition(family) if task_definition_changed?(definitions, current_task_definition) new_task_definition = ecs_client.register_task_definition( family: family, task_role_arn: @task_role_arn, container_definitions: definitions, @@ -454,10 +455,17 @@ host: { source_path: volume['source_path'] }, } end end + def describe_task_definition(family) + ecs_client.describe_task_definition(task_definition: family).task_definition + rescue Aws::ECS::Errors::ClientException + # Task definition does not exist + nil + end + # @param [String] name # @param [Container] container # @return [Hash] def create_definition(name, container) environment = container.env.map { |k, v| { name: k, value: v } } @@ -839,10 +847,16 @@ end unless asg raise Error.new("AutoScaling Group '#{@autoscaling_group_for_oneshot}' does not exist") end - container_instances = ecs_client.list_container_instances(cluster: @cluster).flat_map { |c| ecs_client.describe_container_instances(cluster: @cluster, container_instances: c.container_instance_arns).container_instances } + container_instances = ecs_client.list_container_instances(cluster: @cluster).flat_map do |c| + if c.container_instance_arns.empty? + [] + else + ecs_client.describe_container_instances(cluster: @cluster, container_instances: c.container_instance_arns).container_instances + end + end if has_capacity?(task_definition, container_instances) Hako.logger.info("There's remaining capacity. Start retrying...") return true end