2019-03-30 03:23:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-08-29 03:56:52 -04:00
|
|
|
require 'spec_helper'
|
2017-11-02 06:14:10 -04:00
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe Clusters::Applications::Helm do
|
2018-03-01 18:46:02 -05:00
|
|
|
include_examples 'cluster application core specs', :clusters_applications_helm
|
2017-11-03 14:20:29 -04:00
|
|
|
|
2019-02-15 06:16:45 -05:00
|
|
|
describe '.available' do
|
|
|
|
subject { described_class.available }
|
2018-03-29 15:24:10 -04:00
|
|
|
|
2018-08-07 08:39:38 -04:00
|
|
|
let!(:installed_cluster) { create(:clusters_applications_helm, :installed) }
|
2019-02-15 06:16:45 -05:00
|
|
|
let!(:updated_cluster) { create(:clusters_applications_helm, :updated) }
|
2018-03-29 15:24:10 -04:00
|
|
|
|
|
|
|
before do
|
|
|
|
create(:clusters_applications_helm, :errored)
|
|
|
|
end
|
|
|
|
|
2019-02-15 06:16:45 -05:00
|
|
|
it { is_expected.to contain_exactly(installed_cluster, updated_cluster) }
|
2018-08-07 08:39:38 -04:00
|
|
|
end
|
|
|
|
|
2019-04-12 01:42:48 -04:00
|
|
|
describe '#can_uninstall?' do
|
2019-08-02 15:02:57 -04:00
|
|
|
context "with other existing applications" do
|
|
|
|
Clusters::Cluster::APPLICATIONS.keys.each do |application_name|
|
|
|
|
next if application_name == 'helm'
|
|
|
|
|
2019-08-13 01:18:59 -04:00
|
|
|
it "is false when #{application_name} is installed" do
|
2019-08-02 15:02:57 -04:00
|
|
|
cluster_application = create("clusters_applications_#{application_name}".to_sym)
|
|
|
|
|
|
|
|
helm = cluster_application.cluster.application_helm
|
2019-04-12 01:42:48 -04:00
|
|
|
|
2019-08-02 15:02:57 -04:00
|
|
|
expect(helm.allowed_to_uninstall?).to be_falsy
|
|
|
|
end
|
|
|
|
end
|
2019-08-13 01:18:59 -04:00
|
|
|
|
|
|
|
it 'executes a single query only' do
|
|
|
|
cluster_application = create(:clusters_applications_ingress)
|
|
|
|
helm = cluster_application.cluster.application_helm
|
|
|
|
|
|
|
|
query_count = ActiveRecord::QueryRecorder.new { helm.allowed_to_uninstall? }.count
|
|
|
|
expect(query_count).to eq(1)
|
|
|
|
end
|
2019-08-02 15:02:57 -04:00
|
|
|
end
|
2019-04-12 01:42:48 -04:00
|
|
|
|
2019-08-02 15:02:57 -04:00
|
|
|
context "without other existing applications" do
|
|
|
|
subject { helm.can_uninstall? }
|
|
|
|
|
|
|
|
let(:helm) { create(:clusters_applications_helm) }
|
|
|
|
|
|
|
|
it { is_expected.to be_truthy }
|
|
|
|
end
|
2019-04-12 01:42:48 -04:00
|
|
|
end
|
|
|
|
|
2018-08-07 08:39:38 -04:00
|
|
|
describe '#issue_client_cert' do
|
|
|
|
let(:application) { create(:clusters_applications_helm) }
|
2019-12-18 19:08:01 -05:00
|
|
|
|
2018-08-07 08:39:38 -04:00
|
|
|
subject { application.issue_client_cert }
|
|
|
|
|
|
|
|
it 'returns a new cert' do
|
|
|
|
is_expected.to be_kind_of(Gitlab::Kubernetes::Helm::Certificate)
|
|
|
|
expect(subject.cert_string).not_to eq(application.ca_cert)
|
|
|
|
expect(subject.key_string).not_to eq(application.ca_key)
|
|
|
|
end
|
2018-03-29 15:24:10 -04:00
|
|
|
end
|
|
|
|
|
2017-11-07 09:26:14 -05:00
|
|
|
describe '#install_command' do
|
2018-03-01 18:46:02 -05:00
|
|
|
let(:helm) { create(:clusters_applications_helm) }
|
2017-11-03 14:20:29 -04:00
|
|
|
|
2018-03-01 18:46:02 -05:00
|
|
|
subject { helm.install_command }
|
2017-11-03 14:20:29 -04:00
|
|
|
|
2018-03-01 18:46:02 -05:00
|
|
|
it { is_expected.to be_an_instance_of(Gitlab::Kubernetes::Helm::InitCommand) }
|
2017-11-02 06:14:10 -04:00
|
|
|
|
2019-04-05 04:43:27 -04:00
|
|
|
it 'is initialized with 1 arguments' do
|
2018-03-01 18:46:02 -05:00
|
|
|
expect(subject.name).to eq('helm')
|
2017-11-02 06:14:10 -04:00
|
|
|
end
|
2018-08-07 08:39:38 -04:00
|
|
|
|
2019-04-05 04:43:27 -04:00
|
|
|
it 'has cert files' do
|
2018-08-07 08:39:38 -04:00
|
|
|
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
|
2018-09-06 06:03:38 -04:00
|
|
|
|
|
|
|
describe 'rbac' do
|
2019-01-03 08:41:53 -05:00
|
|
|
context 'rbac cluster' do
|
|
|
|
it { expect(subject).to be_rbac }
|
2018-09-06 06:03:38 -04:00
|
|
|
end
|
|
|
|
|
2019-01-03 08:41:53 -05:00
|
|
|
context 'non rbac cluster' do
|
2018-09-06 06:03:38 -04:00
|
|
|
before do
|
2019-01-03 08:41:53 -05:00
|
|
|
helm.cluster.platform_kubernetes.abac!
|
2018-09-06 06:03:38 -04:00
|
|
|
end
|
|
|
|
|
2019-01-03 08:41:53 -05:00
|
|
|
it { expect(subject).not_to be_rbac }
|
2018-09-06 06:03:38 -04:00
|
|
|
end
|
|
|
|
end
|
2017-11-02 06:14:10 -04:00
|
|
|
end
|
2019-08-02 15:02:57 -04:00
|
|
|
|
|
|
|
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::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
|
2019-09-23 20:06:02 -04:00
|
|
|
|
|
|
|
describe '#post_uninstall' do
|
|
|
|
let(:helm) { create(:clusters_applications_helm, :installed) }
|
|
|
|
|
|
|
|
it do
|
|
|
|
expect(helm.cluster.kubeclient).to receive(:delete_namespace).with('gitlab-managed-apps')
|
|
|
|
|
|
|
|
helm.post_uninstall
|
|
|
|
end
|
|
|
|
end
|
2017-11-02 06:14:10 -04:00
|
|
|
end
|