Sha256: 3319f76935f7238916f94d9939e791434449d85b0a4517ce918a73cf972d5da0

Contents?: true

Size: 1.98 KB

Versions: 11

Compression:

Stored size: 1.98 KB

Contents

# frozen_string_literal: true

require 'hako/schema'

module Hako
  module Schedulers
    class EcsServiceComparator
      def initialize(expected_service)
        @expected_service = expected_service
        @schema = service_schema
      end

      # @param [Aws::ECS::Types::Service] actual_service
      # @return [Boolean]
      def different?(actual_service)
        !@schema.same?(actual_service.to_h, @expected_service)
      end

      private

      def service_schema
        Schema::Structure.new.tap do |struct|
          struct.member(:desired_count, Schema::Integer.new)
          struct.member(:task_definition, Schema::String.new)
          struct.member(:deployment_configuration, Schema::WithDefault.new(deployment_configuration_schema, default_configuration))
          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))
        end
      end

      def deployment_configuration_schema
        Schema::Structure.new.tap do |struct|
          struct.member(:maximum_percent, Schema::Integer.new)
          struct.member(:minimum_healthy_percent, Schema::Integer.new)
        end
      end

      def network_configuration_schema
        Schema::Structure.new.tap do |struct|
          struct.member(:awsvpc_configuration, awsvpc_configuration_schema)
        end
      end

      def awsvpc_configuration_schema
        Schema::Structure.new.tap do |struct|
          struct.member(:subnets, Schema::UnorderedArray.new(Schema::String.new))
          struct.member(:security_groups, Schema::UnorderedArray.new(Schema::String.new))
          struct.member(:assign_public_ip, Schema::String.new)
        end
      end

      def default_configuration
        {
          maximum_percent: 200,
          minimum_healthy_percent: 100,
        }
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
hako-2.12.0 lib/hako/schedulers/ecs_service_comparator.rb
hako-2.11.1 lib/hako/schedulers/ecs_service_comparator.rb
hako-2.11.0 lib/hako/schedulers/ecs_service_comparator.rb
hako-2.10.0 lib/hako/schedulers/ecs_service_comparator.rb
hako-2.9.2 lib/hako/schedulers/ecs_service_comparator.rb
hako-2.9.1 lib/hako/schedulers/ecs_service_comparator.rb
hako-2.9.0 lib/hako/schedulers/ecs_service_comparator.rb
hako-2.8.0 lib/hako/schedulers/ecs_service_comparator.rb
hako-2.7.0 lib/hako/schedulers/ecs_service_comparator.rb
hako-2.6.2 lib/hako/schedulers/ecs_service_comparator.rb
hako-2.6.1 lib/hako/schedulers/ecs_service_comparator.rb