Sha256: fa5566ddd26ceea61bdf3e077731df6c21692fab4c27d27c4f3b1c39b0ec8d8d

Contents?: true

Size: 1.65 KB

Versions: 12

Compression:

Stored size: 1.65 KB

Contents

# frozen_string_literal: true
module Krane
  class HorizontalPodAutoscaler < KubernetesResource
    TIMEOUT = 3.minutes
    RECOVERABLE_CONDITION_PREFIX = "FailedGet"

    def deploy_succeeded?
      scaling_active_condition["status"] == "True" || scaling_disabled?
    end

    def deploy_failed?
      return false unless exists?
      return false if scaling_disabled?
      scaling_active_condition["status"] == "False" &&
      !scaling_active_condition.fetch("reason", "").start_with?(RECOVERABLE_CONDITION_PREFIX)
    end

    def kubectl_resource_type
      'hpa.v2.autoscaling'
    end

    def status
      if !exists?
        super
      elsif scaling_disabled?
        "ScalingDisabled"
      elsif deploy_succeeded?
        "Configured"
      elsif scaling_active_condition.present? || able_to_scale_condition.present?
        condition = scaling_active_condition.presence || able_to_scale_condition
        condition['reason']
      else
        "Unknown"
      end
    end

    def failure_message
      condition = scaling_active_condition.presence || able_to_scale_condition.presence || {}
      condition['message']
    end

    def timeout_message
      failure_message.presence || super
    end

    private

    def scaling_disabled?
      scaling_active_condition["status"] == "False" &&
      scaling_active_condition["reason"] == "ScalingDisabled"
    end

    def conditions
      @instance_data.dig("status", "conditions") || []
    end

    def able_to_scale_condition
      conditions.detect { |c| c["type"] == "AbleToScale" } || {}
    end

    def scaling_active_condition
      conditions.detect { |c| c["type"] == "ScalingActive" } || {}
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
krane-3.7.0 lib/krane/kubernetes_resource/horizontal_pod_autoscaler.rb
krane-3.6.2 lib/krane/kubernetes_resource/horizontal_pod_autoscaler.rb
krane-3.6.1 lib/krane/kubernetes_resource/horizontal_pod_autoscaler.rb
krane-3.5.2 lib/krane/kubernetes_resource/horizontal_pod_autoscaler.rb
krane-3.5.1 lib/krane/kubernetes_resource/horizontal_pod_autoscaler.rb
krane-3.5.0 lib/krane/kubernetes_resource/horizontal_pod_autoscaler.rb
krane-3.4.2 lib/krane/kubernetes_resource/horizontal_pod_autoscaler.rb
krane-3.4.1 lib/krane/kubernetes_resource/horizontal_pod_autoscaler.rb
krane-3.4.0 lib/krane/kubernetes_resource/horizontal_pod_autoscaler.rb
krane-3.3.0 lib/krane/kubernetes_resource/horizontal_pod_autoscaler.rb
krane-3.2.0 lib/krane/kubernetes_resource/horizontal_pod_autoscaler.rb
krane-3.1.0 lib/krane/kubernetes_resource/horizontal_pod_autoscaler.rb