Commit 44eec568 authored by Thong Kuah's avatar Thong Kuah Committed by Stan Hu

Expose can_uninstall in cluster_status.json

Only prometheus can be uninstalled atm, the rest will be dealt with
later.

Presumption is that new application types will have uninstallation
implmemented at the same time.
parent 3c8df0c9
...@@ -24,6 +24,12 @@ module Clusters ...@@ -24,6 +24,12 @@ module Clusters
'stable/cert-manager' 'stable/cert-manager'
end end
# We will implement this in future MRs.
# Need to reverse postinstall step
def allowed_to_uninstall?
false
end
def install_command def install_command
Gitlab::Kubernetes::Helm::InstallCommand.new( Gitlab::Kubernetes::Helm::InstallCommand.new(
name: 'certmanager', name: 'certmanager',
......
...@@ -29,6 +29,13 @@ module Clusters ...@@ -29,6 +29,13 @@ module Clusters
self.status = 'installable' if cluster&.platform_kubernetes_active? self.status = 'installable' if cluster&.platform_kubernetes_active?
end end
# We will implement this in future MRs.
# Basically we need to check all other applications are not installed
# first.
def allowed_to_uninstall?
false
end
def install_command def install_command
Gitlab::Kubernetes::Helm::InitCommand.new( Gitlab::Kubernetes::Helm::InitCommand.new(
name: name, name: name,
......
...@@ -35,6 +35,13 @@ module Clusters ...@@ -35,6 +35,13 @@ module Clusters
'stable/nginx-ingress' 'stable/nginx-ingress'
end end
# We will implement this in future MRs.
# Basically we need to check all dependent applications are not installed
# first.
def allowed_to_uninstall?
false
end
def install_command def install_command
Gitlab::Kubernetes::Helm::InstallCommand.new( Gitlab::Kubernetes::Helm::InstallCommand.new(
name: name, name: name,
......
...@@ -38,6 +38,12 @@ module Clusters ...@@ -38,6 +38,12 @@ module Clusters
content_values.to_yaml content_values.to_yaml
end end
# Will be addressed in future MRs
# We need to investigate and document what will be permenantly deleted.
def allowed_to_uninstall?
false
end
def install_command def install_command
Gitlab::Kubernetes::Helm::InstallCommand.new( Gitlab::Kubernetes::Helm::InstallCommand.new(
name: name, name: name,
......
...@@ -51,6 +51,12 @@ module Clusters ...@@ -51,6 +51,12 @@ module Clusters
{ "domain" => hostname }.to_yaml { "domain" => hostname }.to_yaml
end end
# Handled in a new issue:
# https://gitlab.com/gitlab-org/gitlab-ce/issues/59369
def allowed_to_uninstall?
false
end
def install_command def install_command
Gitlab::Kubernetes::Helm::InstallCommand.new( Gitlab::Kubernetes::Helm::InstallCommand.new(
name: name, name: name,
......
...@@ -29,6 +29,13 @@ module Clusters ...@@ -29,6 +29,13 @@ module Clusters
content_values.to_yaml content_values.to_yaml
end end
# Need to investigate if pipelines run by this runner will stop upon the
# executor pod stopping
# I.e.run a pipeline, and uninstall runner while pipeline is running
def allowed_to_uninstall?
false
end
def install_command def install_command
Gitlab::Kubernetes::Helm::InstallCommand.new( Gitlab::Kubernetes::Helm::InstallCommand.new(
name: name, name: name,
......
...@@ -18,6 +18,16 @@ module Clusters ...@@ -18,6 +18,16 @@ module Clusters
self.status = 'installable' if cluster&.application_helm_available? self.status = 'installable' if cluster&.application_helm_available?
end end
def can_uninstall?
allowed_to_uninstall?
end
# All new applications should uninstall by default
# Override if there's dependencies that needs to be uninstalled first
def allowed_to_uninstall?
true
end
def self.application_name def self.application_name
self.to_s.demodulize.underscore self.to_s.demodulize.underscore
end end
......
...@@ -10,4 +10,5 @@ class ClusterApplicationEntity < Grape::Entity ...@@ -10,4 +10,5 @@ class ClusterApplicationEntity < Grape::Entity
expose :hostname, if: -> (e, _) { e.respond_to?(:hostname) } expose :hostname, if: -> (e, _) { e.respond_to?(:hostname) }
expose :email, if: -> (e, _) { e.respond_to?(:email) } expose :email, if: -> (e, _) { e.respond_to?(:email) }
expose :update_available?, as: :update_available, if: -> (e, _) { e.respond_to?(:update_available?) } expose :update_available?, as: :update_available, if: -> (e, _) { e.respond_to?(:update_available?) }
expose :can_uninstall?, as: :can_uninstall
end end
...@@ -36,7 +36,8 @@ ...@@ -36,7 +36,8 @@
"external_hostname": { "type": ["string", "null"] }, "external_hostname": { "type": ["string", "null"] },
"hostname": { "type": ["string", "null"] }, "hostname": { "type": ["string", "null"] },
"email": { "type": ["string", "null"] }, "email": { "type": ["string", "null"] },
"update_available": { "type": ["boolean", "null"] } "update_available": { "type": ["boolean", "null"] },
"can_uninstall": { "type": "boolean" }
}, },
"required" : [ "name", "status" ] "required" : [ "name", "status" ]
} }
......
...@@ -10,6 +10,12 @@ describe Clusters::Applications::CertManager do ...@@ -10,6 +10,12 @@ describe Clusters::Applications::CertManager do
include_examples 'cluster application version specs', :clusters_applications_cert_managers include_examples 'cluster application version specs', :clusters_applications_cert_managers
include_examples 'cluster application initial status specs' include_examples 'cluster application initial status specs'
describe '#can_uninstall?' do
subject { cert_manager.can_uninstall? }
it { is_expected.to be_falsey }
end
describe '#install_command' do describe '#install_command' do
let(:cert_email) { 'admin@example.com' } let(:cert_email) { 'admin@example.com' }
......
...@@ -18,6 +18,14 @@ describe Clusters::Applications::Helm do ...@@ -18,6 +18,14 @@ describe Clusters::Applications::Helm do
it { is_expected.to contain_exactly(installed_cluster, updated_cluster) } it { is_expected.to contain_exactly(installed_cluster, updated_cluster) }
end end
describe '#can_uninstall?' do
let(:helm) { create(:clusters_applications_helm) }
subject { helm.can_uninstall? }
it { is_expected.to be_falsey }
end
describe '#issue_client_cert' do describe '#issue_client_cert' do
let(:application) { create(:clusters_applications_helm) } let(:application) { create(:clusters_applications_helm) }
subject { application.issue_client_cert } subject { application.issue_client_cert }
......
...@@ -18,6 +18,12 @@ describe Clusters::Applications::Ingress do ...@@ -18,6 +18,12 @@ describe Clusters::Applications::Ingress do
allow(ClusterWaitForIngressIpAddressWorker).to receive(:perform_async) allow(ClusterWaitForIngressIpAddressWorker).to receive(:perform_async)
end end
describe '#can_uninstall?' do
subject { ingress.can_uninstall? }
it { is_expected.to be_falsey }
end
describe '#make_installed!' do describe '#make_installed!' do
before do before do
application.make_installed! application.make_installed!
......
...@@ -10,6 +10,15 @@ describe Clusters::Applications::Jupyter do ...@@ -10,6 +10,15 @@ describe Clusters::Applications::Jupyter do
it { is_expected.to belong_to(:oauth_application) } it { is_expected.to belong_to(:oauth_application) }
describe '#can_uninstall?' do
let(:ingress) { create(:clusters_applications_ingress, :installed, external_hostname: 'localhost.localdomain') }
let(:jupyter) { create(:clusters_applications_jupyter, cluster: ingress.cluster) }
subject { jupyter.can_uninstall? }
it { is_expected.to be_falsey }
end
describe '#set_initial_status' do describe '#set_initial_status' do
before do before do
jupyter.set_initial_status jupyter.set_initial_status
......
...@@ -39,6 +39,12 @@ describe Clusters::Applications::Knative do ...@@ -39,6 +39,12 @@ describe Clusters::Applications::Knative do
end end
end end
describe '#can_uninstall?' do
subject { knative.can_uninstall? }
it { is_expected.to be_falsey }
end
describe '#schedule_status_update with external_ip' do describe '#schedule_status_update with external_ip' do
let(:application) { create(:clusters_applications_knative, :installed) } let(:application) { create(:clusters_applications_knative, :installed) }
......
...@@ -29,6 +29,14 @@ describe Clusters::Applications::Prometheus do ...@@ -29,6 +29,14 @@ describe Clusters::Applications::Prometheus do
end end
end end
describe '#can_uninstall?' do
let(:prometheus) { create(:clusters_applications_prometheus) }
subject { prometheus.can_uninstall? }
it { is_expected.to be_truthy }
end
describe '#prometheus_client' do describe '#prometheus_client' do
context 'cluster is nil' do context 'cluster is nil' do
it 'returns nil' do it 'returns nil' do
......
...@@ -13,6 +13,14 @@ describe Clusters::Applications::Runner do ...@@ -13,6 +13,14 @@ describe Clusters::Applications::Runner do
it { is_expected.to belong_to(:runner) } it { is_expected.to belong_to(:runner) }
describe '#can_uninstall?' do
let(:gitlab_runner) { create(:clusters_applications_runner, runner: ci_runner) }
subject { gitlab_runner.can_uninstall? }
it { is_expected.to be_falsey }
end
describe '#install_command' do describe '#install_command' do
let(:kubeclient) { double('kubernetes client') } let(:kubeclient) { double('kubernetes client') }
let(:gitlab_runner) { create(:clusters_applications_runner, runner: ci_runner) } let(:gitlab_runner) { create(:clusters_applications_runner, runner: ci_runner) }
......
...@@ -21,6 +21,10 @@ describe ClusterApplicationEntity do ...@@ -21,6 +21,10 @@ describe ClusterApplicationEntity do
expect(subject[:status_reason]).to be_nil expect(subject[:status_reason]).to be_nil
end end
it 'has can_uninstall' do
expect(subject[:can_uninstall]).to be_falsey
end
context 'non-helm application' do context 'non-helm application' do
let(:application) { build(:clusters_applications_runner, version: '0.0.0') } let(:application) { build(:clusters_applications_runner, version: '0.0.0') }
......
...@@ -2,6 +2,14 @@ shared_examples 'cluster application core specs' do |application_name| ...@@ -2,6 +2,14 @@ shared_examples 'cluster application core specs' do |application_name|
it { is_expected.to belong_to(:cluster) } it { is_expected.to belong_to(:cluster) }
it { is_expected.to validate_presence_of(:cluster) } it { is_expected.to validate_presence_of(:cluster) }
describe '#can_uninstall?' do
it 'calls allowed_to_uninstall?' do
expect(subject).to receive(:allowed_to_uninstall?).and_return(true)
expect(subject.can_uninstall?).to be_truthy
end
end
describe '#name' do describe '#name' do
it 'is .application_name' do it 'is .application_name' do
expect(subject.name).to eq(described_class.application_name) expect(subject.name).to eq(described_class.application_name)
......
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