Skip to content

Commit

Permalink
Fix crashes with Service of type ExternalName
Browse files Browse the repository at this point in the history
  • Loading branch information
maxlaverse committed Nov 30, 2017
1 parent 01939fc commit bf91833
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
8 changes: 8 additions & 0 deletions lib/kubernetes-deploy/kubernetes_resource/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -54,18 +56,24 @@ 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?

deployments = JSON.parse(raw_json)["items"]
return unless deployments.length == 1
deployments.first["spec"]["replicas"].to_i
end

def external_name?
@definition["spec"]["type"] == "ExternalName"
end
end
end
11 changes: 11 additions & 0 deletions test/fixtures/hello-cloud/redis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion test/integration/kubernetes_deploy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bf91833

Please sign in to comment.