Skip to content

WIP: Refactor Clusters Application Services Flow By moving services upwards into workers.

What does this MR do?

This MR will try to reduce the amount of code duplication and make this flow simpler for a developer to follow through by rearranging some of this code. So here is the proposal:

There are 4 sidekiq workers with 90% duplicated code, that only differ from one to another by the fact that they call a different specific service on their performs. The workers are super small, so I don't see the reason why they couldn't contain the logic from the services they're calling, specially because those services are not called anywhere else. So we could delete the services and move their logic inside the workers. The workers I mean are:

ClusterInstallAppWorker calls Clusters::Applications::InstallService

ClusterUpgradeAppWorker calls Clusters::Applications::UpgradeService

ClusterWaitForIngressIpAddressWorker calls Clusters::Applications::CheckIngressIpAddressService

ClusterWaitForAppInstallationWorker calls Clusters::Applications::CheckInstallationProgressService

The 4 services I mentioned above inherit from Clusters::Applications::BaseHelmService. And they're the only ones who inherit from this class. So to move those services logic inside the workers we'll rename Clusters::Applications::BaseHelmService to Clusters::Applications::BaseWorker and make the workers inherit from it.

Now that we have a Clusters::Applications::BaseWorker which all those workers inherit from, we can remove some of the code duplication we had before.

Right now, If you check these workers you'll see that their structure is mostly duplicated. The base code for all of them is like:

class Cluster*Worker
  include ApplicationWorker
  include ClusterQueue
  include ClusterApplications

  def perform(app_name, app_id)
    find_application(app_name, app_id) do |app|
      Clusters::Applications::*Service.new(app).execute
    end
  end
end

After the move we should have no more of those services and workers will look like something like:

Clusters::Applications::BaseWorker
  include ApplicationWorker
  include ClusterQueue

  def perform(app_name, app_id)
    @app = Clusters::Cluster::APPLICATIONS[app_name].find(id)
  end

  # BaseHelmService logic moved here ...
end
class Cluster*Worker < Clusters::Applications::BaseWorker
  def perform(app_name, app_id)
    super
    execute
  end

  protected

  def execute
    # Cluster::Applications::*Service logic here...
  end
end

Delete ClusterApplications concern. Since its logic is now only used in Clusters::Applications::BaseWorker, we don't need a concern anymore.

Final Stacks

Installation Stack

Clusters::ApplicationsController -> Clusters::Applications::CreateService -> ClusterInstallAppWorker -> ClusterWaitForAppInstallationWorker

Upgrade Stack

Clusters::ApplicationsController -> Clusters::Applications::CreateService -> ClusterUpgradeAppWorker -> ClusterWaitForAppInstallationWorker

What are the relevant issue numbers?

#58005 (closed)

Does this MR meet the acceptance criteria?

Edited by 🤖 GitLab Bot 🤖

Merge request reports