summaryrefslogtreecommitdiff
path: root/app/workers/cluster_wait_for_ingress_ip_address_worker.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/workers/cluster_wait_for_ingress_ip_address_worker.rb')
-rw-r--r--app/workers/cluster_wait_for_ingress_ip_address_worker.rb38
1 files changed, 32 insertions, 6 deletions
diff --git a/app/workers/cluster_wait_for_ingress_ip_address_worker.rb b/app/workers/cluster_wait_for_ingress_ip_address_worker.rb
index 6865384df44..5d4768a8a83 100644
--- a/app/workers/cluster_wait_for_ingress_ip_address_worker.rb
+++ b/app/workers/cluster_wait_for_ingress_ip_address_worker.rb
@@ -1,13 +1,39 @@
# frozen_string_literal: true
-class ClusterWaitForIngressIpAddressWorker
- include ApplicationWorker
- include ClusterQueue
- include ClusterApplications
+class ClusterWaitForIngressIpAddressWorker < ClusterApplicationBaseWorker
+ include Gitlab::Utils::StrongMemoize
+
+ Error = Class.new(StandardError)
+
+ LEASE_TIMEOUT = 15.seconds.to_i
def perform(app_name, app_id)
- find_application(app_name, app_id) do |app|
- Clusters::Applications::CheckIngressIpAddressService.new(app).execute
+ 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