diff --git a/lib/kubernetes-deploy/kubeclient_builder.rb b/lib/kubernetes-deploy/kubeclient_builder.rb index 1e3919f30..b5d3693fd 100644 --- a/lib/kubernetes-deploy/kubeclient_builder.rb +++ b/lib/kubernetes-deploy/kubeclient_builder.rb @@ -52,14 +52,6 @@ def build_apps_v1beta1_kubeclient(context) ) end - def build_autoscaling_v2beta1_kubeclient(context) - _build_kubeclient( - api_version: "v2beta1", - context: context, - endpoint_path: "/apis/autoscaling" - ) - end - def _build_kubeclient(api_version:, context:, endpoint_path: nil) # Find a context defined in kube conf files that matches the input context by name friendly_configs = config_files.map { |f| GoogleFriendlyConfig.read(f) } diff --git a/lib/kubernetes-deploy/kubernetes_resource/horizontal_pod_autoscaler.rb b/lib/kubernetes-deploy/kubernetes_resource/horizontal_pod_autoscaler.rb index fa0c0ccbd..a31e033d1 100644 --- a/lib/kubernetes-deploy/kubernetes_resource/horizontal_pod_autoscaler.rb +++ b/lib/kubernetes-deploy/kubernetes_resource/horizontal_pod_autoscaler.rb @@ -1,25 +1,36 @@ # frozen_string_literal: true module KubernetesDeploy class HorizontalPodAutoscaler < KubernetesResource - PRUNABLE = true TIMEOUT = 30.seconds def deploy_succeeded? - conditions = @instance_data.dig("status", "conditions") || [] - able_to_scale = conditions.detect { |c| c["type"] == "AbleToScale" } || {} - able_to_scale["status"] == "True" + able_to_scale_condition["status"] == "True" end def deploy_failed? - !exists? - end - - def timeout_message - UNUSUAL_FAILURE_MESSAGE + return false unless exists? + able_to_scale_condition["status"] == "False" end def type 'hpa.v2beta1.autoscaling' end + + def status + if !exists? + super + elsif deploy_succeeded? + "Succeeded" + else + able_to_scale_condition["reason"] + end + end + + private + + def able_to_scale_condition + conditions = @instance_data.dig("status", "conditions") || [] + conditions.detect { |c| c["type"] == "AbleToScale" } || {} + end end end diff --git a/test/fixtures/hpa/deployment.yml b/test/fixtures/hpa/deployment.yml index 213ab6b38..abc2d7832 100644 --- a/test/fixtures/hpa/deployment.yml +++ b/test/fixtures/hpa/deployment.yml @@ -10,8 +10,8 @@ spec: template: metadata: labels: - name: web - app: hello-cloud + name: hpa + app: hpa-deployment spec: containers: - name: app diff --git a/test/helpers/kubeclient_helper.rb b/test/helpers/kubeclient_helper.rb index 12cb7330d..3e5b3a040 100644 --- a/test/helpers/kubeclient_helper.rb +++ b/test/helpers/kubeclient_helper.rb @@ -25,8 +25,4 @@ def apps_v1beta1_kubeclient def batch_v1beta1_kubeclient @batch_v1beta1_kubeclient ||= build_batch_v1beta1_kubeclient(MINIKUBE_CONTEXT) end - - def autoscaling_v2beta1_kubeclient - @autoscaling_v2beta1_kubeclient ||= build_autoscaling_v2beta1_kubeclient(MINIKUBE_CONTEXT) - end end diff --git a/test/integration/kubernetes_deploy_test.rb b/test/integration/kubernetes_deploy_test.rb index bbbfa6871..a104df8d7 100644 --- a/test/integration/kubernetes_deploy_test.rb +++ b/test/integration/kubernetes_deploy_test.rb @@ -1010,11 +1010,21 @@ def test_raise_on_yaml_missing_kind def test_hpa_can_be_successful skip if KUBE_SERVER_VERSION < Gem::Version.new('1.8.0') assert_deploy_success(deploy_fixtures("hpa")) + assert_logs_match_all([ + "Deploying resources:", + "hpa.v2beta1.autoscaling/hello-hpa (timeout: 30s)", + %r{hpa.v2beta1.autoscaling/hello-hpa\s+Succeeded} + ]) end - def test_hpa_can_times_out_when_no_matching_deployment + def test_hpa_can_fail_when_no_matching_deployment skip if KUBE_SERVER_VERSION < Gem::Version.new('1.8.0') - assert_deploy_failure(deploy_fixtures("hpa", subset: ["hpa.yml"]), :timed_out) + assert_deploy_failure(deploy_fixtures("hpa", subset: ["hpa.yml"])) + assert_logs_match_all([ + "Deploying hpa.v2beta1.autoscaling/hello-hpa (timeout: 30s)", + "hpa.v2beta1.autoscaling/hello-hpa: FAILED", + "Final status: FailedGetScale" + ]) end def test_hpa_can_be_pruned