From bf918332893a8ef9915b35ebc42306bf6b186347 Mon Sep 17 00:00:00 2001 From: Max Laverse Date: Thu, 30 Nov 2017 10:46:25 +0100 Subject: [PATCH] Fix crashes with Service of type ExternalName --- lib/kubernetes-deploy/kubernetes_resource/service.rb | 8 ++++++++ test/fixtures/hello-cloud/redis.yml | 11 +++++++++++ test/integration/kubernetes_deploy_test.rb | 2 +- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/kubernetes-deploy/kubernetes_resource/service.rb b/lib/kubernetes-deploy/kubernetes_resource/service.rb index 3408d5488..d536d47b5 100644 --- a/lib/kubernetes-deploy/kubernetes_resource/service.rb +++ b/lib/kubernetes-deploy/kubernetes_resource/service.rb @@ -21,6 +21,8 @@ def status end def deploy_succeeded? + return exists? if external_name? + # We can't use endpoints if we want the service to be able to fail fast when the pods are down exposes_zero_replica_deployment? || selects_some_pods? end @@ -54,12 +56,14 @@ def selector end def fetch_related_pod_count + return 0 if external_name? raw_json, _err, st = kubectl.run("get", "pods", "--selector=#{selector}", "--output=json") return unless st.success? JSON.parse(raw_json)["items"].length end def fetch_related_replica_count + return 0 if external_name? raw_json, _err, st = kubectl.run("get", "deployments", "--selector=#{selector}", "--output=json") return unless st.success? @@ -67,5 +71,9 @@ def fetch_related_replica_count return unless deployments.length == 1 deployments.first["spec"]["replicas"].to_i end + + def external_name? + @definition["spec"]["type"] == "ExternalName" + end end end diff --git a/test/fixtures/hello-cloud/redis.yml b/test/fixtures/hello-cloud/redis.yml index c80ecfac5..2d21fb729 100644 --- a/test/fixtures/hello-cloud/redis.yml +++ b/test/fixtures/hello-cloud/redis.yml @@ -12,6 +12,17 @@ spec: selector: name: redis --- +apiVersion: v1 +kind: Service +metadata: + name: external-redis + labels: + name: external-redis + app: hello-cloud +spec: + type: ExternalName + externalName: my.external-redis.local +--- kind: PersistentVolumeClaim apiVersion: v1 metadata: diff --git a/test/integration/kubernetes_deploy_test.rb b/test/integration/kubernetes_deploy_test.rb index 842513c61..adfda3048 100644 --- a/test/integration/kubernetes_deploy_test.rb +++ b/test/integration/kubernetes_deploy_test.rb @@ -59,7 +59,7 @@ def test_pruning_works 'daemonset "nginx"', 'statefulset "nginx-ss"' ] # not necessarily listed in this order - expected_msgs = [/Pruned 7 resources and successfully deployed 3 resources/] + expected_msgs = [/Pruned 7 resources and successfully deployed 4 resources/] expected_pruned.map do |resource| expected_msgs << /The following resources were pruned:.*#{resource}/ end