diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index c189b519..231960ef 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -68,7 +68,7 @@ class ProjectsController < ApplicationController # DELETE /projects/1 or /projects/1.json def destroy - @project.destroy! + Projects::DestroyJob.perform_later(@project) respond_to do |format| format.html { redirect_to projects_url, status: :see_other, notice: "Project was successfully destroyed." } format.json { head :no_content } diff --git a/app/jobs/projects/destroy_job.rb b/app/jobs/projects/destroy_job.rb new file mode 100644 index 00000000..54757b17 --- /dev/null +++ b/app/jobs/projects/destroy_job.rb @@ -0,0 +1,12 @@ + +class Projects::DestroyJob < ApplicationJob + + def perform(project) + kubeconfig = project.cluster.kubeconfig + kubectl = K8::Kubectl.new(kubeconfig) + + kubectl.call("delete namespace #{project.name}") + + project.destroy! + end +end