Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
dturn committed Jul 27, 2018
1 parent 68417d7 commit a45680a
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 24 deletions.
8 changes: 0 additions & 8 deletions lib/kubernetes-deploy/kubeclient_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,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) }
Expand Down
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions test/fixtures/hpa/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ spec:
template:
metadata:
labels:
name: web
app: hello-cloud
name: hpa
app: hpa-deployment
spec:
containers:
- name: app
Expand Down
3 changes: 0 additions & 3 deletions test/helpers/kubeclient_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,4 @@ def batch_v1_kubeclient
@batch_v1_kubeclient ||= build_batch_v1_kubeclient(MINIKUBE_CONTEXT)
end

def autoscaling_v2beta1_kubeclient
@autoscaling_v2beta1_kubeclient ||= build_autoscaling_v2beta1_kubeclient(MINIKUBE_CONTEXT)
end
end
14 changes: 12 additions & 2 deletions test/integration/kubernetes_deploy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1065,11 +1065,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
Expand Down

0 comments on commit a45680a

Please sign in to comment.