diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-04-12 18:15:44 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-04-12 18:15:44 +0300 |
commit | c1a7bcdf1bfef9455bc58b1737f52530bf681a90 (patch) | |
tree | fb683b37e3ef58bb7bd7698629796ed9c5bfbeae /spec/models/clusters | |
parent | e0d7577e29dcab90623e1f38cf11b351c665ee23 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models/clusters')
-rw-r--r-- | spec/models/clusters/applications/helm_spec.rb | 116 | ||||
-rw-r--r-- | spec/models/clusters/cluster_spec.rb | 127 | ||||
-rw-r--r-- | spec/models/clusters/integrations/prometheus_spec.rb | 4 |
3 files changed, 4 insertions, 243 deletions
diff --git a/spec/models/clusters/applications/helm_spec.rb b/spec/models/clusters/applications/helm_spec.rb deleted file mode 100644 index 1b8be92475a..00000000000 --- a/spec/models/clusters/applications/helm_spec.rb +++ /dev/null @@ -1,116 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Clusters::Applications::Helm do - include_examples 'cluster application core specs', :clusters_applications_helm - - describe 'default values' do - it { expect(subject.version).to eq(Gitlab::Kubernetes::Helm::V2::BaseCommand::HELM_VERSION) } - end - - describe '.available' do - subject { described_class.available } - - let!(:installed_cluster) { create(:clusters_applications_helm, :installed) } - let!(:updated_cluster) { create(:clusters_applications_helm, :updated) } - - before do - create(:clusters_applications_helm, :errored) - end - - it { is_expected.to contain_exactly(installed_cluster, updated_cluster) } - end - - describe '#can_uninstall?' do - subject(:application) { build(:clusters_applications_helm).can_uninstall? } - - it { is_expected.to eq true } - end - - describe '#issue_client_cert' do - let(:application) { create(:clusters_applications_helm) } - - subject { application.issue_client_cert } - - it 'returns a new cert' do - is_expected.to be_kind_of(Gitlab::Kubernetes::Helm::V2::Certificate) - expect(subject.cert_string).not_to eq(application.ca_cert) - expect(subject.key_string).not_to eq(application.ca_key) - end - end - - describe '#install_command' do - let(:helm) { create(:clusters_applications_helm) } - - subject { helm.install_command } - - it { is_expected.to be_an_instance_of(Gitlab::Kubernetes::Helm::V2::InitCommand) } - - it 'is initialized with 1 arguments' do - expect(subject.name).to eq('helm') - end - - it 'has cert files' do - expect(subject.files[:'ca.pem']).to be_present - expect(subject.files[:'ca.pem']).to eq(helm.ca_cert) - - expect(subject.files[:'cert.pem']).to be_present - expect(subject.files[:'key.pem']).to be_present - - cert = OpenSSL::X509::Certificate.new(subject.files[:'cert.pem']) - expect(cert.not_after).to be > 999.years.from_now - end - - describe 'rbac' do - context 'rbac cluster' do - it { expect(subject).to be_rbac } - end - - context 'non rbac cluster' do - before do - helm.cluster.platform_kubernetes.abac! - end - - it { expect(subject).not_to be_rbac } - end - end - end - - describe '#uninstall_command' do - let(:helm) { create(:clusters_applications_helm) } - - subject { helm.uninstall_command } - - it { is_expected.to be_an_instance_of(Gitlab::Kubernetes::Helm::V2::ResetCommand) } - - it 'has name' do - expect(subject.name).to eq('helm') - end - - it 'has cert files' do - expect(subject.files[:'ca.pem']).to be_present - expect(subject.files[:'ca.pem']).to eq(helm.ca_cert) - - expect(subject.files[:'cert.pem']).to be_present - expect(subject.files[:'key.pem']).to be_present - - cert = OpenSSL::X509::Certificate.new(subject.files[:'cert.pem']) - expect(cert.not_after).to be > 999.years.from_now - end - - describe 'rbac' do - context 'rbac cluster' do - it { expect(subject).to be_rbac } - end - - context 'non rbac cluster' do - before do - helm.cluster.platform_kubernetes.abac! - end - - it { expect(subject).not_to be_rbac } - end - end - end -end diff --git a/spec/models/clusters/cluster_spec.rb b/spec/models/clusters/cluster_spec.rb index f1d4a91f289..b038eb7c03e 100644 --- a/spec/models/clusters/cluster_spec.rb +++ b/spec/models/clusters/cluster_spec.rb @@ -23,7 +23,6 @@ feature_category: :kubernetes_management do it { is_expected.to have_one(:provider_aws) } it { is_expected.to have_one(:platform_kubernetes) } it { is_expected.to have_one(:integration_prometheus) } - it { is_expected.to have_one(:application_helm) } it { is_expected.to have_many(:kubernetes_namespaces) } it { is_expected.to have_one(:cluster_project) } it { is_expected.to have_many(:deployment_clusters) } @@ -45,15 +44,6 @@ feature_category: :kubernetes_management do let(:factory_name) { :cluster } end - describe 'applications have inverse_of: :cluster option' do - let(:cluster) { create(:cluster) } - let!(:helm) { create(:clusters_applications_helm, cluster: cluster) } - - it 'does not do a third query when referencing cluster again' do - expect { cluster.application_helm.cluster }.not_to exceed_query_limit(2) - end - end - describe '.enabled' do subject { described_class.enabled } @@ -688,89 +678,6 @@ feature_category: :kubernetes_management do end end - describe '.with_persisted_applications' do - let(:cluster) { create(:cluster) } - let!(:helm) { create(:clusters_applications_helm, :installed, cluster: cluster) } - - it 'preloads persisted applications' do - query_rec = ActiveRecord::QueryRecorder.new do - described_class.with_persisted_applications.find_by_id(cluster.id).application_helm - end - - expect(query_rec.count).to eq(1) - end - end - - describe '#persisted_applications' do - let(:cluster) { create(:cluster) } - - subject { cluster.persisted_applications } - - context 'when applications are created' do - let!(:helm) { create(:clusters_applications_helm, cluster: cluster) } - - it 'returns a list of created applications' do - is_expected.to contain_exactly(helm) - end - end - end - - describe '#applications' do - let_it_be(:cluster, reload: true) { create(:cluster) } - - subject { cluster.applications } - - context 'when none of applications are created' do - it 'returns a list of a new objects' do - is_expected.not_to be_empty - end - end - - context 'when applications are created' do - let(:cluster) { create(:cluster, :with_all_applications) } - - it 'returns a list of created applications', :aggregate_failures do - is_expected.to have_attributes(size: described_class::APPLICATIONS.size) - is_expected.to all(be_kind_of(::Clusters::Concerns::ApplicationCore)) - is_expected.to all(be_persisted) - end - end - end - - describe '#find_or_build_application' do - let_it_be(:cluster, reload: true) { create(:cluster) } - - it 'rejects classes that are not applications' do - expect do - cluster.find_or_build_application(Project) - end.to raise_error(ArgumentError) - end - - context 'when none of applications are created' do - it 'returns the new application', :aggregate_failures do - described_class::APPLICATIONS.values.each do |application_class| - application = cluster.find_or_build_application(application_class) - - expect(application).to be_a(application_class) - expect(application).not_to be_persisted - end - end - end - - context 'when application is persisted' do - let(:cluster) { create(:cluster, :with_all_applications) } - - it 'returns the persisted application', :aggregate_failures do - described_class::APPLICATIONS.each_value do |application_class| - application = cluster.find_or_build_application(application_class) - - expect(application).to be_kind_of(::Clusters::Concerns::ApplicationCore) - expect(application).to be_persisted - end - end - end - end - describe '#allow_user_defined_namespace?' do subject { cluster.allow_user_defined_namespace? } @@ -820,7 +727,7 @@ feature_category: :kubernetes_management do describe '#all_projects' do context 'cluster_type is project_type' do let(:project) { create(:project) } - let(:cluster) { create(:cluster, :with_installed_helm, projects: [project]) } + let(:cluster) { create(:cluster, projects: [project]) } it 'returns projects' do expect(cluster.all_projects).to match_array [project] @@ -830,7 +737,7 @@ feature_category: :kubernetes_management do context 'cluster_type is group_type' do let(:group) { create(:group) } let!(:project) { create(:project, group: group) } - let(:cluster) { create(:cluster_for_group, :with_installed_helm, groups: [group]) } + let(:cluster) { create(:cluster_for_group, groups: [group]) } it 'returns group projects' do expect(cluster.all_projects.ids).to match_array [project.id] @@ -1468,34 +1375,4 @@ feature_category: :kubernetes_management do end end end - - describe '#application_helm_available?' do - subject(:application_helm_available?) { cluster.application_helm_available? } - - before do - allow(cluster).to receive(:application_helm).and_return(application_helm) - end - - context 'without application_helm' do - let(:application_helm) {} - - it { is_expected.to eq(false) } - end - - context 'with application_helm' do - let(:application_helm) { instance_double(Clusters::Applications::Helm, available?: available?) } - - context 'with available? set to true' do - let(:available?) { true } - - it { is_expected.to eq(true) } - end - - context 'with available? set to false' do - let(:available?) { false } - - it { is_expected.to eq(false) } - end - end - end end diff --git a/spec/models/clusters/integrations/prometheus_spec.rb b/spec/models/clusters/integrations/prometheus_spec.rb index d6d1105cdb1..f7ab0ae067c 100644 --- a/spec/models/clusters/integrations/prometheus_spec.rb +++ b/spec/models/clusters/integrations/prometheus_spec.rb @@ -28,7 +28,7 @@ RSpec.describe Clusters::Integrations::Prometheus do describe 'after_destroy' do subject(:integration) { create(:clusters_integrations_prometheus, cluster: cluster, enabled: true) } - let(:cluster) { create(:cluster, :with_installed_helm) } + let(:cluster) { create(:cluster) } it 'deactivates prometheus_integration' do expect(Clusters::Applications::DeactivateIntegrationWorker) @@ -41,7 +41,7 @@ RSpec.describe Clusters::Integrations::Prometheus do describe 'after_save' do subject(:integration) { create(:clusters_integrations_prometheus, cluster: cluster, enabled: enabled) } - let(:cluster) { create(:cluster, :with_installed_helm) } + let(:cluster) { create(:cluster) } let(:enabled) { true } context 'when no change to enabled status' do |