Sha256: c12e54f438e06d88fea59aee48d26f9472a5837e5536be4e0037585cfaeeb9d8

Contents?: true

Size: 1.66 KB

Versions: 12

Compression:

Stored size: 1.66 KB

Contents

# frozen_string_literal: true
module KubernetesDeploy
  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.v2beta1.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
kubernetes-deploy-0.30.0 lib/kubernetes-deploy/kubernetes_resource/horizontal_pod_autoscaler.rb
kubernetes-deploy-0.29.0 lib/kubernetes-deploy/kubernetes_resource/horizontal_pod_autoscaler.rb
kubernetes-deploy-0.28.0 lib/kubernetes-deploy/kubernetes_resource/horizontal_pod_autoscaler.rb
kubernetes-deploy-0.27.0 lib/kubernetes-deploy/kubernetes_resource/horizontal_pod_autoscaler.rb
kubernetes-deploy-0.26.7 lib/kubernetes-deploy/kubernetes_resource/horizontal_pod_autoscaler.rb
kubernetes-deploy-0.26.6 lib/kubernetes-deploy/kubernetes_resource/horizontal_pod_autoscaler.rb
kubernetes-deploy-0.26.5 lib/kubernetes-deploy/kubernetes_resource/horizontal_pod_autoscaler.rb
kubernetes-deploy-0.26.4 lib/kubernetes-deploy/kubernetes_resource/horizontal_pod_autoscaler.rb
kubernetes-deploy-0.26.3 lib/kubernetes-deploy/kubernetes_resource/horizontal_pod_autoscaler.rb
kubernetes-deploy-0.26.2 lib/kubernetes-deploy/kubernetes_resource/horizontal_pod_autoscaler.rb
kubernetes-deploy-0.26.1 lib/kubernetes-deploy/kubernetes_resource/horizontal_pod_autoscaler.rb
kubernetes-deploy-0.26.0 lib/kubernetes-deploy/kubernetes_resource/horizontal_pod_autoscaler.rb