diff options
author | Kamil Trzcinski <ayufan@ayufan.eu> | 2017-11-07 17:35:55 +0100 |
---|---|---|
committer | Kamil Trzcinski <ayufan@ayufan.eu> | 2017-11-07 17:35:55 +0100 |
commit | c42786021caed7e10ca3b001be1ae08fc092417a (patch) | |
tree | 499e3fb7da0bf27727c5c45cdad411c68b9bb270 /spec | |
parent | 18760259182050ee92e8e10dc5d46e56ca7f601f (diff) | |
parent | 02878cd958557128cd9c22b27bd2fb97a843266b (diff) | |
download | gitlab-ce-c42786021caed7e10ca3b001be1ae08fc092417a.tar.gz |
Merge remote-tracking branch 'origin/38464-k8s-apps' into add-ingress-to-cluster-applications
Diffstat (limited to 'spec')
-rw-r--r-- | spec/factories/clusters/applications/helm.rb | 2 | ||||
-rw-r--r-- | spec/features/projects/clusters_spec.rb | 42 | ||||
-rw-r--r-- | spec/lib/gitlab/kubernetes/helm_spec.rb | 100 | ||||
-rw-r--r-- | spec/models/clusters/applications/helm_spec.rb | 6 | ||||
-rw-r--r-- | spec/serializers/cluster_application_entity_spec.rb | 2 | ||||
-rw-r--r-- | spec/serializers/cluster_entity_spec.rb | 4 | ||||
-rw-r--r-- | spec/services/clusters/applications/install_service_spec.rb | 4 |
7 files changed, 154 insertions, 6 deletions
diff --git a/spec/factories/clusters/applications/helm.rb b/spec/factories/clusters/applications/helm.rb index a0c874b103b..fab37195113 100644 --- a/spec/factories/clusters/applications/helm.rb +++ b/spec/factories/clusters/applications/helm.rb @@ -3,7 +3,7 @@ FactoryGirl.define do cluster factory: %i(cluster provided_by_gcp) trait :not_installable do - status -2 + status(-2) end trait :installable do diff --git a/spec/features/projects/clusters_spec.rb b/spec/features/projects/clusters_spec.rb index 368aad860e7..03d866f8bc1 100644 --- a/spec/features/projects/clusters_spec.rb +++ b/spec/features/projects/clusters_spec.rb @@ -50,10 +50,22 @@ feature 'Clusters', :js do it 'user sees a cluster details page and creation status' do expect(page).to have_content('Cluster is being created on Google Container Engine...') + # Application Installation buttons + expect(page.find(:css, '.js-cluster-application-install-button')['disabled']).to eq('true') + expect(page.find(:css, '.js-cluster-application-install-button').text).to eq('Install') + Clusters::Cluster.last.provider.make_created! expect(page).to have_content('Cluster was successfully created on Google Container Engine') end + + it 'user sees a error if something worng during creation' do + expect(page).to have_content('Cluster is being created on Google Container Engine...') + + Clusters::Cluster.last.provider.make_errored!('Something wrong!') + + expect(page).to have_content('Something wrong!') + end end context 'when user filled form with invalid parameters' do @@ -78,6 +90,36 @@ feature 'Clusters', :js do it 'user sees an cluster details page' do expect(page).to have_button('Save') expect(page.find(:css, '.cluster-name').value).to eq(cluster.name) + + # Application Installation buttons + expect(page.find(:css, '.js-cluster-application-install-button')['disabled']).to be_nil + expect(page.find(:css, '.js-cluster-application-install-button')).to have_content('Install') + end + + context 'when user installs application: tiller' do + before do + allow(ClusterInstallAppWorker).to receive(:perform_async).and_return(nil) + + page.find(:css, '.js-cluster-application-install-button').click + end + + it 'user sees status transition' do + # FE sends request and gets the responce, then the buttons is "Install" + expect(page.find(:css, '.js-cluster-application-install-button')['disabled']).to eq('true') + expect(page.find(:css, '.js-cluster-application-install-button')).to have_content('Install') + + Clusters::Cluster.last.application_helm.make_installing! + + # FE starts pooling and update the buttons to "Installing" + expect(page.find(:css, '.js-cluster-application-install-button')['disabled']).to eq('true') + expect(page.find(:css, '.js-cluster-application-install-button')).to have_content('Installing') + + Clusters::Cluster.last.application_helm.make_installed! + + expect(page.find(:css, '.js-cluster-application-install-button')['disabled']).to eq('true') + expect(page.find(:css, '.js-cluster-application-install-button')).to have_content('Installed') + expect(page).to have_content('Helm Tiller was successfully installed on your cluster') + end end context 'when user disables the cluster' do diff --git a/spec/lib/gitlab/kubernetes/helm_spec.rb b/spec/lib/gitlab/kubernetes/helm_spec.rb new file mode 100644 index 00000000000..15f99b0401f --- /dev/null +++ b/spec/lib/gitlab/kubernetes/helm_spec.rb @@ -0,0 +1,100 @@ +require 'spec_helper' + +describe Gitlab::Kubernetes::Helm do + let(:client) { double('kubernetes client') } + let(:helm) { described_class.new(client) } + let(:namespace) { Gitlab::Kubernetes::Namespace.new(described_class::NAMESPACE, client) } + let(:install_helm) { true } + let(:chart) { 'stable/a_chart' } + let(:application_name) { 'app_name' } + let(:command) { Gitlab::Kubernetes::Helm::InstallCommand.new(application_name, install_helm, chart) } + subject { helm } + + before do + allow(Gitlab::Kubernetes::Namespace).to receive(:new).with(described_class::NAMESPACE, client).and_return(namespace) + end + + describe '#initialize' do + it 'creates a namespace object' do + expect(Gitlab::Kubernetes::Namespace).to receive(:new).with(described_class::NAMESPACE, client) + + subject + end + end + + describe '#install' do + before do + allow(client).to receive(:create_pod).and_return(nil) + allow(namespace).to receive(:ensure_exists!).once + end + + it 'ensures the namespace exists before creating the POD' do + expect(namespace).to receive(:ensure_exists!).once.ordered + expect(client).to receive(:create_pod).once.ordered + + subject.install(command) + end + end + + describe '#installation_status' do + let(:phase) { Gitlab::Kubernetes::Pod::RUNNING } + let(:pod) { Kubeclient::Resource.new(status: { phase: phase }) } # partial representation + + it 'fetches POD phase from kubernetes cluster' do + expect(client).to receive(:get_pod).with(command.pod_name, described_class::NAMESPACE).once.and_return(pod) + + expect(subject.installation_status(command.pod_name)).to eq(phase) + end + end + + describe '#installation_log' do + let(:log) { 'some output' } + let(:response) { RestClient::Response.new(log) } + + it 'fetches POD phase from kubernetes cluster' do + expect(client).to receive(:get_pod_log).with(command.pod_name, described_class::NAMESPACE).once.and_return(response) + + expect(subject.installation_log(command.pod_name)).to eq(log) + end + end + + describe '#delete_installation_pod!' do + it 'deletes the POD from kubernetes cluster' do + expect(client).to receive(:delete_pod).with(command.pod_name, described_class::NAMESPACE).once + + subject.delete_installation_pod!(command.pod_name) + end + end + + describe '#helm_init_command' do + subject { helm.send(:helm_init_command, command) } + + context 'when command.install_helm is true' do + let(:install_helm) { true } + + it { is_expected.to eq('helm init >/dev/null') } + end + + context 'when command.install_helm is false' do + let(:install_helm) { false } + + it { is_expected.to eq('helm init --client-only >/dev/null') } + end + end + + describe '#helm_install_command' do + subject { helm.send(:helm_install_command, command) } + + context 'when command.chart is nil' do + let(:chart) { nil } + + it { is_expected.to be_nil } + end + + context 'when command.chart is set' do + let(:chart) { 'stable/a_chart' } + + it { is_expected.to eq("helm install #{chart} --name #{application_name} --namespace #{namespace.name} >/dev/null")} + end + end +end diff --git a/spec/models/clusters/applications/helm_spec.rb b/spec/models/clusters/applications/helm_spec.rb index beb10bf38c9..f8855079842 100644 --- a/spec/models/clusters/applications/helm_spec.rb +++ b/spec/models/clusters/applications/helm_spec.rb @@ -38,6 +38,12 @@ describe Clusters::Applications::Helm do end end + describe '#install_command' do + it 'has all the needed information' do + expect(subject.install_command).to have_attributes(name: subject.name, install_helm: true, chart: nil) + end + end + describe 'status state machine' do describe '#make_installing' do subject { create(:cluster_applications_helm, :scheduled) } diff --git a/spec/serializers/cluster_application_entity_spec.rb b/spec/serializers/cluster_application_entity_spec.rb index 8a3a081adf8..87c7b2ad36e 100644 --- a/spec/serializers/cluster_application_entity_spec.rb +++ b/spec/serializers/cluster_application_entity_spec.rb @@ -10,7 +10,7 @@ describe ClusterApplicationEntity do end it 'has status' do - expect(subject[:status]).to eq(:installable) + expect(subject[:status]).to eq(:not_installable) end it 'has no status_reason' do diff --git a/spec/serializers/cluster_entity_spec.rb b/spec/serializers/cluster_entity_spec.rb index f50f5999bfc..d6a43fd0f00 100644 --- a/spec/serializers/cluster_entity_spec.rb +++ b/spec/serializers/cluster_entity_spec.rb @@ -39,12 +39,12 @@ describe ClusterEntity do let(:cluster) { create(:cluster) } subject { described_class.new(cluster).as_json[:applications]} - it 'contains helm as installable' do + it 'contains helm as not_installable' do expect(subject).not_to be_empty helm = subject[0] expect(helm[:name]).to eq('helm') - expect(helm[:status]).to eq(:installable) + expect(helm[:status]).to eq(:not_installable) end end end diff --git a/spec/services/clusters/applications/install_service_spec.rb b/spec/services/clusters/applications/install_service_spec.rb index 408f7e4354e..054a49ffedf 100644 --- a/spec/services/clusters/applications/install_service_spec.rb +++ b/spec/services/clusters/applications/install_service_spec.rb @@ -12,7 +12,7 @@ describe Clusters::Applications::InstallService do context 'when there are no errors' do before do - expect(helm_client).to receive(:install).with(application) + expect(helm_client).to receive(:install).with(application.install_command) allow(ClusterWaitForAppInstallationWorker).to receive(:perform_in).and_return(nil) end @@ -33,7 +33,7 @@ describe Clusters::Applications::InstallService do context 'when k8s cluster communication fails' do before do error = KubeException.new(500, 'system failure', nil) - expect(helm_client).to receive(:install).with(application).and_raise(error) + expect(helm_client).to receive(:install).with(application.install_command).and_raise(error) end it 'make the application errored' do |