diff options
author | Gilbert Roulot <groulot@gitlab.com> | 2019-03-25 17:14:42 +0100 |
---|---|---|
committer | Gilbert Roulot <groulot@gitlab.com> | 2019-04-01 10:53:04 +0200 |
commit | b0dced271f6555756fb8f7433581994308a06ee4 (patch) | |
tree | ccb52c8b88b4377b9bcf17e38cda102eb9fdb78e | |
parent | 093629fedc43e8b481c6626765e3fcf0603add17 (diff) | |
download | gitlab-ce-8553_enable_modsecurity_on_cluster_ingress-ce.tar.gz |
Port EE changes to CE8553_enable_modsecurity_on_cluster_ingress-ce
Add a upgrade command method to the Ingress application.
-rw-r--r-- | app/models/clusters/applications/ingress.rb | 18 | ||||
-rw-r--r-- | spec/models/clusters/applications/ingress_spec.rb | 79 |
2 files changed, 97 insertions, 0 deletions
diff --git a/app/models/clusters/applications/ingress.rb b/app/models/clusters/applications/ingress.rb index 376d54aab2c..6f49fd06579 100644 --- a/app/models/clusters/applications/ingress.rb +++ b/app/models/clusters/applications/ingress.rb @@ -45,6 +45,24 @@ module Clusters ) end + def upgrade_command(values) + ::Gitlab::Kubernetes::Helm::InstallCommand.new( + name: name, + version: VERSION, + rbac: cluster.platform_kubernetes_rbac?, + chart: chart, + files: files_with_replaced_values(values) + ) + end + + # Returns a copy of files where the values of 'values.yaml' + # are replaced by the argument. + # + # See #values for the data format required + def files_with_replaced_values(replaced_values) + files.merge('values.yaml': replaced_values) + end + def schedule_status_update return unless installed? return if external_ip diff --git a/spec/models/clusters/applications/ingress_spec.rb b/spec/models/clusters/applications/ingress_spec.rb index a40fa988287..bd2bc4d1391 100644 --- a/spec/models/clusters/applications/ingress_spec.rb +++ b/spec/models/clusters/applications/ingress_spec.rb @@ -96,6 +96,46 @@ describe Clusters::Applications::Ingress do end end + describe '#upgrade_command' do + let(:ingress) { build(:clusters_applications_ingress) } + let(:values) { ingress.values } + + it 'returns an instance of Gitlab::Kubernetes::Helm::InstallCommand' do + expect(ingress.upgrade_command(values)).to be_an_instance_of(::Gitlab::Kubernetes::Helm::InstallCommand) + end + + it 'should be initialized with ingress arguments' do + command = ingress.upgrade_command(values) + + expect(command.name).to eq('ingress') + expect(command.chart).to eq('stable/nginx-ingress') + expect(command.version).to eq('1.1.2') + expect(command.files).to eq(ingress.files) + end + end + + describe '#update_in_progress?' do + context 'when app is updating' do + it 'returns true' do + cluster = create(:cluster) + ingress_app = build(:clusters_applications_ingress, :updating, cluster: cluster) + + expect(ingress_app.update_in_progress?).to be true + end + end + end + + describe '#update_errored?' do + context 'when app errored' do + it 'returns true' do + cluster = create(:cluster) + ingress_app = build(:clusters_applications_ingress, :update_errored, cluster: cluster) + + expect(ingress_app.update_errored?).to be true + end + end + end + describe '#files' do let(:application) { ingress } let(:values) { subject[:'values.yaml'] } @@ -109,4 +149,43 @@ describe Clusters::Applications::Ingress do expect(values).to include('podAnnotations') end end + + describe '#files_with_replaced_values' do + let(:application) { build(:clusters_applications_ingress) } + let(:files) { application.files } + + subject { application.files_with_replaced_values({ hello: :world }) } + + it 'does not modify #files' do + expect(subject[:'values.yaml']).not_to eq(files) + expect(files[:'values.yaml']).to eq(application.values) + end + + it 'returns values.yaml with replaced values' do + expect(subject[:'values.yaml']).to eq({ hello: :world }) + end + + it 'should include cert files' do + expect(subject[:'ca.pem']).to be_present + expect(subject[:'ca.pem']).to eq(application.cluster.application_helm.ca_cert) + + expect(subject[:'cert.pem']).to be_present + expect(subject[:'key.pem']).to be_present + + cert = OpenSSL::X509::Certificate.new(subject[:'cert.pem']) + expect(cert.not_after).to be < 60.minutes.from_now + end + + context 'when the helm application does not have a ca_cert' do + before do + application.cluster.application_helm.ca_cert = nil + end + + it 'should 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 |