Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cluster_wait_for_ingress_ip_address_worker.rb « workers « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5d4768a8a830e38458064c74c3a2779d3790396f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# frozen_string_literal: true

class ClusterWaitForIngressIpAddressWorker < ClusterApplicationBaseWorker
  include Gitlab::Utils::StrongMemoize

  Error = Class.new(StandardError)

  LEASE_TIMEOUT = 15.seconds.to_i

  def perform(app_name, app_id)
    super
    execute
  end

  def execute
    return if app.external_ip
    return unless try_obtain_lease

    app.update!(external_ip: ingress_ip) if ingress_ip
  end

  private

  def try_obtain_lease
    Gitlab::ExclusiveLease
      .new("check_ingress_ip_address_service:#{app.id}", timeout: LEASE_TIMEOUT)
      .try_obtain
  end

  def ingress_ip
    service.status.loadBalancer.ingress&.first&.ip
  end

  def service
    strong_memoize(:ingress_service) do
      app.ingress_service
    end
  end
end