diff options
Diffstat (limited to 'spec/services/clusters')
5 files changed, 5 insertions, 258 deletions
diff --git a/spec/services/clusters/applications/create_service_spec.rb b/spec/services/clusters/applications/create_service_spec.rb index f3b420510a6..eb907377ca8 100644 --- a/spec/services/clusters/applications/create_service_spec.rb +++ b/spec/services/clusters/applications/create_service_spec.rb @@ -46,8 +46,7 @@ RSpec.describe Clusters::Applications::CreateService do context 'ingress application' do let(:params) do { - application: 'ingress', - modsecurity_enabled: true + application: 'ingress' } end @@ -64,10 +63,6 @@ RSpec.describe Clusters::Applications::CreateService do cluster.reload end.to change(cluster, :application_ingress) end - - it 'sets modsecurity_enabled' do - expect(subject.modsecurity_enabled).to eq(true) - end end context 'cert manager application' do diff --git a/spec/services/clusters/cleanup/app_service_spec.rb b/spec/services/clusters/cleanup/app_service_spec.rb deleted file mode 100644 index ea1194d2100..00000000000 --- a/spec/services/clusters/cleanup/app_service_spec.rb +++ /dev/null @@ -1,118 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Clusters::Cleanup::AppService do - describe '#execute' do - let!(:cluster) { create(:cluster, :project, :cleanup_uninstalling_applications, provider_type: :gcp) } - let(:service) { described_class.new(cluster) } - let(:logger) { service.send(:logger) } - let(:log_meta) do - { - service: described_class.name, - cluster_id: cluster.id, - execution_count: 0 - } - end - - subject { service.execute } - - shared_examples 'does not reschedule itself' do - it 'does not reschedule itself' do - expect(Clusters::Cleanup::AppWorker).not_to receive(:perform_in) - end - end - - context 'when cluster has no applications available or transitioning applications' do - it_behaves_like 'does not reschedule itself' - - it 'transitions cluster to cleanup_removing_project_namespaces' do - expect { subject } - .to change { cluster.reload.cleanup_status_name } - .from(:cleanup_uninstalling_applications) - .to(:cleanup_removing_project_namespaces) - end - - it 'schedules Clusters::Cleanup::ProjectNamespaceWorker' do - expect(Clusters::Cleanup::ProjectNamespaceWorker).to receive(:perform_async).with(cluster.id) - subject - end - - it 'logs all events' do - expect(logger).to receive(:info) - .with(log_meta.merge(event: :schedule_remove_project_namespaces)) - - subject - end - end - - context 'when cluster has uninstallable applications' do - shared_examples 'reschedules itself' do - it 'reschedules itself' do - expect(Clusters::Cleanup::AppWorker) - .to receive(:perform_in) - .with(1.minute, cluster.id, 1) - - subject - end - end - - context 'has applications with dependencies' do - let!(:helm) { create(:clusters_applications_helm, :installed, cluster: cluster) } - let!(:ingress) { create(:clusters_applications_ingress, :installed, cluster: cluster) } - let!(:cert_manager) { create(:clusters_applications_cert_manager, :installed, cluster: cluster) } - let!(:jupyter) { create(:clusters_applications_jupyter, :installed, cluster: cluster) } - - it_behaves_like 'reschedules itself' - - it 'only uninstalls apps that are not dependencies for other installed apps' do - expect(Clusters::Applications::UninstallWorker) - .to receive(:perform_async).with(helm.name, helm.id) - .and_call_original - - expect(Clusters::Applications::UninstallWorker) - .not_to receive(:perform_async).with(ingress.name, ingress.id) - - expect(Clusters::Applications::UninstallWorker) - .to receive(:perform_async).with(cert_manager.name, cert_manager.id) - .and_call_original - - expect(Clusters::Applications::UninstallWorker) - .to receive(:perform_async).with(jupyter.name, jupyter.id) - .and_call_original - - subject - end - - it 'logs application uninstalls and next execution' do - expect(logger).to receive(:info) - .with(log_meta.merge(event: :uninstalling_app, application: kind_of(String))).exactly(3).times - expect(logger).to receive(:info) - .with(log_meta.merge(event: :scheduling_execution, next_execution: 1)) - - subject - end - - context 'cluster is not cleanup_uninstalling_applications' do - let!(:cluster) { create(:cluster, :project, provider_type: :gcp) } - - it_behaves_like 'does not reschedule itself' - end - end - - context 'when applications are still uninstalling/scheduled/depending on others' do - let!(:helm) { create(:clusters_applications_helm, :installed, cluster: cluster) } - let!(:ingress) { create(:clusters_applications_ingress, :scheduled, cluster: cluster) } - let!(:runner) { create(:clusters_applications_runner, :uninstalling, cluster: cluster) } - - it_behaves_like 'reschedules itself' - - it 'does not call the uninstallation service' do - expect(Clusters::Applications::UninstallWorker).not_to receive(:new) - - subject - end - end - end - end -end diff --git a/spec/services/clusters/destroy_service_spec.rb b/spec/services/clusters/destroy_service_spec.rb index 76d9cc34b5d..dc600c9e830 100644 --- a/spec/services/clusters/destroy_service_spec.rb +++ b/spec/services/clusters/destroy_service_spec.rb @@ -37,7 +37,7 @@ RSpec.describe Clusters::DestroyService do let(:params) { { cleanup: 'true' } } before do - allow(Clusters::Cleanup::AppWorker).to receive(:perform_async) + allow(Clusters::Cleanup::ProjectNamespaceWorker).to receive(:perform_async) end it 'does not destroy cluster' do @@ -45,10 +45,10 @@ RSpec.describe Clusters::DestroyService do expect(Clusters::Cluster.where(id: cluster.id).exists?).not_to be_falsey end - it 'transition cluster#cleanup_status from cleanup_not_started to cleanup_uninstalling_applications' do + it 'transition cluster#cleanup_status from cleanup_not_started to cleanup_removing_project_namespaces' do expect { subject }.to change { cluster.cleanup_status_name } .from(:cleanup_not_started) - .to(:cleanup_uninstalling_applications) + .to(:cleanup_removing_project_namespaces) end end end diff --git a/spec/services/clusters/gcp/finalize_creation_service_spec.rb b/spec/services/clusters/gcp/finalize_creation_service_spec.rb index d8c95a70bd0..9c553d0eec2 100644 --- a/spec/services/clusters/gcp/finalize_creation_service_spec.rb +++ b/spec/services/clusters/gcp/finalize_creation_service_spec.rb @@ -11,8 +11,6 @@ RSpec.describe Clusters::Gcp::FinalizeCreationService, '#execute' do let(:platform) { cluster.platform } let(:endpoint) { '111.111.111.111' } let(:api_url) { 'https://' + endpoint } - let(:username) { 'sample-username' } - let(:password) { 'sample-password' } let(:secret_name) { 'gitlab-token' } let(:token) { 'sample-token' } let(:namespace) { "#{cluster.project.path}-#{cluster.project.id}" } @@ -34,8 +32,6 @@ RSpec.describe Clusters::Gcp::FinalizeCreationService, '#execute' do expect(provider.endpoint).to eq(endpoint) expect(platform.api_url).to eq(api_url) expect(platform.ca_cert).to eq(Base64.decode64(load_sample_cert).strip) - expect(platform.username).to eq(username) - expect(platform.password).to eq(password) expect(platform.token).to eq(token) end end @@ -83,7 +79,7 @@ RSpec.describe Clusters::Gcp::FinalizeCreationService, '#execute' do shared_context 'kubernetes information successfully fetched' do before do stub_cloud_platform_get_zone_cluster( - provider.gcp_project_id, provider.zone, cluster.name, { endpoint: endpoint, username: username, password: password } + provider.gcp_project_id, provider.zone, cluster.name, { endpoint: endpoint } ) stub_kubeclient_discover(api_url) diff --git a/spec/services/clusters/parse_cluster_applications_artifact_service_spec.rb b/spec/services/clusters/parse_cluster_applications_artifact_service_spec.rb deleted file mode 100644 index 1f6ad218927..00000000000 --- a/spec/services/clusters/parse_cluster_applications_artifact_service_spec.rb +++ /dev/null @@ -1,126 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Clusters::ParseClusterApplicationsArtifactService do - let_it_be(:project) { create(:project) } - let_it_be(:user) { create(:user) } - - before do - project.add_maintainer(user) - end - - describe 'RELEASE_NAMES' do - it 'is included in Cluster application names', :aggregate_failures do - described_class::RELEASE_NAMES.each do |release_name| - expect(Clusters::Cluster::APPLICATIONS).to include(release_name) - end - end - end - - describe '.new' do - let(:job) { build(:ci_build) } - - it 'sets the project and current user', :aggregate_failures do - service = described_class.new(job, user) - - expect(service.project).to eq(job.project) - expect(service.current_user).to eq(user) - end - end - - describe '#execute' do - let_it_be(:cluster, reload: true) { create(:cluster, projects: [project]) } - let_it_be(:deployment, reload: true) { create(:deployment, cluster: cluster) } - - let(:job) { deployment.deployable } - let(:artifact) { create(:ci_job_artifact, :cluster_applications, job: job) } - - it 'calls Gitlab::Kubernetes::Helm::Parsers::ListV2' do - expect(Gitlab::Kubernetes::Helm::Parsers::ListV2).to receive(:new).and_call_original - - result = described_class.new(job, user).execute(artifact) - - expect(result[:status]).to eq(:success) - end - - context 'artifact is not of cluster_applications type' do - let(:artifact) { create(:ci_job_artifact, :archive) } - let(:job) { artifact.job } - - it 'raise ArgumentError' do - expect do - described_class.new(job, user).execute(artifact) - end.to raise_error(ArgumentError, 'Artifact is not cluster_applications file type') - end - end - - context 'artifact exceeds acceptable size' do - it 'returns an error' do - stub_const("#{described_class}::MAX_ACCEPTABLE_ARTIFACT_SIZE", 1.byte) - - result = described_class.new(job, user).execute(artifact) - - expect(result[:status]).to eq(:error) - expect(result[:message]).to eq('Cluster_applications artifact too big. Maximum allowable size: 1 Byte') - end - end - - context 'job has no deployment' do - let(:job) { build(:ci_build) } - - it 'returns an error' do - result = described_class.new(job, user).execute(artifact) - - expect(result[:status]).to eq(:error) - expect(result[:message]).to eq('No deployment found for this job') - end - end - - context 'job has no deployment cluster' do - let(:deployment) { create(:deployment) } - let(:job) { deployment.deployable } - - it 'returns an error' do - result = described_class.new(job, user).execute(artifact) - - expect(result[:status]).to eq(:error) - expect(result[:message]).to eq('No deployment cluster found for this job') - end - end - - context 'blob is empty' do - let(:file) { fixture_file_upload(Rails.root.join("spec/fixtures/helm/helm_list_v2_empty_blob.json.gz")) } - let(:artifact) { create(:ci_job_artifact, :cluster_applications, job: job, file: file) } - - it 'returns success' do - result = described_class.new(job, user).execute(artifact) - - expect(result[:status]).to eq(:success) - end - end - - context 'job has deployment cluster' do - context 'current user does not have access to deployment cluster' do - let(:other_user) { create(:user) } - - it 'returns an error' do - result = described_class.new(job, other_user).execute(artifact) - - expect(result[:status]).to eq(:error) - expect(result[:message]).to eq('No deployment cluster found for this job') - end - end - - it 'does not affect unpermitted cluster applications' do - expect(Clusters::ParseClusterApplicationsArtifactService::RELEASE_NAMES).to contain_exactly('cilium') - end - - Clusters::ParseClusterApplicationsArtifactService::RELEASE_NAMES.each do |release_name| - context release_name do - include_examples 'parse cluster applications artifact', release_name - end - end - end - end -end |