Commit 024ddcab authored by Thong Kuah's avatar Thong Kuah Committed by Stan Hu

Deactivate any prometheus_service upon destroy

Basically does the reverse of after_transition to :installed.
parent eae0fc2b
...@@ -16,6 +16,8 @@ module Clusters ...@@ -16,6 +16,8 @@ module Clusters
default_value_for :version, VERSION default_value_for :version, VERSION
after_destroy :disable_prometheus_integration
state_machine :status do state_machine :status do
after_transition any => [:installed] do |application| after_transition any => [:installed] do |application|
application.cluster.projects.each do |project| application.cluster.projects.each do |project|
...@@ -90,6 +92,12 @@ module Clusters ...@@ -90,6 +92,12 @@ module Clusters
private private
def disable_prometheus_integration
cluster.projects.each do |project|
project.prometheus_service&.update(active: false)
end
end
def kube_client def kube_client
cluster&.kubeclient&.core_client cluster&.kubeclient&.core_client
end end
......
...@@ -11,6 +11,23 @@ describe Clusters::Applications::Prometheus do ...@@ -11,6 +11,23 @@ describe Clusters::Applications::Prometheus do
include_examples 'cluster application helm specs', :clusters_applications_prometheus include_examples 'cluster application helm specs', :clusters_applications_prometheus
include_examples 'cluster application initial status specs' include_examples 'cluster application initial status specs'
describe 'after_destroy' do
let(:project) { create(:project) }
let(:cluster) { create(:cluster, :with_installed_helm, projects: [project]) }
let!(:application) { create(:clusters_applications_prometheus, :installed, cluster: cluster) }
let!(:prometheus_service) { project.create_prometheus_service(active: true) }
it 'deactivates prometheus_service after destroy' do
expect do
application.destroy
prometheus_service.reload
end.to change(prometheus_service, :active)
expect(prometheus_service).not_to be_active
end
end
describe 'transition to installed' do describe 'transition to installed' do
let(:project) { create(:project) } let(:project) { create(:project) }
let(:cluster) { create(:cluster, :with_installed_helm, projects: [project]) } let(:cluster) { create(:cluster, :with_installed_helm, projects: [project]) }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment