Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
dturn committed Jul 17, 2018
1 parent a24876c commit d32e502
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 25 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 @@ -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) }
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
4 changes: 0 additions & 4 deletions test/helpers/kubeclient_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 12 additions & 2 deletions test/integration/kubernetes_deploy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d32e502

Please sign in to comment.