summaryrefslogtreecommitdiff
path: root/app/services/clusters/applications/uninstall_service.rb
blob: 50c8d806c14a084c03b7294c7b9a5657415a9027 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# frozen_string_literal: true

module Clusters
  module Applications
    class UninstallService < BaseHelmService
      def execute
        return unless app.scheduled?

        app.make_uninstalling!
        uninstall
      end

      private

      def uninstall
        helm_api.uninstall(app.uninstall_command)

        Clusters::Applications::WaitForUninstallAppWorker.perform_in(
          Clusters::Applications::WaitForUninstallAppWorker::INTERVAL, app.name, app.id)
      rescue Kubeclient::HttpError => e
        log_error(e)
        app.make_errored!("Kubernetes error: #{e.error_code}")
      rescue StandardError => e
        log_error(e)
        app.make_errored!('Failed to uninstall.')
      end
    end
  end
end