Commit b1074be6 authored by Thong Kuah's avatar Thong Kuah

We don't have helm installed when local tiller

- Add tests where local tiller FF is disabled
- Add test where local tiller FF is enabled, and also where helm is
installed / not installed

Simplify prometheus specs which don't need to re-test the same logic
from #files.
parent 097ecc1c
...@@ -23,7 +23,7 @@ module Clusters ...@@ -23,7 +23,7 @@ module Clusters
@files ||= begin @files ||= begin
files = { 'values.yaml': values } files = { 'values.yaml': values }
files.merge!(certificate_files) if cluster.application_helm.has_ssl? files.merge!(certificate_files) if use_tiller_ssl?
files files
end end
...@@ -31,6 +31,12 @@ module Clusters ...@@ -31,6 +31,12 @@ module Clusters
private private
def use_tiller_ssl?
return false if ::Gitlab::Kubernetes::Helm.local_tiller_enabled?
cluster.application_helm.has_ssl?
end
def certificate_files def certificate_files
{ {
'ca.pem': ca_cert, 'ca.pem': ca_cert,
......
...@@ -92,7 +92,10 @@ module Clusters ...@@ -92,7 +92,10 @@ module Clusters
# When installing any application we are also performing an update # When installing any application we are also performing an update
# of tiller (see Gitlab::Kubernetes::Helm::ClientCommand) so # of tiller (see Gitlab::Kubernetes::Helm::ClientCommand) so
# therefore we need to reflect that in the database. # therefore we need to reflect that in the database.
application.cluster.application_helm.update!(version: Gitlab::Kubernetes::Helm::HELM_VERSION)
unless ::Gitlab::Kubernetes::Helm.local_tiller_enabled?
application.cluster.application_helm.update!(version: Gitlab::Kubernetes::Helm::HELM_VERSION)
end
end end
after_transition any => [:uninstalling], :use_transactions => false do |application, _| after_transition any => [:uninstalling], :use_transactions => false do |application, _|
......
...@@ -73,39 +73,71 @@ FactoryBot.define do ...@@ -73,39 +73,71 @@ FactoryBot.define do
factory :clusters_applications_ingress, class: 'Clusters::Applications::Ingress' do factory :clusters_applications_ingress, class: 'Clusters::Applications::Ingress' do
modsecurity_enabled { false } modsecurity_enabled { false }
cluster factory: %i(cluster with_installed_helm provided_by_gcp) cluster factory: %i(cluster with_installed_helm provided_by_gcp)
trait :no_helm_installed do
cluster factory: %i(cluster provided_by_gcp)
end
end end
factory :clusters_applications_cert_manager, class: 'Clusters::Applications::CertManager' do factory :clusters_applications_cert_manager, class: 'Clusters::Applications::CertManager' do
email { 'admin@example.com' } email { 'admin@example.com' }
cluster factory: %i(cluster with_installed_helm provided_by_gcp) cluster factory: %i(cluster with_installed_helm provided_by_gcp)
trait :no_helm_installed do
cluster factory: %i(cluster provided_by_gcp)
end
end end
factory :clusters_applications_elastic_stack, class: 'Clusters::Applications::ElasticStack' do factory :clusters_applications_elastic_stack, class: 'Clusters::Applications::ElasticStack' do
cluster factory: %i(cluster with_installed_helm provided_by_gcp) cluster factory: %i(cluster with_installed_helm provided_by_gcp)
trait :no_helm_installed do
cluster factory: %i(cluster provided_by_gcp)
end
end end
factory :clusters_applications_crossplane, class: 'Clusters::Applications::Crossplane' do factory :clusters_applications_crossplane, class: 'Clusters::Applications::Crossplane' do
stack { 'gcp' } stack { 'gcp' }
cluster factory: %i(cluster with_installed_helm provided_by_gcp) cluster factory: %i(cluster with_installed_helm provided_by_gcp)
trait :no_helm_installed do
cluster factory: %i(cluster provided_by_gcp)
end
end end
factory :clusters_applications_prometheus, class: 'Clusters::Applications::Prometheus' do factory :clusters_applications_prometheus, class: 'Clusters::Applications::Prometheus' do
cluster factory: %i(cluster with_installed_helm provided_by_gcp) cluster factory: %i(cluster with_installed_helm provided_by_gcp)
trait :no_helm_installed do
cluster factory: %i(cluster provided_by_gcp)
end
end end
factory :clusters_applications_runner, class: 'Clusters::Applications::Runner' do factory :clusters_applications_runner, class: 'Clusters::Applications::Runner' do
runner factory: %i(ci_runner) runner factory: %i(ci_runner)
cluster factory: %i(cluster with_installed_helm provided_by_gcp) cluster factory: %i(cluster with_installed_helm provided_by_gcp)
trait :no_helm_installed do
cluster factory: %i(cluster provided_by_gcp)
end
end end
factory :clusters_applications_knative, class: 'Clusters::Applications::Knative' do factory :clusters_applications_knative, class: 'Clusters::Applications::Knative' do
hostname { 'example.com' } hostname { 'example.com' }
cluster factory: %i(cluster with_installed_helm provided_by_gcp) cluster factory: %i(cluster with_installed_helm provided_by_gcp)
trait :no_helm_installed do
cluster factory: %i(cluster provided_by_gcp)
end
end end
factory :clusters_applications_jupyter, class: 'Clusters::Applications::Jupyter' do factory :clusters_applications_jupyter, class: 'Clusters::Applications::Jupyter' do
oauth_application factory: :oauth_application oauth_application factory: :oauth_application
cluster factory: %i(cluster with_installed_helm provided_by_gcp project) cluster factory: %i(cluster with_installed_helm provided_by_gcp project)
trait :no_helm_installed do
cluster factory: %i(cluster provided_by_gcp)
end
end end
end end
end end
...@@ -274,7 +274,8 @@ describe Clusters::Applications::Prometheus do ...@@ -274,7 +274,8 @@ describe Clusters::Applications::Prometheus do
subject { application.files_with_replaced_values({ hello: :world }) } subject { application.files_with_replaced_values({ hello: :world }) }
it 'does not modify #files' do it 'does not modify #files' do
expect(subject[:'values.yaml']).not_to eq(files) expect(subject[:'values.yaml']).not_to eq(files[:'values.yaml'])
expect(files[:'values.yaml']).to eq(application.values) expect(files[:'values.yaml']).to eq(application.values)
end end
...@@ -282,27 +283,17 @@ describe Clusters::Applications::Prometheus do ...@@ -282,27 +283,17 @@ describe Clusters::Applications::Prometheus do
expect(subject[:'values.yaml']).to eq({ hello: :world }) expect(subject[:'values.yaml']).to eq({ hello: :world })
end end
it 'includes cert files' do it 'uses values from #files, except for values.yaml' do
expect(subject[:'ca.pem']).to be_present allow(application).to receive(:files).and_return({
expect(subject[:'ca.pem']).to eq(application.cluster.application_helm.ca_cert) 'values.yaml': 'some value specific to files',
'file_a.txt': 'file_a',
expect(subject[:'cert.pem']).to be_present 'file_b.txt': 'file_b'
expect(subject[:'key.pem']).to be_present })
cert = OpenSSL::X509::Certificate.new(subject[:'cert.pem']) expect(subject.except(:'values.yaml')).to eq({
expect(cert.not_after).to be < 60.minutes.from_now 'file_a.txt': 'file_a',
end 'file_b.txt': 'file_b'
})
context 'when the helm application does not have a ca_cert' do
before do
application.cluster.application_helm.ca_cert = nil
end
it 'does not include cert files' do
expect(subject[:'ca.pem']).not_to be_present
expect(subject[:'cert.pem']).not_to be_present
expect(subject[:'key.pem']).not_to be_present
end
end end
end end
......
...@@ -28,22 +28,46 @@ RSpec.shared_examples 'cluster application helm specs' do |application_name| ...@@ -28,22 +28,46 @@ RSpec.shared_examples 'cluster application helm specs' do |application_name|
describe '#files' do describe '#files' do
subject { application.files } subject { application.files }
context 'when the helm application does not have a ca_cert' do context 'managed_apps_local_tiller feature flag is disabled' do
before do before do
application.cluster.application_helm.ca_cert = nil stub_feature_flags(managed_apps_local_tiller: false)
end end
it 'does not include cert files when there is no ca_cert entry' do context 'when the helm application does not have a ca_cert' do
expect(subject).not_to include(:'ca.pem', :'cert.pem', :'key.pem') before do
application.cluster.application_helm.ca_cert = nil
end
it 'does not include cert files when there is no ca_cert entry' do
expect(subject).not_to include(:'ca.pem', :'cert.pem', :'key.pem')
end
end
it 'includes cert files when there is a ca_cert entry' do
expect(subject).to include(:'ca.pem', :'cert.pem', :'key.pem')
expect(subject[:'ca.pem']).to eq(application.cluster.application_helm.ca_cert)
cert = OpenSSL::X509::Certificate.new(subject[:'cert.pem'])
expect(cert.not_after).to be < 60.minutes.from_now
end end
end end
it 'includes cert files when there is a ca_cert entry' do context 'managed_apps_local_tiller feature flag is enabled' do
expect(subject).to include(:'ca.pem', :'cert.pem', :'key.pem') before do
expect(subject[:'ca.pem']).to eq(application.cluster.application_helm.ca_cert) stub_feature_flags(managed_apps_local_tiller: true)
end
it 'does not include cert files' do
expect(subject).not_to include(:'ca.pem', :'cert.pem', :'key.pem')
end
context 'when cluster does not have helm installed' do
let(:application) { create(application_name, :no_helm_installed) }
cert = OpenSSL::X509::Certificate.new(subject[:'cert.pem']) it 'does not include cert files' do
expect(cert.not_after).to be < 60.minutes.from_now expect(subject).not_to include(:'ca.pem', :'cert.pem', :'key.pem')
end
end
end end
end end
end end
...@@ -48,14 +48,44 @@ RSpec.shared_examples 'cluster application status specs' do |application_name| ...@@ -48,14 +48,44 @@ RSpec.shared_examples 'cluster application status specs' do |application_name|
expect(subject).to be_installed expect(subject).to be_installed
end end
it 'updates helm version' do context 'managed_apps_local_tiller feature flag disabled' do
subject.cluster.application_helm.update!(version: '1.2.3') before do
stub_feature_flags(managed_apps_local_tiller: false)
end
subject.make_installed! it 'updates helm version' do
subject.cluster.application_helm.update!(version: '1.2.3')
subject.cluster.application_helm.reload subject.make_installed!
expect(subject.cluster.application_helm.version).to eq(Gitlab::Kubernetes::Helm::HELM_VERSION) subject.cluster.application_helm.reload
expect(subject.cluster.application_helm.version).to eq(Gitlab::Kubernetes::Helm::HELM_VERSION)
end
end
context 'managed_apps_local_tiller feature flag enabled' do
before do
stub_feature_flags(managed_apps_local_tiller: true)
end
it 'does not update the helm version' do
subject.cluster.application_helm.update!(version: '1.2.3')
expect do
subject.make_installed!
subject.cluster.application_helm.reload
end.not_to change { subject.cluster.application_helm.version }
end
context 'the cluster has no helm installed' do
subject { create(application_name, :installing, :no_helm_installed) }
it 'runs without errors' do
expect { subject.make_installed! }.not_to raise_error
end
end
end end
it 'sets the correct version of the application' do it 'sets the correct version of the application' do
...@@ -77,14 +107,44 @@ RSpec.shared_examples 'cluster application status specs' do |application_name| ...@@ -77,14 +107,44 @@ RSpec.shared_examples 'cluster application status specs' do |application_name|
expect(subject).to be_updated expect(subject).to be_updated
end end
it 'updates helm version' do context 'managed_apps_local_tiller feature flag disabled' do
subject.cluster.application_helm.update!(version: '1.2.3') before do
stub_feature_flags(managed_apps_local_tiller: false)
end
subject.make_installed! it 'updates helm version' do
subject.cluster.application_helm.update!(version: '1.2.3')
subject.cluster.application_helm.reload subject.make_installed!
expect(subject.cluster.application_helm.version).to eq(Gitlab::Kubernetes::Helm::HELM_VERSION) subject.cluster.application_helm.reload
expect(subject.cluster.application_helm.version).to eq(Gitlab::Kubernetes::Helm::HELM_VERSION)
end
end
context 'managed_apps_local_tiller feature flag enabled' do
before do
stub_feature_flags(managed_apps_local_tiller: true)
end
it 'does not update the helm version' do
subject.cluster.application_helm.update!(version: '1.2.3')
expect do
subject.make_installed!
subject.cluster.application_helm.reload
end.not_to change { subject.cluster.application_helm.version }
end
context 'the cluster has no helm installed' do
subject { create(application_name, :updating, :no_helm_installed) }
it 'runs without errors' do
expect { subject.make_installed! }.not_to raise_error
end
end
end end
it 'updates the version of the application' do it 'updates the version of the application' do
......
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