Stop writing plan_id on ci_pending_builds

What does this MR do and why?

Stops writing plans.id into ci_pending_builds.plan_id. plans is cell-local, so the id does not survive an organization move (&20087), and nothing reads the column.

belongs_to :plan becomes belongs_to_fixed_items on GitlabSubscriptions::SystemDefined::Plan (it was already keyed on plan_name_uid). plan_id is ignored until #600317 drops it.

Part of #571923.

Database

No migration. The only SQL change is the pending-build upsert: its INSERT no longer includes plan_id. No new or altered query.

How to set up and validate locally

Specs:

bin/rspec spec/models/ci/pending_build_spec.rb ee/spec/models/ee/ci/pending_build_spec.rb

By hand. The plan_name_uid write only happens on SaaS, so the console needs the SaaS flag. No license is needed for this path.

  1. If a local runner is running, stop it so nothing picks the pending build up.

  2. Open a SaaS-simulated console: GITLAB_SIMULATE_SAAS=1 bin/rails console.

  3. Put a seeded project's root group on Premium and grab one of its builds:

    build   = Ci::Build.last                      # any seeded project with a pipeline
    project = build.project
    group   = project.root_ancestor
    
    premium = Plan.find_or_create_by!(name: 'premium') { |p| p.title = 'Premium' }
    GitlabSubscription.find_or_initialize_by(namespace: group)
      .update!(hosted_plan: premium, seats: 10, start_date: Date.current)
    project.update!(shared_runners_enabled: true)
    
    project.reset.actual_plan.name  # => "premium"
  4. Write the pending build and check the row:

    Ci::PendingBuild.upsert_from_build!(build)
    Ci::PendingBuild.where(build: build).pick('plan_id', 'plan_name_uid')
    # => [nil, 5]        master puts plans.id in the first slot
    
    pb = Ci::PendingBuild.find_by(build: build)
    pb.plan                  # => #<GitlabSubscriptions::SystemDefined::Plan ... name: "premium">
    pb.respond_to?(:plan_id) # => false
  5. Check the only reader, the runner allowed-plans filter, still matches on plan_name_uid:

    runner = Ci::Runner.instance_type.first ||
      Ci::Runner.create!(runner_type: :instance_type, access_level: :not_protected,
        registration_type: :registration_token, description: 'plan filter test')
    
    runner.update!(allowed_plans: ['premium'])
    Ci::Queue::BuildQueueService.new(runner).builds_for_shared_runner.exists?(build_id: build.id) # => true
    runner.update!(allowed_plans: ['ultimate'])
    Ci::Queue::BuildQueueService.new(runner).builds_for_shared_runner.exists?(build_id: build.id) # => false

Clean up with Ci::PendingBuild.where(build: build).delete_all and runner.update!(allowed_plans: []).

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Ryan Cobb

Merge request reports

Loading
Loading