diff options
author | Grzegorz Bizon <grzegorz@gitlab.com> | 2018-11-07 15:00:38 +0000 |
---|---|---|
committer | Grzegorz Bizon <grzegorz@gitlab.com> | 2018-11-07 15:00:38 +0000 |
commit | 5dc0577b84b9d41b1e2a6e781dfeaa400e8e2c10 (patch) | |
tree | 06954c98466840c21b88de8c929a36086d1310a2 /spec | |
parent | fadaa3d181b26c420a2424d35780cddc9fc32ce0 (diff) | |
parent | c2097ed74cc832972142d24f3cda1faf7a96d550 (diff) | |
download | gitlab-ce-5dc0577b84b9d41b1e2a6e781dfeaa400e8e2c10.tar.gz |
Merge branch 'triggermesh-phase1-knative' into 'master'
Allow to install Knative as cluster application
See merge request gitlab-org/gitlab-ce!22593
Diffstat (limited to 'spec')
15 files changed, 237 insertions, 95 deletions
diff --git a/spec/factories/clusters/applications/helm.rb b/spec/factories/clusters/applications/helm.rb index 3c9ca22a051..ff65c76cf26 100644 --- a/spec/factories/clusters/applications/helm.rb +++ b/spec/factories/clusters/applications/helm.rb @@ -57,6 +57,11 @@ FactoryBot.define do cluster factory: %i(cluster with_installed_helm provided_by_gcp) end + factory :clusters_applications_knative, class: Clusters::Applications::Knative do + hostname 'example.com' + cluster factory: %i(cluster with_installed_helm provided_by_gcp) + end + factory :clusters_applications_jupyter, class: Clusters::Applications::Jupyter do oauth_application factory: :oauth_application cluster factory: %i(cluster with_installed_helm provided_by_gcp project) diff --git a/spec/javascripts/clusters/components/applications_spec.js b/spec/javascripts/clusters/components/applications_spec.js index a70138c7eee..0e2cc13fa52 100644 --- a/spec/javascripts/clusters/components/applications_spec.js +++ b/spec/javascripts/clusters/components/applications_spec.js @@ -23,6 +23,7 @@ describe('Applications', () => { runner: { title: 'GitLab Runner' }, prometheus: { title: 'Prometheus' }, jupyter: { title: 'JupyterHub' }, + knative: { title: 'Knative' }, }, }); }); @@ -46,6 +47,10 @@ describe('Applications', () => { it('renders a row for Jupyter', () => { expect(vm.$el.querySelector('.js-cluster-application-row-jupyter')).not.toBe(null); }); + + it('renders a row for Knative', () => { + expect(vm.$el.querySelector('.js-cluster-application-row-knative')).not.toBe(null); + }); }); describe('Ingress application', () => { @@ -63,6 +68,7 @@ describe('Applications', () => { runner: { title: 'GitLab Runner' }, prometheus: { title: 'Prometheus' }, jupyter: { title: 'JupyterHub', hostname: '' }, + knative: { title: 'Knative', hostname: '' }, }, }); @@ -86,6 +92,7 @@ describe('Applications', () => { runner: { title: 'GitLab Runner' }, prometheus: { title: 'Prometheus' }, jupyter: { title: 'JupyterHub', hostname: '' }, + knative: { title: 'Knative', hostname: '' }, }, }); @@ -105,6 +112,7 @@ describe('Applications', () => { runner: { title: 'GitLab Runner' }, prometheus: { title: 'Prometheus' }, jupyter: { title: 'JupyterHub', hostname: '' }, + knative: { title: 'Knative', hostname: '' }, }, }); @@ -123,6 +131,7 @@ describe('Applications', () => { runner: { title: 'GitLab Runner' }, prometheus: { title: 'Prometheus' }, jupyter: { title: 'JupyterHub', hostname: '', status: 'installable' }, + knative: { title: 'Knative', hostname: '', status: 'installable' }, }, }); @@ -139,6 +148,7 @@ describe('Applications', () => { runner: { title: 'GitLab Runner' }, prometheus: { title: 'Prometheus' }, jupyter: { title: 'JupyterHub', hostname: '', status: 'installable' }, + knative: { title: 'Knative', hostname: '', status: 'installable' }, }, }); @@ -155,6 +165,7 @@ describe('Applications', () => { runner: { title: 'GitLab Runner' }, prometheus: { title: 'Prometheus' }, jupyter: { title: 'JupyterHub', status: 'installed', hostname: '' }, + knative: { title: 'Knative', status: 'installed', hostname: '' }, }, }); @@ -171,6 +182,7 @@ describe('Applications', () => { runner: { title: 'GitLab Runner' }, prometheus: { title: 'Prometheus' }, jupyter: { title: 'JupyterHub', status: 'not_installable' }, + knative: { title: 'Knative' }, }, }); }); diff --git a/spec/javascripts/clusters/services/mock_data.js b/spec/javascripts/clusters/services/mock_data.js index 4e6ad11cd92..73abf6504c0 100644 --- a/spec/javascripts/clusters/services/mock_data.js +++ b/spec/javascripts/clusters/services/mock_data.js @@ -33,6 +33,11 @@ const CLUSTERS_MOCK_DATA = { status: APPLICATION_STATUS.INSTALLING, status_reason: 'Cannot connect', }, + { + name: 'knative', + status: APPLICATION_STATUS.INSTALLING, + status_reason: 'Cannot connect', + }, ], }, }, @@ -67,6 +72,11 @@ const CLUSTERS_MOCK_DATA = { status: APPLICATION_STATUS.INSTALLABLE, status_reason: 'Cannot connect', }, + { + name: 'knative', + status: APPLICATION_STATUS.INSTALLABLE, + status_reason: 'Cannot connect', + }, ], }, }, @@ -77,6 +87,7 @@ const CLUSTERS_MOCK_DATA = { '/gitlab-org/gitlab-shell/clusters/1/applications/runner': {}, '/gitlab-org/gitlab-shell/clusters/1/applications/prometheus': {}, '/gitlab-org/gitlab-shell/clusters/1/applications/jupyter': {}, + '/gitlab-org/gitlab-shell/clusters/1/applications/knative': {}, }, }; diff --git a/spec/javascripts/clusters/stores/clusters_store_spec.js b/spec/javascripts/clusters/stores/clusters_store_spec.js index e0f55a12fca..34ed36afa5b 100644 --- a/spec/javascripts/clusters/stores/clusters_store_spec.js +++ b/spec/javascripts/clusters/stores/clusters_store_spec.js @@ -100,6 +100,14 @@ describe('Clusters Store', () => { requestReason: null, hostname: '', }, + knative: { + title: 'Knative', + status: mockResponseData.applications[5].status, + statusReason: mockResponseData.applications[5].status_reason, + requestStatus: null, + requestReason: null, + hostname: null, + }, }, }); }); diff --git a/spec/lib/gitlab/kubernetes/helm/install_command_spec.rb b/spec/lib/gitlab/kubernetes/helm/install_command_spec.rb index f28941ce58f..ed879350004 100644 --- a/spec/lib/gitlab/kubernetes/helm/install_command_spec.rb +++ b/spec/lib/gitlab/kubernetes/helm/install_command_spec.rb @@ -5,6 +5,8 @@ describe Gitlab::Kubernetes::Helm::InstallCommand do let(:repository) { 'https://repository.example.com' } let(:rbac) { false } let(:version) { '1.2.3' } + let(:preinstall) { nil } + let(:postinstall) { nil } let(:install_command) do described_class.new( @@ -13,7 +15,9 @@ describe Gitlab::Kubernetes::Helm::InstallCommand do rbac: rbac, files: files, version: version, - repository: repository + repository: repository, + preinstall: preinstall, + postinstall: postinstall ) end @@ -24,6 +28,7 @@ describe Gitlab::Kubernetes::Helm::InstallCommand do <<~EOS helm init --client-only >/dev/null helm repo add app-name https://repository.example.com + helm repo update >/dev/null #{helm_install_comand} EOS end @@ -51,6 +56,7 @@ describe Gitlab::Kubernetes::Helm::InstallCommand do <<~EOS helm init --client-only >/dev/null helm repo add app-name https://repository.example.com + helm repo update >/dev/null #{helm_install_command} EOS end @@ -99,6 +105,53 @@ describe Gitlab::Kubernetes::Helm::InstallCommand do end end + context 'when there is a pre-install script' do + let(:preinstall) { ['/bin/date', '/bin/true'] } + + it_behaves_like 'helm commands' do + let(:commands) do + <<~EOS + helm init --client-only >/dev/null + helm repo add app-name https://repository.example.com + helm repo update >/dev/null + #{helm_install_command} + EOS + end + + let(:helm_install_command) do + <<~EOS.strip + /bin/date + /bin/true + helm install chart-name --name app-name --tls --tls-ca-cert /data/helm/app-name/config/ca.pem --tls-cert /data/helm/app-name/config/cert.pem --tls-key /data/helm/app-name/config/key.pem --version 1.2.3 --namespace gitlab-managed-apps -f /data/helm/app-name/config/values.yaml >/dev/null + EOS + end + end + end + + context 'when there is a post-install script' do + let(:postinstall) { ['/bin/date', "/bin/false\n"] } + + it_behaves_like 'helm commands' do + let(:commands) do + <<~EOS + helm init --client-only >/dev/null + helm repo add app-name https://repository.example.com + helm repo update >/dev/null + #{helm_install_command} + EOS + end + + let(:helm_install_command) do + <<~EOS.strip + helm install chart-name --name app-name --tls --tls-ca-cert /data/helm/app-name/config/ca.pem --tls-cert /data/helm/app-name/config/cert.pem --tls-key /data/helm/app-name/config/key.pem --version 1.2.3 --namespace gitlab-managed-apps -f /data/helm/app-name/config/values.yaml >/dev/null + + /bin/date + /bin/false + EOS + end + end + end + context 'when there is no ca.pem file' do let(:files) { { 'file.txt': 'some content' } } @@ -107,6 +160,7 @@ describe Gitlab::Kubernetes::Helm::InstallCommand do <<~EOS helm init --client-only >/dev/null helm repo add app-name https://repository.example.com + helm repo update >/dev/null #{helm_install_command} EOS end @@ -131,6 +185,7 @@ describe Gitlab::Kubernetes::Helm::InstallCommand do <<~EOS helm init --client-only >/dev/null helm repo add app-name https://repository.example.com + helm repo update >/dev/null #{helm_install_command} EOS end diff --git a/spec/lib/gitlab/usage_data_spec.rb b/spec/lib/gitlab/usage_data_spec.rb index 69ee5ff4bcd..76dec4a44fd 100644 --- a/spec/lib/gitlab/usage_data_spec.rb +++ b/spec/lib/gitlab/usage_data_spec.rb @@ -20,6 +20,7 @@ describe Gitlab::UsageData do create(:clusters_applications_ingress, :installed, cluster: gcp_cluster) create(:clusters_applications_prometheus, :installed, cluster: gcp_cluster) create(:clusters_applications_runner, :installed, cluster: gcp_cluster) + create(:clusters_applications_knative, :installed, cluster: gcp_cluster) end subject { described_class.data } @@ -81,6 +82,7 @@ describe Gitlab::UsageData do clusters_applications_ingress clusters_applications_prometheus clusters_applications_runner + clusters_applications_knative in_review_folder groups issues @@ -126,6 +128,7 @@ describe Gitlab::UsageData do expect(count_data[:clusters_applications_ingress]).to eq(1) expect(count_data[:clusters_applications_prometheus]).to eq(1) expect(count_data[:clusters_applications_runner]).to eq(1) + expect(count_data[:clusters_applications_knative]).to eq(1) end it 'works when queries time out' do diff --git a/spec/models/clusters/applications/ingress_spec.rb b/spec/models/clusters/applications/ingress_spec.rb index 1580ef36127..6b0b23eeab3 100644 --- a/spec/models/clusters/applications/ingress_spec.rb +++ b/spec/models/clusters/applications/ingress_spec.rb @@ -5,6 +5,7 @@ describe Clusters::Applications::Ingress do include_examples 'cluster application core specs', :clusters_applications_ingress include_examples 'cluster application status specs', :clusters_applications_ingress + include_examples 'cluster application helm specs', :clusters_applications_knative before do allow(ClusterWaitForIngressIpAddressWorker).to receive(:perform_in) @@ -121,28 +122,5 @@ describe Clusters::Applications::Ingress do expect(values).to include('stats') expect(values).to include('podAnnotations') 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 - - 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 end end diff --git a/spec/models/clusters/applications/jupyter_spec.rb b/spec/models/clusters/applications/jupyter_spec.rb index 9c4396731eb..faaabafddb7 100644 --- a/spec/models/clusters/applications/jupyter_spec.rb +++ b/spec/models/clusters/applications/jupyter_spec.rb @@ -2,6 +2,7 @@ require 'rails_helper' describe Clusters::Applications::Jupyter do include_examples 'cluster application core specs', :clusters_applications_jupyter + include_examples 'cluster application helm specs', :clusters_applications_knative it { is_expected.to belong_to(:oauth_application) } @@ -79,29 +80,6 @@ describe Clusters::Applications::Jupyter do subject { application.files } - 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 - it 'should include valid values' do expect(values).to include('ingress') expect(values).to include('hub') diff --git a/spec/models/clusters/applications/knative_spec.rb b/spec/models/clusters/applications/knative_spec.rb new file mode 100644 index 00000000000..be2a91d566b --- /dev/null +++ b/spec/models/clusters/applications/knative_spec.rb @@ -0,0 +1,77 @@ +require 'rails_helper' + +describe Clusters::Applications::Knative do + let(:knative) { create(:clusters_applications_knative) } + + include_examples 'cluster application core specs', :clusters_applications_knative + include_examples 'cluster application status specs', :clusters_applications_knative + include_examples 'cluster application helm specs', :clusters_applications_knative + + describe '.installed' do + subject { described_class.installed } + + let!(:cluster) { create(:clusters_applications_knative, :installed) } + + before do + create(:clusters_applications_knative, :errored) + end + + it { is_expected.to contain_exactly(cluster) } + end + + describe '#make_installing!' do + before do + application.make_installing! + end + + context 'application install previously errored with older version' do + let(:application) { create(:clusters_applications_knative, :scheduled, version: '0.1.3') } + + it 'updates the application version' do + expect(application.reload.version).to eq('0.1.3') + end + end + end + + describe '#make_installed' do + subject { described_class.installed } + + let!(:cluster) { create(:clusters_applications_knative, :installed) } + + before do + create(:clusters_applications_knative, :errored) + end + + it { is_expected.to contain_exactly(cluster) } + end + + describe '#install_command' do + subject { knative.install_command } + + it 'should be an instance of Helm::InstallCommand' do + expect(subject).to be_an_instance_of(Gitlab::Kubernetes::Helm::InstallCommand) + end + + it 'should be initialized with knative arguments' do + expect(subject.name).to eq('knative') + expect(subject.chart).to eq('knative/knative') + expect(subject.version).to eq('0.1.3') + expect(subject.files).to eq(knative.files) + end + end + + describe '#files' do + let(:application) { knative } + let(:values) { subject[:'values.yaml'] } + + subject { application.files } + + it 'should include knative specific keys in the values.yaml file' do + expect(values).to include('domain') + end + end + + describe 'validations' do + it { is_expected.to validate_presence_of(:hostname) } + end +end diff --git a/spec/models/clusters/applications/prometheus_spec.rb b/spec/models/clusters/applications/prometheus_spec.rb index 48ba163b38c..86de9dc60f2 100644 --- a/spec/models/clusters/applications/prometheus_spec.rb +++ b/spec/models/clusters/applications/prometheus_spec.rb @@ -5,6 +5,7 @@ describe Clusters::Applications::Prometheus do include_examples 'cluster application core specs', :clusters_applications_prometheus include_examples 'cluster application status specs', :clusters_applications_prometheus + include_examples 'cluster application helm specs', :clusters_applications_knative describe '.installed' do subject { described_class.installed } @@ -187,29 +188,6 @@ describe Clusters::Applications::Prometheus do subject { application.files } - 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 - it 'should include prometheus valid values' do expect(values).to include('alertmanager') expect(values).to include('kubeStateMetrics') diff --git a/spec/models/clusters/applications/runner_spec.rb b/spec/models/clusters/applications/runner_spec.rb index d5fb1a9d010..052cfdbc4b1 100644 --- a/spec/models/clusters/applications/runner_spec.rb +++ b/spec/models/clusters/applications/runner_spec.rb @@ -5,6 +5,7 @@ describe Clusters::Applications::Runner do include_examples 'cluster application core specs', :clusters_applications_runner include_examples 'cluster application status specs', :clusters_applications_runner + include_examples 'cluster application helm specs', :clusters_applications_knative it { is_expected.to belong_to(:runner) } @@ -74,29 +75,6 @@ describe Clusters::Applications::Runner do subject { application.files } - 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 - it 'should include runner valid values' do expect(values).to include('concurrent') expect(values).to include('checkInterval') diff --git a/spec/models/clusters/cluster_spec.rb b/spec/models/clusters/cluster_spec.rb index 19b76ca8cfb..10b9ca1a778 100644 --- a/spec/models/clusters/cluster_spec.rb +++ b/spec/models/clusters/cluster_spec.rb @@ -314,9 +314,10 @@ describe Clusters::Cluster do let!(:prometheus) { create(:clusters_applications_prometheus, cluster: cluster) } let!(:runner) { create(:clusters_applications_runner, cluster: cluster) } let!(:jupyter) { create(:clusters_applications_jupyter, cluster: cluster) } + let!(:knative) { create(:clusters_applications_knative, cluster: cluster) } it 'returns a list of created applications' do - is_expected.to contain_exactly(helm, ingress, prometheus, runner, jupyter) + is_expected.to contain_exactly(helm, ingress, prometheus, runner, jupyter, knative) end end end diff --git a/spec/services/clusters/applications/create_service_spec.rb b/spec/services/clusters/applications/create_service_spec.rb index 056db0c5486..a9985133b93 100644 --- a/spec/services/clusters/applications/create_service_spec.rb +++ b/spec/services/clusters/applications/create_service_spec.rb @@ -67,5 +67,38 @@ describe Clusters::Applications::CreateService do expect { subject }.to raise_error(Clusters::Applications::CreateService::InvalidApplicationError) end end + + context 'knative application' do + let(:params) do + { + application: 'knative', + hostname: 'example.com' + } + end + + before do + allow_any_instance_of(Clusters::Applications::ScheduleInstallationService).to receive(:execute) + end + + it 'creates the application' do + expect do + subject + + cluster.reload + end.to change(cluster, :application_knative) + end + + it 'sets the hostname' do + expect(subject.hostname).to eq('example.com') + end + end + + context 'invalid application' do + let(:params) { { application: 'non-existent' } } + + it 'raises an error' do + expect { subject }.to raise_error(Clusters::Applications::CreateService::InvalidApplicationError) + end + 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 7fbb6cf2cf5..efee158739d 100644 --- a/spec/services/clusters/gcp/finalize_creation_service_spec.rb +++ b/spec/services/clusters/gcp/finalize_creation_service_spec.rb @@ -33,7 +33,7 @@ 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)) + 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) diff --git a/spec/support/shared_examples/models/cluster_application_helm_cert_examples.rb b/spec/support/shared_examples/models/cluster_application_helm_cert_examples.rb new file mode 100644 index 00000000000..d87b3181e80 --- /dev/null +++ b/spec/support/shared_examples/models/cluster_application_helm_cert_examples.rb @@ -0,0 +1,25 @@ +shared_examples 'cluster application helm specs' do |application_name| + let(:application) { create(application_name) } + + describe '#files' do + subject { application.files } + + 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 when there is no ca_cert entry' do + expect(subject).not_to include(:'ca.pem', :'cert.pem', :'key.pem') + end + end + + it 'should include 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 |