diff options
author | Dylan Griffith <dyl.griffith@gmail.com> | 2018-02-23 01:08:12 +0300 |
---|---|---|
committer | Dylan Griffith <dyl.griffith@gmail.com> | 2018-02-23 01:10:14 +0300 |
commit | 3b320d675fe058311d921e26cd89b2e703310b21 (patch) | |
tree | c8135b9041f238bc2d435fea26cf3c3dd6940cd8 /app/services | |
parent | 17e85dacdd73b51a173d1f4c5efea5e20ee8c55b (diff) |
Simplify retrying for ClusterWaitForIngressIpAddressWorker and style changes
(#42643)
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/clusters/applications/check_ingress_ip_address_service.rb | 27 |
1 files changed, 11 insertions, 16 deletions
diff --git a/app/services/clusters/applications/check_ingress_ip_address_service.rb b/app/services/clusters/applications/check_ingress_ip_address_service.rb index 300b7ed522c..a98e05b25cb 100644 --- a/app/services/clusters/applications/check_ingress_ip_address_service.rb +++ b/app/services/clusters/applications/check_ingress_ip_address_service.rb @@ -1,24 +1,17 @@ module Clusters module Applications class CheckIngressIpAddressService < BaseHelmService + include Gitlab::Utils::StrongMemoize + Error = Class.new(StandardError) LEASE_TIMEOUT = 3.seconds.to_i def execute - return true if app.external_ip - return true unless try_obtain_lease - - service = get_service + return if app.external_ip + return unless try_obtain_lease - if service.status.loadBalancer.ingress - resolve_external_ip(service) - else - false - end - - rescue KubeException => e - raise Error, "#{e.class}: #{e.message}" + app.update!(external_ip: ingress_ip) if ingress_ip end private @@ -29,12 +22,14 @@ module Clusters .try_obtain end - def resolve_external_ip(service) - app.update!(external_ip: service.status.loadBalancer.ingress[0].ip) + def ingress_ip + service.status.loadBalancer.ingress&.first&.ip end - def get_service - kubeclient.get_service('ingress-nginx-ingress-controller', Gitlab::Kubernetes::Helm::NAMESPACE) + def service + strong_memoize(:ingress_service) do + kubeclient.get_service('ingress-nginx-ingress-controller', Gitlab::Kubernetes::Helm::NAMESPACE) + end end end end |