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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/environment.rb')
-rw-r--r--app/models/environment.rb41
1 files changed, 32 insertions, 9 deletions
diff --git a/app/models/environment.rb b/app/models/environment.rb
index deded3eeae0..31a95bb1b5d 100644
--- a/app/models/environment.rb
+++ b/app/models/environment.rb
@@ -32,6 +32,7 @@ class Environment < ApplicationRecord
has_one :last_visible_deployment, -> { visible.distinct_on_environment }, inverse_of: :environment, class_name: 'Deployment'
has_one :last_visible_deployable, through: :last_visible_deployment, source: 'deployable', source_type: 'CommitStatus'
has_one :last_visible_pipeline, through: :last_visible_deployable, source: 'pipeline'
+ has_one :upcoming_deployment, -> { running.order('deployments.id DESC') }, class_name: 'Deployment'
has_one :latest_opened_most_severe_alert, -> { order_severity_with_open_prometheus_alert }, class_name: 'AlertManagement::Alert', inverse_of: :environment
before_validation :nullify_external_url
@@ -60,6 +61,7 @@ class Environment < ApplicationRecord
addressable_url: true
delegate :stop_action, :manual_actions, to: :last_deployment, allow_nil: true
+ delegate :auto_rollback_enabled?, to: :project
scope :available, -> { with_state(:available) }
scope :stopped, -> { with_state(:stopped) }
@@ -240,10 +242,6 @@ class Environment < ApplicationRecord
def cancel_deployment_jobs!
jobs = active_deployments.with_deployable
jobs.each do |deployment|
- # guard against data integrity issues,
- # for example https://gitlab.com/gitlab-org/gitlab/-/issues/218659#note_348823660
- next unless deployment.deployable
-
Gitlab::OptimisticLocking.retry_lock(deployment.deployable) do |deployable|
deployable.cancel! if deployable&.cancelable?
end
@@ -387,8 +385,38 @@ class Environment < ApplicationRecord
!!deployment_platform&.cluster&.application_elastic_stack_available?
end
+ def rollout_status
+ return unless rollout_status_available?
+
+ result = rollout_status_with_reactive_cache
+
+ result || ::Gitlab::Kubernetes::RolloutStatus.loading
+ end
+
+ def ingresses
+ return unless rollout_status_available?
+
+ deployment_platform.ingresses(deployment_namespace)
+ end
+
+ def patch_ingress(ingress, data)
+ return unless rollout_status_available?
+
+ deployment_platform.patch_ingress(deployment_namespace, ingress, data)
+ end
+
private
+ def rollout_status_available?
+ has_terminals?
+ end
+
+ def rollout_status_with_reactive_cache
+ with_reactive_cache do |data|
+ deployment_platform.rollout_status(self, data)
+ end
+ end
+
def has_metrics_and_can_query?
has_metrics? && prometheus_adapter.can_query?
end
@@ -396,11 +424,6 @@ class Environment < ApplicationRecord
def generate_slug
self.slug = Gitlab::Slug::Environment.new(name).generate
end
-
- # Overrides ReactiveCaching default to activate limit checking behind a FF
- def reactive_cache_limit_enabled?
- Feature.enabled?(:reactive_caching_limit_environment, project, default_enabled: true)
- end
end
Environment.prepend_if_ee('EE::Environment')