diff --git a/app/models/ci/runner.rb b/app/models/ci/runner.rb index fd1c457a7ff142cdfffeaeb525ad750454a3d358..730f982a4e1ea9e1e6d520a54ab1583b9bf21b07 100644 --- a/app/models/ci/runner.rb +++ b/app/models/ci/runner.rb @@ -28,8 +28,8 @@ class Runner < Ci::ApplicationRecord if: ->(token_owner_record) { token_owner_record.owner }, payload: { o: ->(token_owner_record) { token_owner_record.owner.try(:organization_id) }, - g: ->(token_owner_record) { token_owner_record.group_type? ? token_owner_record.sharding_key_id : nil }, - p: ->(token_owner_record) { token_owner_record.project_type? ? token_owner_record.sharding_key_id : nil }, + g: ->(token_owner_record) { token_owner_record.runner_namespaces.first&.namespace_id }, + p: ->(token_owner_record) { token_owner_record.runner_projects.first&.project_id }, u: ->(token_owner_record) { token_owner_record.creator_id }, t: ->(token_owner_record) { token_owner_record.partition_id } } @@ -151,7 +151,6 @@ class Runner < Ci::ApplicationRecord scope :created_by_admins, -> { with_creator_id(User.admins.ids) } scope :with_creator_id, ->(value) { where(creator_id: value) } - scope :with_sharding_key, ->(value) { where(sharding_key_id: value) } scope :belonging_to_group_or_project_descendants, ->(group_id) { group_ids = Ci::NamespaceMirror.by_group_and_descendants(group_id).select(:namespace_id) @@ -242,7 +241,6 @@ class Runner < Ci::ApplicationRecord scope :with_api_entity_associations, -> { preload(:creator) } validate :tag_constraints - validates :sharding_key_id, presence: true, unless: :instance_type? validates :organization_id, presence: true, on: [:create, :update], unless: :instance_type? validates :name, length: { maximum: 256 }, if: :name_changed? validates :description, length: { maximum: 1024 }, if: :description_changed? @@ -251,7 +249,6 @@ class Runner < Ci::ApplicationRecord validates :registration_type, presence: true validate :no_projects, unless: :project_type? - validate :no_sharding_key_id, if: :instance_type? validate :no_organization_id, if: :instance_type? validate :no_groups, unless: :group_type? validate :any_project, if: :project_type? @@ -382,11 +379,6 @@ def assign_to(project, current_user = nil) begin transaction do - if projects.id_in(sharding_key_id).empty? && !update_project_id - self.errors.add(:assign_to, 'Runner is orphaned and no fallback owner exists') - next false - end - self.runner_projects << ::Ci::RunnerProject.new(project: project, runner: self) self.save! end @@ -550,8 +542,10 @@ def ensure_manager(system_xid) # rubocop: disable Performance/ActiveRecordSubtransactionMethods -- This is used only in API endpoints outside of transactions RunnerManager.safe_find_or_create_by!(runner_id: id, system_xid: system_xid.to_s) do |m| m.runner_type = runner_type - m.sharding_key_id = sharding_key_id m.organization_id = organization_id + + # Use a bogus sharding_key_id instead of copying a potentially NULL value from the runner + m.sharding_key_id = instance_type? ? nil : sharding_key_id || 0 end # rubocop: enable Performance/ActiveRecordSubtransactionMethods end @@ -592,20 +586,6 @@ def fallback_owner_project Project.order(projects_added_to_runner_asc).find_by_id(project_ids) end - # Ensure we have a valid sharding_key_id. Logic is similar to the one used in - # Ci::Runners::UpdateProjectRunnersOwnerService when a project is deleted - def update_project_id - project_id = fallback_owner_project&.id - - return if project_id.nil? - - self.clear_memoization(:owner) - self.sharding_key_id = project_id - - runner_managers.where(runner_type: :project_type).each_batch { |batch| batch.update_all(sharding_key_id: project_id) } - taggings.where(runner_type: :project_type).update_all(sharding_key_id: project_id) - end - def compute_token_expiration_instance return unless expiration_interval = Gitlab::CurrentSettings.runner_token_expiration_interval @@ -653,10 +633,6 @@ def tag_constraints end end - def no_sharding_key_id - errors.add(:runner, 'cannot have sharding_key_id assigned') if sharding_key_id - end - def no_organization_id errors.add(:runner, 'cannot have organization_id assigned') if organization_id end diff --git a/app/models/ci/runner_manager.rb b/app/models/ci/runner_manager.rb index e82f24127231dc806638437f3cf74ad0c1861e0f..711e9beca5abadba9c92c42f90968fcdeba7235e 100644 --- a/app/models/ci/runner_manager.rb +++ b/app/models/ci/runner_manager.rb @@ -55,7 +55,6 @@ class RunnerManager < Ci::ApplicationRecord validates :runner, presence: true validates :runner_type, presence: true, on: :create validates :system_xid, presence: true, length: { maximum: 64 } - validates :sharding_key_id, presence: true, on: :create, unless: :instance_type? validates :organization_id, presence: true, on: [:create, :update], unless: :instance_type? validates :version, length: { maximum: 2048 } validates :revision, length: { maximum: 255 } @@ -65,7 +64,6 @@ class RunnerManager < Ci::ApplicationRecord validates :config, json_schema: { filename: 'ci_runner_config' } validates :runtime_features, json_schema: { filename: 'ci_runner_runtime_features' } - validate :no_sharding_key_id, if: :instance_type? validate :no_organization_id, if: :instance_type? cached_attr_reader :version, :revision, :platform, :architecture, :ip_address, :contacted_at, @@ -193,10 +191,6 @@ def schedule_runner_version_update(new_version) Ci::Runners::ProcessRunnerVersionUpdateWorker.perform_async(new_version) end - def no_sharding_key_id - errors.add(:runner_manager, 'cannot have sharding_key_id assigned') if sharding_key_id - end - def no_organization_id errors.add(:runner_manager, 'cannot have organization_id assigned') if organization_id end diff --git a/app/models/ci/runner_tagging.rb b/app/models/ci/runner_tagging.rb index e7c98b15861b4bf8fe9d27bd1de6cfaa825a7e82..a0db870ff5ed3bf1826f4e475ebef7124053200c 100644 --- a/app/models/ci/runner_tagging.rb +++ b/app/models/ci/runner_tagging.rb @@ -19,10 +19,8 @@ class RunnerTagging < Ci::ApplicationRecord belongs_to :tag, class_name: 'Ci::Tag', optional: false validates :runner_type, presence: true - validates :sharding_key_id, presence: true, unless: :instance_type? validates :organization_id, presence: true, on: [:create, :update], unless: :instance_type? - validate :no_sharding_key_id, if: :instance_type? validate :no_organization_id, if: :instance_type? scope :scoped_runners, -> do @@ -37,12 +35,6 @@ def set_runner_type self.runner_type = runner.runner_type end - def no_sharding_key_id - return if sharding_key_id.nil? - - errors.add(:sharding_key_id, 'instance_type runners must not have a sharding_key_id') - end - def no_organization_id return if organization_id.nil? diff --git a/app/services/ci/runners/update_project_runners_owner_service.rb b/app/services/ci/runners/update_project_runners_owner_service.rb deleted file mode 100644 index 508f1eb657adb0f5fa3d29dfe62646d682d7447b..0000000000000000000000000000000000000000 --- a/app/services/ci/runners/update_project_runners_owner_service.rb +++ /dev/null @@ -1,70 +0,0 @@ -# frozen_string_literal: true - -module Ci - module Runners - # Service used to recompute runner owners after a project is deleted. - class UpdateProjectRunnersOwnerService - BATCH_SIZE = 1000 - - # @param [Int] project_id: the ID of the deleted project - # @param [Int] namespace_id: the ID of the parent namespace of the deleted project - def initialize(project_id, namespace_id) - @project_id = project_id - @organization_id = Namespace.find(namespace_id).organization_id - end - - def execute - # Since the project was deleted in the 'main' database, let's ensure that the respective - # ci_runner_projects join records are also gone (would be handled by LFK otherwise, - # but it is a helpful precondition for the service's logic) - Ci::RunnerProject.belonging_to_project(project_id).each_batch do |batch| - batch.delete_all - end - - # rubocop: disable CodeReuse/ActiveRecord -- this query is too specific to generalize on the models - runner_projects = - Ci::RunnerProject.where(Ci::RunnerProject.arel_table[:runner_id].eq(Ci::Runner.arel_table[:id])) - orphaned_runners = Ci::Runner.project_type.with_sharding_key(project_id) - - orphaned_runners.select(:id).each_batch(of: BATCH_SIZE) do |batch| - runners_missing_owner_project = Ci::Runner.id_in(batch.limit(BATCH_SIZE).pluck_primary_key) - runners_with_fallback_owner = runners_missing_owner_project.where_exists(runner_projects.limit(1)) - - Ci::Runner.transaction do - runner_ids = runners_with_fallback_owner.limit(BATCH_SIZE).pluck_primary_key - - runners_with_fallback_owner.update_all(runner_id_update_query(Ci::Runner.arel_table[:id])) - Ci::RunnerManager.project_type.for_runner(runner_ids) - .update_all(runner_id_update_query(Ci::RunnerManager.arel_table[:runner_id])) - Ci::RunnerTagging.project_type.for_runner(runner_ids) - .update_all(runner_id_update_query(Ci::RunnerTagging.arel_table[:runner_id])) - - # Delete any orphaned runners that are still pointing to the project - # (they are the ones which no longer have any matching ci_runner_projects records) - # We can afford to sidestep Ci::Runner hooks since we know by definition that - # there are no Ci::RunnerProject models pointing to these runners (it's the reason they are being deleted) - runners_missing_owner_project.project_type.with_sharding_key(project_id).delete_all - end - end - # rubocop: enable CodeReuse/ActiveRecord - - ServiceResponse.success - end - - private - - attr_reader :project_id - - def runner_id_update_query(runner_id_column) - # rubocop: disable CodeReuse/ActiveRecord -- this query is too specific to generalize on the models - runner_projects = Ci::RunnerProject.where(Ci::RunnerProject.arel_table[:runner_id].eq(runner_id_column)) - - <<~SQL - sharding_key_id = (#{runner_projects.order(id: :asc).limit(1).select(:project_id).to_sql}), - organization_id = #{@organization_id} - SQL - # rubocop: enable CodeReuse/ActiveRecord - end - end - end -end diff --git a/app/workers/all_queues.yml b/app/workers/all_queues.yml index c2eea937f9e0621c48a2e7303f84172422321282..fa404b479c07f56ee00548bf5900332a839a1781 100644 --- a/app/workers/all_queues.yml +++ b/app/workers/all_queues.yml @@ -3497,16 +3497,6 @@ :idempotent: true :tags: [] :queue_namespace: -- :name: ci_runners_update_project_runners_owner - :worker_name: Ci::Runners::UpdateProjectRunnersOwnerWorker - :feature_category: :runner - :has_external_dependencies: false - :urgency: :low - :resource_boundary: :unknown - :weight: 1 - :idempotent: true - :tags: [] - :queue_namespace: - :name: ci_safe_disable_pipeline_variables :worker_name: Ci::SafeDisablePipelineVariablesWorker :feature_category: :ci_variables diff --git a/app/workers/ci/runners/update_project_runners_owner_worker.rb b/app/workers/ci/runners/update_project_runners_owner_worker.rb deleted file mode 100644 index 8399d77255b1dc000a7ee42ba908c391f23fbe84..0000000000000000000000000000000000000000 --- a/app/workers/ci/runners/update_project_runners_owner_worker.rb +++ /dev/null @@ -1,19 +0,0 @@ -# frozen_string_literal: true - -module Ci - module Runners - class UpdateProjectRunnersOwnerWorker - include Gitlab::EventStore::Subscriber - - data_consistency :sticky - - idempotent! - - feature_category :runner - - def handle_event(event) - ::Ci::Runners::UpdateProjectRunnersOwnerService.new(event.data[:project_id], event.data[:namespace_id]).execute - end - end - end -end diff --git a/config/sidekiq_queues.yml b/config/sidekiq_queues.yml index 43e05fba35394aa943e2422822cbf2e448cd35e5..1fb65b9c04909177ca59b0c8cfdbc90800fc2570 100644 --- a/config/sidekiq_queues.yml +++ b/config/sidekiq_queues.yml @@ -235,8 +235,6 @@ - 1 - - ci_runners_process_runner_version_update - 1 -- - ci_runners_update_project_runners_owner - - 1 - - ci_safe_disable_pipeline_variables - 1 - - ci_slsa_publish_statement diff --git a/db/migrate/20250723124358_remove_sharding_key_check_constraint_from_ci_runners2.rb b/db/migrate/20250723124358_remove_sharding_key_check_constraint_from_ci_runners2.rb new file mode 100644 index 0000000000000000000000000000000000000000..66ea5786d652d8840bada5c16597e16f086d5277 --- /dev/null +++ b/db/migrate/20250723124358_remove_sharding_key_check_constraint_from_ci_runners2.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class RemoveShardingKeyCheckConstraintFromCiRunners2 < Gitlab::Database::Migration[2.3] + disable_ddl_transaction! + milestone '18.3' + + CONSTRAINT_NAME = 'check_sharding_key_id_nullness' + + def up + remove_check_constraint(:instance_type_ci_runners, CONSTRAINT_NAME) + remove_check_constraint(:group_type_ci_runners, CONSTRAINT_NAME) + remove_check_constraint(:project_type_ci_runners, CONSTRAINT_NAME) + end + + def down + add_check_constraint(:instance_type_ci_runners, 'sharding_key_id IS NULL', CONSTRAINT_NAME) + add_check_constraint(:group_type_ci_runners, 'sharding_key_id IS NOT NULL', CONSTRAINT_NAME) + add_check_constraint(:project_type_ci_runners, 'sharding_key_id IS NOT NULL', CONSTRAINT_NAME) + end +end diff --git a/db/migrate/20250723124360_remove_sharding_key_check_constraint_from_ci_runner_machines2.rb b/db/migrate/20250723124360_remove_sharding_key_check_constraint_from_ci_runner_machines2.rb new file mode 100644 index 0000000000000000000000000000000000000000..dcba8500b5847f6a4fab73aefafb172b5c7f3e4f --- /dev/null +++ b/db/migrate/20250723124360_remove_sharding_key_check_constraint_from_ci_runner_machines2.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class RemoveShardingKeyCheckConstraintFromCiRunnerMachines2 < Gitlab::Database::Migration[2.3] + disable_ddl_transaction! + milestone '18.3' + + CONSTRAINT_NAME = 'check_sharding_key_id_nullness' + + def up + remove_check_constraint(:instance_type_ci_runner_machines, CONSTRAINT_NAME) + remove_check_constraint(:group_type_ci_runner_machines, CONSTRAINT_NAME) + remove_check_constraint(:project_type_ci_runner_machines, CONSTRAINT_NAME) + end + + def down + add_check_constraint(:instance_type_ci_runner_machines, 'sharding_key_id IS NULL', CONSTRAINT_NAME) + add_check_constraint(:group_type_ci_runner_machines, 'sharding_key_id IS NOT NULL', CONSTRAINT_NAME) + add_check_constraint(:project_type_ci_runner_machines, 'sharding_key_id IS NOT NULL', CONSTRAINT_NAME) + end +end diff --git a/db/migrate/20250723124365_remove_sharding_key_check_constraint_from_ci_runner_taggings2.rb b/db/migrate/20250723124365_remove_sharding_key_check_constraint_from_ci_runner_taggings2.rb new file mode 100644 index 0000000000000000000000000000000000000000..e7cf35667d5b6ef5203d7838f5f33b2555ab4b90 --- /dev/null +++ b/db/migrate/20250723124365_remove_sharding_key_check_constraint_from_ci_runner_taggings2.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class RemoveShardingKeyCheckConstraintFromCiRunnerTaggings2 < Gitlab::Database::Migration[2.3] + disable_ddl_transaction! + milestone '18.3' + + CONSTRAINT_NAME = 'check_sharding_key_id_nullness' + + def up + remove_check_constraint(:ci_runner_taggings_instance_type, CONSTRAINT_NAME) + remove_check_constraint(:ci_runner_taggings_group_type, CONSTRAINT_NAME) + remove_check_constraint(:ci_runner_taggings_project_type, CONSTRAINT_NAME) + end + + def down + add_check_constraint(:ci_runner_taggings_instance_type, 'sharding_key_id IS NULL', CONSTRAINT_NAME) + add_check_constraint(:ci_runner_taggings_group_type, 'sharding_key_id IS NOT NULL', CONSTRAINT_NAME) + add_check_constraint(:ci_runner_taggings_project_type, 'sharding_key_id IS NOT NULL', CONSTRAINT_NAME) + end +end diff --git a/db/migrate/20250723124370_cleanup_records_with_null_sharding_key_id_values_from_ci_runners2.rb b/db/migrate/20250723124370_cleanup_records_with_null_sharding_key_id_values_from_ci_runners2.rb new file mode 100644 index 0000000000000000000000000000000000000000..fec1a7a5f5561e1f6947f3ec5ab955964192fc3f --- /dev/null +++ b/db/migrate/20250723124370_cleanup_records_with_null_sharding_key_id_values_from_ci_runners2.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +class CleanupRecordsWithNullShardingKeyIdValuesFromCiRunners2 < Gitlab::Database::Migration[2.3] + milestone '18.3' + + disable_ddl_transaction! + restrict_gitlab_migration gitlab_schema: :gitlab_ci + + BATCH_SIZE = 1000 + + class CiRunner < MigrationRecord + include EachBatch + + self.table_name = 'ci_runners' + self.primary_key = :id + end + + def up + # no-op - this migration is required to allow a rollback of `RemoveShardingKeyCheckConstraintFromCiRunners2` + end + + def down + CiRunner.each_batch(of: BATCH_SIZE) do |relation| + relation.where.not(runner_type: 1).where(sharding_key_id: nil).delete_all + end + end +end diff --git a/db/migrate/20250723124375_cleanup_records_with_null_sharding_key_id_values_from_ci_runner_machines2.rb b/db/migrate/20250723124375_cleanup_records_with_null_sharding_key_id_values_from_ci_runner_machines2.rb new file mode 100644 index 0000000000000000000000000000000000000000..4f7df93fdfb7c8a54fa47b658f1368b4366f4355 --- /dev/null +++ b/db/migrate/20250723124375_cleanup_records_with_null_sharding_key_id_values_from_ci_runner_machines2.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +class CleanupRecordsWithNullShardingKeyIdValuesFromCiRunnerMachines2 < Gitlab::Database::Migration[2.3] + milestone '18.3' + + disable_ddl_transaction! + restrict_gitlab_migration gitlab_schema: :gitlab_ci + + BATCH_SIZE = 1000 + + class CiRunnerMachine < MigrationRecord + include EachBatch + + self.table_name = 'ci_runner_machines' + self.primary_key = :id + end + + def up + # no-op - this migration is required to allow a rollback of `RemoveShardingKeyCheckConstraintFromCiRunnerMachines2` + end + + def down + CiRunnerMachine.each_batch(of: BATCH_SIZE) do |relation| + relation.where.not(runner_type: 1).where(sharding_key_id: nil).delete_all + end + end +end diff --git a/db/migrate/20250723124378_cleanup_records_with_null_sharding_key_id_values_from_ci_runner_taggings2.rb b/db/migrate/20250723124378_cleanup_records_with_null_sharding_key_id_values_from_ci_runner_taggings2.rb new file mode 100644 index 0000000000000000000000000000000000000000..df9a7e98aff54235b9de0bbf59202af9ebbd9808 --- /dev/null +++ b/db/migrate/20250723124378_cleanup_records_with_null_sharding_key_id_values_from_ci_runner_taggings2.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +class CleanupRecordsWithNullShardingKeyIdValuesFromCiRunnerTaggings2 < Gitlab::Database::Migration[2.3] + milestone '18.3' + + disable_ddl_transaction! + restrict_gitlab_migration gitlab_schema: :gitlab_ci + + BATCH_SIZE = 1000 + + class CiRunnerTagging < MigrationRecord + include EachBatch + + self.table_name = 'ci_runner_taggings' + self.primary_key = :id + end + + def up + # no-op - this migration is required to allow a rollback of `RemoveShardingKeyCheckConstraintFromCiRunnerTaggings2` + end + + def down + CiRunnerTagging.each_batch(of: BATCH_SIZE) do |relation| + relation.where.not(runner_type: 1).where(sharding_key_id: nil).delete_all + end + end +end diff --git a/db/schema_migrations/20250723124358 b/db/schema_migrations/20250723124358 new file mode 100644 index 0000000000000000000000000000000000000000..5fa791eaeb4cc2b7a5d5a5e36a2dc046068e12a7 --- /dev/null +++ b/db/schema_migrations/20250723124358 @@ -0,0 +1 @@ +e49af8ec9ef7b23170c598e7a60f4ceea457aac175aca234d094fae3f21dd29d \ No newline at end of file diff --git a/db/schema_migrations/20250723124360 b/db/schema_migrations/20250723124360 new file mode 100644 index 0000000000000000000000000000000000000000..59503ef03e4b99f83fa6ba8840fc8171c57ad504 --- /dev/null +++ b/db/schema_migrations/20250723124360 @@ -0,0 +1 @@ +a38f040182f01b28cdb7c77671e1eba6bbbe32e06b73096ec868325af8392e3e \ No newline at end of file diff --git a/db/schema_migrations/20250723124365 b/db/schema_migrations/20250723124365 new file mode 100644 index 0000000000000000000000000000000000000000..e0e625d198ecc88b7d83ac02b399396065135583 --- /dev/null +++ b/db/schema_migrations/20250723124365 @@ -0,0 +1 @@ +5a11a0fc43981e5c904359a89919cbcd313f84e32566e8478415e9d118d7d7b7 \ No newline at end of file diff --git a/db/schema_migrations/20250723124370 b/db/schema_migrations/20250723124370 new file mode 100644 index 0000000000000000000000000000000000000000..3f85b59fd12b3a73dbae813bb56b751bdf6e3102 --- /dev/null +++ b/db/schema_migrations/20250723124370 @@ -0,0 +1 @@ +8a6e782b40701b8016df275b3df04f8f8f2a8a3817ca446e3775e82f4b154fa3 \ No newline at end of file diff --git a/db/schema_migrations/20250723124375 b/db/schema_migrations/20250723124375 new file mode 100644 index 0000000000000000000000000000000000000000..ca7c6810487c1703cbefd8864d1cfe80c2b9cce1 --- /dev/null +++ b/db/schema_migrations/20250723124375 @@ -0,0 +1 @@ +3ef0cced2f559be303aa83891083d8ca58d52bc0e50bfcdb22c81f6963074cf2 \ No newline at end of file diff --git a/db/schema_migrations/20250723124378 b/db/schema_migrations/20250723124378 new file mode 100644 index 0000000000000000000000000000000000000000..3513788a3ca1d4e5455e7bcd01a173296fb184b1 --- /dev/null +++ b/db/schema_migrations/20250723124378 @@ -0,0 +1 @@ +4ab0dcde38c8580cb16500a22c89ca4f31d7680774f56617320be4df8fc5ebad \ No newline at end of file diff --git a/db/structure.sql b/db/structure.sql index d6194940ab8aefa9c1714281d3672b3446f34464..e57b879d7320b84031ec939b2076af78bf65828c 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -12312,8 +12312,7 @@ CREATE TABLE ci_runner_taggings_group_type ( runner_id bigint NOT NULL, sharding_key_id bigint, runner_type smallint NOT NULL, - organization_id bigint, - CONSTRAINT check_sharding_key_id_nullness CHECK ((sharding_key_id IS NOT NULL)) + organization_id bigint ); CREATE SEQUENCE ci_runner_taggings_id_seq @@ -12331,8 +12330,7 @@ CREATE TABLE ci_runner_taggings_instance_type ( runner_id bigint NOT NULL, sharding_key_id bigint, runner_type smallint NOT NULL, - organization_id bigint, - CONSTRAINT check_sharding_key_id_nullness CHECK ((sharding_key_id IS NULL)) + organization_id bigint ); CREATE TABLE ci_runner_taggings_project_type ( @@ -12341,8 +12339,7 @@ CREATE TABLE ci_runner_taggings_project_type ( runner_id bigint NOT NULL, sharding_key_id bigint, runner_type smallint NOT NULL, - organization_id bigint, - CONSTRAINT check_sharding_key_id_nullness CHECK ((sharding_key_id IS NOT NULL)) + organization_id bigint ); CREATE TABLE ci_runner_versions ( @@ -15738,8 +15735,7 @@ CREATE TABLE group_type_ci_runner_machines ( CONSTRAINT check_7dc4eee8a5 CHECK ((char_length(version) <= 2048)), CONSTRAINT check_b1e456641b CHECK ((char_length(ip_address) <= 1024)), CONSTRAINT check_c788f4b18a CHECK ((char_length(platform) <= 255)), - CONSTRAINT check_f3d25ab844 CHECK ((char_length(architecture) <= 255)), - CONSTRAINT check_sharding_key_id_nullness CHECK ((sharding_key_id IS NOT NULL)) + CONSTRAINT check_f3d25ab844 CHECK ((char_length(architecture) <= 255)) ); CREATE TABLE group_type_ci_runners ( @@ -15772,8 +15768,7 @@ CREATE TABLE group_type_ci_runners ( CONSTRAINT check_1f8618ab23 CHECK ((char_length(name) <= 256)), CONSTRAINT check_24b281f5bf CHECK ((char_length(maintainer_note) <= 1024)), CONSTRAINT check_5db8ae9d30 CHECK ((char_length(description) <= 1024)), - CONSTRAINT check_af25130d5a CHECK ((char_length(token) <= 128)), - CONSTRAINT check_sharding_key_id_nullness CHECK ((sharding_key_id IS NOT NULL)) + CONSTRAINT check_af25130d5a CHECK ((char_length(token) <= 128)) ); CREATE TABLE group_wiki_repositories ( @@ -16413,8 +16408,7 @@ CREATE TABLE instance_type_ci_runner_machines ( CONSTRAINT check_7dc4eee8a5 CHECK ((char_length(version) <= 2048)), CONSTRAINT check_b1e456641b CHECK ((char_length(ip_address) <= 1024)), CONSTRAINT check_c788f4b18a CHECK ((char_length(platform) <= 255)), - CONSTRAINT check_f3d25ab844 CHECK ((char_length(architecture) <= 255)), - CONSTRAINT check_sharding_key_id_nullness CHECK ((sharding_key_id IS NULL)) + CONSTRAINT check_f3d25ab844 CHECK ((char_length(architecture) <= 255)) ); CREATE TABLE instance_type_ci_runners ( @@ -16447,8 +16441,7 @@ CREATE TABLE instance_type_ci_runners ( CONSTRAINT check_1f8618ab23 CHECK ((char_length(name) <= 256)), CONSTRAINT check_24b281f5bf CHECK ((char_length(maintainer_note) <= 1024)), CONSTRAINT check_5db8ae9d30 CHECK ((char_length(description) <= 1024)), - CONSTRAINT check_af25130d5a CHECK ((char_length(token) <= 128)), - CONSTRAINT check_sharding_key_id_nullness CHECK ((sharding_key_id IS NULL)) + CONSTRAINT check_af25130d5a CHECK ((char_length(token) <= 128)) ); CREATE TABLE integrations ( @@ -22147,8 +22140,7 @@ CREATE TABLE project_type_ci_runner_machines ( CONSTRAINT check_7dc4eee8a5 CHECK ((char_length(version) <= 2048)), CONSTRAINT check_b1e456641b CHECK ((char_length(ip_address) <= 1024)), CONSTRAINT check_c788f4b18a CHECK ((char_length(platform) <= 255)), - CONSTRAINT check_f3d25ab844 CHECK ((char_length(architecture) <= 255)), - CONSTRAINT check_sharding_key_id_nullness CHECK ((sharding_key_id IS NOT NULL)) + CONSTRAINT check_f3d25ab844 CHECK ((char_length(architecture) <= 255)) ); CREATE TABLE project_type_ci_runners ( @@ -22181,8 +22173,7 @@ CREATE TABLE project_type_ci_runners ( CONSTRAINT check_1f8618ab23 CHECK ((char_length(name) <= 256)), CONSTRAINT check_24b281f5bf CHECK ((char_length(maintainer_note) <= 1024)), CONSTRAINT check_5db8ae9d30 CHECK ((char_length(description) <= 1024)), - CONSTRAINT check_af25130d5a CHECK ((char_length(token) <= 128)), - CONSTRAINT check_sharding_key_id_nullness CHECK ((sharding_key_id IS NOT NULL)) + CONSTRAINT check_af25130d5a CHECK ((char_length(token) <= 128)) ); CREATE TABLE project_uploads ( diff --git a/lib/gitlab/event_store.rb b/lib/gitlab/event_store.rb index f20ab0c44627b478ff57ce27a280df714f9d2e25..83286c288a09ffbd504271885eb51d6392ca7f78 100644 --- a/lib/gitlab/event_store.rb +++ b/lib/gitlab/event_store.rb @@ -42,7 +42,6 @@ def configure!(store) store.subscribe ::MergeRequests::UpdateHeadPipelineWorker, to: ::Ci::PipelineCreatedEvent store.subscribe ::Namespaces::UpdateRootStatisticsWorker, to: ::Projects::ProjectDeletedEvent - store.subscribe ::Ci::Runners::UpdateProjectRunnersOwnerWorker, to: ::Projects::ProjectDeletedEvent store.subscribe ::MergeRequests::ProcessAutoMergeFromEventWorker, to: ::MergeRequests::AutoMerge::TitleDescriptionUpdateEvent diff --git a/spec/db/schema_spec.rb b/spec/db/schema_spec.rb index 94de75e8d41e5e4da84585f5c7ef79d5214210ae..e4da19afbfabcc6c0ff4f82c7974a0ef7abde4b4 100644 --- a/spec/db/schema_spec.rb +++ b/spec/db/schema_spec.rb @@ -85,18 +85,18 @@ ci_resources: %w[project_id], p_ci_pipelines: %w[partition_id auto_canceled_by_partition_id auto_canceled_by_id trigger_id], p_ci_runner_machine_builds: %w[project_id], - ci_runner_taggings: %w[runner_id organization_id sharding_key_id], # The organization_id/sharding_key_id values are meant to populate the partitioned table, no other usage. The runner_id FK exists at the partition level - ci_runner_taggings_instance_type: %w[tag_id organization_id sharding_key_id], # organization_id/sharding_key_id are always NULL in this partition, tag_id is handled on ci_runner_taggings - ci_runner_taggings_group_type: %w[tag_id organization_id], # tag_id is handled on ci_runner_taggings. These records are indirectly deleted by the FK to group_type_ci_runners - ci_runner_taggings_project_type: %w[tag_id organization_id], # tag_id is handled on ci_runner_taggings. These records are indirectly deleted by the FK to project_type_ci_runners - ci_runners: %w[sharding_key_id], # This value is meant to populate the partitioned table, no other usage - instance_type_ci_runners: %w[creator_id organization_id sharding_key_id], # No need for LFKs on partition, already handled on ci_runners routing table. - group_type_ci_runners: %w[creator_id organization_id sharding_key_id], # No need for LFKs on partition, already handled on ci_runners routing table. - project_type_ci_runners: %w[creator_id organization_id sharding_key_id], # No need for LFKs on partition, already handled on ci_runners routing table. - ci_runner_machines: %w[runner_id organization_id sharding_key_id], # The runner_id and sharding_key_id fields are only used in the partitions, and have the appropriate FKs. The runner_id field will be removed with https://gitlab.com/gitlab-org/gitlab/-/issues/503749. - instance_type_ci_runner_machines: %w[organization_id sharding_key_id], # This field is always NULL in this partition. - group_type_ci_runner_machines: %w[organization_id sharding_key_id], # No need for LFK, rows will be deleted by the FK to ci_runners. - project_type_ci_runner_machines: %w[organization_id sharding_key_id], # No need for LFK, rows will be deleted by the FK to ci_runners. + ci_runner_taggings: %w[runner_id organization_id sharding_key_id], # The organization_id value is meant to populate the partitioned table, no other usage. The sharding_key_id will be dropped in https://gitlab.com/gitlab-org/gitlab/-/issues/547650. The runner_id FK exists at the partition level + ci_runner_taggings_instance_type: %w[tag_id organization_id sharding_key_id], # organization_id is always NULL in this partition, tag_id is handled on ci_runner_taggings. The sharding_key_id will be dropped in https://gitlab.com/gitlab-org/gitlab/-/issues/547650 + ci_runner_taggings_group_type: %w[tag_id organization_id sharding_key_id], # tag_id is handled on ci_runner_taggings. The sharding_key_id will be dropped in https://gitlab.com/gitlab-org/gitlab/-/issues/547650. These records are indirectly deleted by the FK to group_type_ci_runners + ci_runner_taggings_project_type: %w[tag_id organization_id sharding_key_id], # tag_id is handled on ci_runner_taggings. The sharding_key_id will be dropped in https://gitlab.com/gitlab-org/gitlab/-/issues/547650. These records are indirectly deleted by the FK to project_type_ci_runners + ci_runners: %w[sharding_key_id], # The sharding_key_id will be dropped in https://gitlab.com/gitlab-org/gitlab/-/issues/547650. + instance_type_ci_runners: %w[creator_id organization_id sharding_key_id], # No need for LFKs on partition, already handled on ci_runners routing table. The sharding_key_id will be dropped in https://gitlab.com/gitlab-org/gitlab/-/issues/547650. + group_type_ci_runners: %w[creator_id organization_id sharding_key_id], # No need for LFKs on partition, already handled on ci_runners routing table. The sharding_key_id will be dropped in https://gitlab.com/gitlab-org/gitlab/-/issues/547650. + project_type_ci_runners: %w[creator_id organization_id sharding_key_id], # No need for LFKs on partition, already handled on ci_runners routing table. The sharding_key_id will be dropped in https://gitlab.com/gitlab-org/gitlab/-/issues/547650. + ci_runner_machines: %w[runner_id organization_id sharding_key_id], # The organization_id field is only used in the partitions, and have the appropriate FKs. The runner_id field will be removed with https://gitlab.com/gitlab-org/gitlab/-/issues/503749. The sharding_key_id will be dropped in https://gitlab.com/gitlab-org/gitlab/-/issues/547650. + instance_type_ci_runner_machines: %w[organization_id sharding_key_id], # This field is always NULL in this partition. The sharding_key_id will be dropped in https://gitlab.com/gitlab-org/gitlab/-/issues/547650. + group_type_ci_runner_machines: %w[organization_id sharding_key_id], # No need for LFK, rows will be deleted by the FK to ci_runners. The sharding_key_id will be dropped in https://gitlab.com/gitlab-org/gitlab/-/issues/547650. + project_type_ci_runner_machines: %w[organization_id sharding_key_id], # No need for LFK, rows will be deleted by the FK to ci_runners. The sharding_key_id will be dropped in https://gitlab.com/gitlab-org/gitlab/-/issues/547650. ci_runner_projects: %w[runner_id], ci_sources_pipelines: %w[partition_id source_partition_id source_job_id], ci_sources_projects: %w[partition_id], diff --git a/spec/lib/gitlab/database/sharding_key_spec.rb b/spec/lib/gitlab/database/sharding_key_spec.rb index 393e8dd779836a2696a5458e0328dae3b50ca4a0..c266149e34f7e10d41c1ccd3fc96d69fba0b1104 100644 --- a/spec/lib/gitlab/database/sharding_key_spec.rb +++ b/spec/lib/gitlab/database/sharding_key_spec.rb @@ -35,30 +35,30 @@ # The following tables are work in progress as part of # https://gitlab.com/gitlab-org/gitlab/-/issues/398199 - # TODO: Remove these excepttions once the issue is closed. + # TODO: Remove these exceptions once the issue is closed. let(:uploads_and_partitions) do - [ - "achievement_uploads.namespace_id", - "ai_vectorizable_file_uploads.project_id", - "alert_management_alert_metric_image_uploads.project_id", - "bulk_import_export_upload_uploads.project_id", "bulk_import_export_upload_uploads.namespace_id", - "dependency_list_export_part_uploads.organization_id", - "dependency_list_export_uploads.organization_id", "dependency_list_export_uploads.namespace_id", - "dependency_list_export_uploads.project_id", - "design_management_action_uploads.namespace_id", - "import_export_upload_uploads.project_id", "import_export_upload_uploads.namespace_id", - "issuable_metric_image_uploads.namespace_id", - "namespace_uploads.namespace_id", - "note_uploads.namespace_id", - "organization_detail_uploads.organization_id", - "project_import_export_relation_export_upload_uploads.project_id", - "project_topic_uploads.organization_id", - "project_uploads.project_id", - "snippet_uploads.organization_id", - "vulnerability_export_part_uploads.organization_id", - "vulnerability_export_uploads.organization_id", - "vulnerability_archive_export_uploads.project_id", - "vulnerability_remediation_uploads.project_id" + %w[ + achievement_uploads.namespace_id + ai_vectorizable_file_uploads.project_id + alert_management_alert_metric_image_uploads.project_id + bulk_import_export_upload_uploads.project_id bulk_import_export_upload_uploads.namespace_id + dependency_list_export_part_uploads.organization_id + dependency_list_export_uploads.organization_id dependency_list_export_uploads.namespace_id + dependency_list_export_uploads.project_id + design_management_action_uploads.namespace_id + import_export_upload_uploads.project_id import_export_upload_uploads.namespace_id + issuable_metric_image_uploads.namespace_id + namespace_uploads.namespace_id + note_uploads.namespace_id + organization_detail_uploads.organization_id + project_import_export_relation_export_upload_uploads.project_id + project_topic_uploads.organization_id + project_uploads.project_id + snippet_uploads.organization_id + vulnerability_export_part_uploads.organization_id + vulnerability_export_uploads.organization_id + vulnerability_archive_export_uploads.project_id + vulnerability_remediation_uploads.project_id ] end diff --git a/spec/models/ci/runner_manager_spec.rb b/spec/models/ci/runner_manager_spec.rb index 12b9ebd92080a25e30ab3eb7aef1ad68f31ee3fe..700260eae305e4e46dfc7ef9511d6a07d40ca052 100644 --- a/spec/models/ci/runner_manager_spec.rb +++ b/spec/models/ci/runner_manager_spec.rb @@ -22,7 +22,6 @@ it { is_expected.to validate_presence_of(:system_xid) } it { is_expected.to validate_length_of(:system_xid).is_at_most(64) } it { is_expected.to validate_presence_of(:runner_type).on(:create) } - it { is_expected.to validate_presence_of(:sharding_key_id).on(:create) } it { is_expected.to validate_presence_of(:organization_id).on([:create, :update]) } it { is_expected.to validate_length_of(:version).is_at_most(2048) } it { is_expected.to validate_length_of(:revision).is_at_most(255) } @@ -35,18 +34,6 @@ it { expect(runner_manager).to be_valid } - context 'when sharding_key_id is present' do - let(:runner_manager) do - build(:ci_runner_machine, runner: build(:ci_runner, sharding_key_id: non_existing_record_id)) - end - - it 'is invalid' do - expect(runner_manager).to be_invalid - expect(runner_manager.errors.full_messages).to contain_exactly( - 'Runner manager cannot have sharding_key_id assigned') - end - end - context 'when organization_id is present' do let(:runner_manager) do build(:ci_runner_machine, runner: build(:ci_runner, organization_id: non_existing_record_id)) @@ -76,60 +63,6 @@ end end - describe 'shading_key_id validations' do - let(:runner_manager) { build(:ci_runner_machine, runner: runner) } - - context 'with instance runner' do - let(:runner) { build(:ci_runner, :instance) } - - it { expect(runner).to be_valid } - - context 'when sharding_key_id is not present' do - before do - runner.sharding_key_id = nil - runner_manager.sharding_key_id = nil - end - - it { expect(runner_manager).to be_valid } - end - end - - context 'with group runner' do - let(:runner) { build(:ci_runner, :group, groups: [group]) } - - it { expect(runner_manager).to be_valid } - - context 'when sharding_key_id is not present' do - before do - runner.sharding_key_id = nil - runner_manager.sharding_key_id = nil - end - - it 'adds error to model', :aggregate_failures do - expect(runner_manager).not_to be_valid - expect(runner_manager.errors[:sharding_key_id]).to contain_exactly("can't be blank") - end - end - end - - context 'with project runner' do - let(:runner) { build(:ci_runner, :project, projects: [project]) } - - it { expect(runner).to be_valid } - - context 'when sharding_key_id is not present' do - before do - runner.sharding_key_id = nil - end - - it 'adds error to model', :aggregate_failures do - expect(runner_manager).not_to be_valid - expect(runner_manager.errors[:sharding_key_id]).to contain_exactly("can't be blank") - end - end - end - end - context 'when runner has runtime features' do it 'is valid' do runner_manager = build(:ci_runner_machine, runtime_features: { cancelable: true }) diff --git a/spec/models/ci/runner_spec.rb b/spec/models/ci/runner_spec.rb index 3eb01b9cc43cd8bc93e2e07ebf6718770dd347c0..755d3cc7a2c8bda7a11f62c44fe5b107d192377c 100644 --- a/spec/models/ci/runner_spec.rb +++ b/spec/models/ci/runner_spec.rb @@ -127,7 +127,6 @@ it { is_expected.to validate_presence_of(:access_level) } it { is_expected.to validate_presence_of(:runner_type) } it { is_expected.to validate_presence_of(:registration_type) } - it { is_expected.to validate_presence_of(:sharding_key_id) } it { is_expected.to validate_presence_of(:organization_id).on([:create, :update]) } context 'when runner is instance type' do @@ -135,15 +134,6 @@ it { expect(runner).to be_valid } - context 'when sharding_key_id is present' do - let(:runner) { build(:ci_runner, :instance_type, sharding_key_id: non_existing_record_id) } - - it 'is invalid' do - expect(runner).to be_invalid - expect(runner.errors.full_messages).to contain_exactly('Runner cannot have sharding_key_id assigned') - end - end - context 'when organization_id is present' do let(:runner) { build(:ci_runner, :instance_type, organization_id: non_existing_record_id) } @@ -1614,7 +1604,7 @@ def expect_db_update shared_examples 'a group runner encrypted token' do |prefix| let(:runner_type) { :group_type } - let(:attrs) { { groups: [group], sharding_key_id: group.id } } + let(:attrs) { { groups: [group], organization_id: group.organization_id } } it_behaves_like 'an encrypted routable token for resource', prefix do let(:resource) { group } @@ -1623,7 +1613,7 @@ def expect_db_update shared_examples 'a project runner encrypted token' do |prefix| let(:runner_type) { :project_type } - let(:attrs) { { projects: [project], sharding_key_id: project.id } } + let(:attrs) { { projects: [project], organization_id: project.organization_id } } it_behaves_like 'an encrypted routable token for resource', prefix do let(:resource) { project } @@ -1865,6 +1855,30 @@ def expect_db_update .to change { runner.runner_managers.with_system_xid(system_xid).pluck(:organization_id) } .from([]).to([runner.organization_id]) end + + context 'when runner sharding_key_id is not NULL' do + before do + runner.update!(sharding_key_id: runner.owner.id) + end + + it "populates with runner's sharding_key_id" do + expect { ensure_manager } + .to change { runner.runner_managers.with_system_xid(system_xid).pluck(:sharding_key_id) } + .from([]).to([runner.sharding_key_id]) + end + end + + context 'when runner sharding_key_id is NULL' do + before do + runner.update!(sharding_key_id: nil) + end + + it 'populates a bogus sharding_key_id' do + expect { ensure_manager } + .to change { runner.runner_managers.with_system_xid(system_xid).pluck(:sharding_key_id) } + .from([]).to([0]) + end + end end context 'with group runner' do @@ -2573,44 +2587,5 @@ def expect_db_update it { is_expected.to contain_exactly(instance_runner, group_runner, project_runner) } end end - - describe '.with_sharding_key' do - subject(:scope) { described_class.with_runner_type(runner_type).with_sharding_key(sharding_key_id) } - - let_it_be(:group_runner) { create(:ci_runner, :group, groups: [group]) } - let_it_be(:project_runner) { create(:ci_runner, :project, projects: [project, other_project]) } - - context 'with group_type' do - let(:runner_type) { 'group_type' } - - context 'when sharding_key_id exists' do - let(:sharding_key_id) { group.id } - - it { is_expected.to contain_exactly(group_runner) } - end - - context 'when sharding_key_id does not exist' do - let(:sharding_key_id) { non_existing_record_id } - - it { is_expected.to eq [] } - end - end - - context 'with project_type' do - let(:runner_type) { 'project_type' } - - context 'when sharding_key_id exists' do - let(:sharding_key_id) { project.id } - - it { is_expected.to contain_exactly(project_runner) } - end - - context 'when sharding_key_id does not exist' do - let(:sharding_key_id) { non_existing_record_id } - - it { is_expected.to eq [] } - end - end - end end end diff --git a/spec/models/ci/runner_tagging_spec.rb b/spec/models/ci/runner_tagging_spec.rb index e21331b476d9da47a529bf104be8af76653a541a..1e1e7ef7c50951f02b1ebdf3bb8df16baaf4f5ea 100644 --- a/spec/models/ci/runner_tagging_spec.rb +++ b/spec/models/ci/runner_tagging_spec.rb @@ -10,41 +10,8 @@ describe 'validations' do it { is_expected.to validate_presence_of(:runner_type) } - it { is_expected.to validate_presence_of(:sharding_key_id) } it { is_expected.to validate_presence_of(:organization_id).on([:create, :update]) } - describe 'sharding_key_id' do - subject(:runner_tagging) { runner.taggings.first } - - context 'when runner_type is instance_type' do - let(:runner) { create(:ci_runner, :instance, tag_list: ['postgres']) } - - it { is_expected.to be_valid } - - context 'and sharding_key_id is not nil' do - before do - runner_tagging.sharding_key_id = group.id - end - - it { is_expected.to be_invalid } - end - end - - context 'when runner_type is group_type' do - let(:runner) { create(:ci_runner, :group, groups: [group], tag_list: ['postgres']) } - - it { is_expected.to be_valid } - - context 'and sharding_key_id is nil' do - before do - runner_tagging.sharding_key_id = nil - end - - it { is_expected.to be_invalid } - end - end - end - describe 'organization_id' do subject(:runner_tagging) { runner.taggings.first } diff --git a/spec/services/ci/runners/update_project_runners_owner_service_spec.rb b/spec/services/ci/runners/update_project_runners_owner_service_spec.rb deleted file mode 100644 index c0ef5e1a716376b85963f59136e1c959299ce6d6..0000000000000000000000000000000000000000 --- a/spec/services/ci/runners/update_project_runners_owner_service_spec.rb +++ /dev/null @@ -1,74 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe ::Ci::Runners::UpdateProjectRunnersOwnerService, '#execute', feature_category: :runner do - let_it_be(:owner_group) { create(:group) } - let_it_be(:owner_project) { create(:project, group: owner_group) } - let_it_be(:new_projects) { create_list(:project, 2) } - - let_it_be(:owned_runner1) do - create(:ci_runner, :project, projects: [owner_project, new_projects.first], tag_list: %w[tag1]) - end - - let_it_be(:owned_runner2) { create(:ci_runner, :project, projects: [owner_project], tag_list: %w[tag1 tag2]) } - let_it_be(:owned_runner3) do - create(:ci_runner, :project, projects: [owner_project, *new_projects.reverse], tag_list: %w[tag2]) - end - - let_it_be(:owned_runner4) do - create(:ci_runner, :project, projects: [owner_project, *new_projects], tag_list: %w[tag1 tag2]) - end - - let_it_be(:other_runner) { create(:ci_runner, :project, projects: new_projects, tag_list: %w[tag1 tag2]) } - let_it_be(:orphaned_runner) { create(:ci_runner, :project, :without_projects, tag_list: %w[tag1 tag2]) } - - let_it_be(:owned_runner1_manager) { create(:ci_runner_machine, runner: owned_runner1) } - let_it_be(:owned_runner2_manager) { create(:ci_runner_machine, runner: owned_runner2) } - let_it_be(:owned_runner3_manager) { create(:ci_runner_machine, runner: owned_runner3) } - let_it_be(:owned_runner4_manager) { create(:ci_runner_machine, runner: owned_runner4) } - - let(:service) { described_class.new(owner_project.id, owner_project.namespace_id) } - - subject(:execute) { service.execute } - - before_all do - owner_project.destroy! - end - - before do - stub_const("#{described_class}::BATCH_SIZE", 2) - end - - it 'updates sharding_key_id on affected runners', :aggregate_failures do - expect { execute } - # owned_runner1's owner project was deleted - .to change { owned_runner1.reload.sharding_key_id }.from(owner_project.id).to(new_projects.first.id) - .and change { owned_runner1_manager.reload.sharding_key_id }.from(owner_project.id).to(new_projects.first.id) - .and change { tagging_sharding_key_id_for_runner(owned_runner1) }.from(owner_project.id).to(new_projects.first.id) - # owned_runner2's owner project was deleted and there were no other associated projects to fall back to - .and change { Ci::Runner.find_by_id(owned_runner2) }.to(nil) # delete, since no other project to adopt it - .and change { Ci::RunnerManager.find_by_id(owned_runner2_manager) }.to(nil) - .and change { Ci::RunnerTagging.find_by_runner_id(owned_runner2) }.to(nil) - # owned_runner3's owner project was deleted - .and change { owned_runner3.reload.sharding_key_id }.from(owner_project.id).to(new_projects.last.id) - .and change { owned_runner3_manager.reload.sharding_key_id }.from(owner_project.id).to(new_projects.last.id) - .and change { tagging_sharding_key_id_for_runner(owned_runner3) }.from(owner_project.id).to(new_projects.last.id) - # owned_runner4's owner project was deleted - .and change { owned_runner4.reload.sharding_key_id }.from(owner_project.id).to(new_projects.first.id) - .and change { owned_runner4_manager.reload.sharding_key_id }.from(owner_project.id).to(new_projects.first.id) - .and change { tagging_sharding_key_id_for_runner(owned_runner4) }.from(owner_project.id).to(new_projects.first.id) - # runners whose owner project was not affected - .and not_change { other_runner.reload.sharding_key_id }.from(new_projects.first.id) - .and not_change { orphaned_runner.reload.sharding_key_id } - .and not_change { tagging_sharding_key_id_for_runner(orphaned_runner) } - - expect(execute).to be_success - end - - private - - def tagging_sharding_key_id_for_runner(runner) - runner.taggings.pluck(:sharding_key_id).uniq.sole - end -end diff --git a/spec/workers/ci/runners/update_project_runners_owner_worker_spec.rb b/spec/workers/ci/runners/update_project_runners_owner_worker_spec.rb deleted file mode 100644 index ab5cbdbc6f02797fce6c2711ab6d972856d6f848..0000000000000000000000000000000000000000 --- a/spec/workers/ci/runners/update_project_runners_owner_worker_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Ci::Runners::UpdateProjectRunnersOwnerWorker, '#handle_event', feature_category: :runner do - let_it_be(:project) { create(:project).tap(&:destroy) } - - let(:project_deleted_event) { Projects::ProjectDeletedEvent.new(data: data) } - let(:data) do - { project_id: project.id, namespace_id: project.namespace_id, root_namespace_id: project.root_namespace.id } - end - - it_behaves_like 'subscribes to event' do - let(:event) { project_deleted_event } - end - - it 'calls Ci::Runners::UpdateProjectRunnersOwnerService' do - expect_next_instance_of( - Ci::Runners::UpdateProjectRunnersOwnerService, project.id, project.namespace_id - ) do |service| - expect(service).to receive(:execute) - end - - described_class.new.handle_event(project_deleted_event) - end -end