diff options
author | Eric Eastwood <contact@ericeastwood.com> | 2017-11-06 13:39:54 -0600 |
---|---|---|
committer | Eric Eastwood <contact@ericeastwood.com> | 2017-11-06 13:39:54 -0600 |
commit | 39dd1c66dd349146ae75070b1ea15d3539a4b2a8 (patch) | |
tree | da8a7d53245e21df62aaa12a3d9e570b48b269f1 /spec | |
parent | 6d2a564dc3d0f84c2ac9b15a940a2375363f79b4 (diff) | |
parent | 14fcd394dabefc54bbd57ccf28e407b910f70d9a (diff) | |
download | gitlab-ce-39dd1c66dd349146ae75070b1ea15d3539a4b2a8.tar.gz |
Merge branch '38464-k8s-apps' into add-ingress-to-cluster-applications
Diffstat (limited to 'spec')
30 files changed, 498 insertions, 251 deletions
diff --git a/spec/controllers/projects/clusters/applications_controller_spec.rb b/spec/controllers/projects/clusters/applications_controller_spec.rb index b8464b713c4..3213a797756 100644 --- a/spec/controllers/projects/clusters/applications_controller_spec.rb +++ b/spec/controllers/projects/clusters/applications_controller_spec.rb @@ -49,6 +49,19 @@ describe Projects::Clusters::ApplicationsController do expect(response).to have_http_status(:not_found) end end + + context 'when application is already installing' do + before do + other = current_application.new(cluster: cluster) + other.make_installing! + end + + it 'returns 400' do + go + + expect(response).to have_http_status(:bad_request) + end + end end describe 'security' do diff --git a/spec/controllers/projects/clusters_controller_spec.rb b/spec/controllers/projects/clusters_controller_spec.rb index bfa5b5a91dc..de4cf40b492 100644 --- a/spec/controllers/projects/clusters_controller_spec.rb +++ b/spec/controllers/projects/clusters_controller_spec.rb @@ -200,51 +200,6 @@ describe Projects::ClustersController do expect(response).to redirect_to(project_cluster_path(project, project.cluster)) end end - - # TODO: Activate in 10.3 - # context 'when adds a cluster manually' do - # let(:params) do - # { - # cluster: { - # name: 'new-cluster', - # platform_type: :kubernetes, - # provider_type: :user, - # platform_kubernetes_attributes: { - # namespace: 'custom-namespace', - # api_url: 'https://111.111.111.111', - # token: 'token' - # } - # } - # } - # end - - # it 'creates a new cluster' do - # expect(ClusterProvisionWorker).to receive(:perform_async) - # expect { go }.to change { Clusters::Cluster.count } - # expect(response).to redirect_to(project_cluster_path(project, project.cluster)) - # end - # end - - # TODO: We should fix this in 10.2 - # Maybe - # - validates :provider_gcp, presence: true, if: :gcp? - # - validates :provider_type, presence: true - # are required in Clusters::Cluster - # context 'when not all required parameters are set' do - # let(:params) do - # { - # cluster: { - # name: 'new-cluster' - # } - # } - # end - - # it 'shows an error message' do - # expect { go }.not_to change { Clusters::Cluster.count } - # expect(assigns(:cluster).errors).not_to be_empty - # expect(response).to render_template(:new) - # end - # end end context 'when access token is expired' do @@ -397,42 +352,6 @@ describe Projects::ClustersController do end end end - - # TODO: Activate in 10.3 - # context 'when update namespace' do - # let(:namespace) { 'namespace-123' } - - # let(:params) do - # { - # cluster: { - # platform_kubernetes_attributes: { - # namespace: namespace - # } - # } - # } - # end - - # it "updates and redirects back to show page" do - # go - - # cluster.reload - # expect(response).to redirect_to(project_cluster_path(project, project.cluster)) - # expect(flash[:notice]).to eq('Cluster was successfully updated.') - # expect(cluster.platform.namespace).to eq(namespace) - # end - - # context 'when namespace is invalid' do - # let(:namespace) { 'my Namespace 321321321 #' } - - # it "rejects changes" do - # go - - # expect(response).to have_gitlab_http_status(:ok) - # expect(response).to render_template(:show) - # expect(cluster.platform.namespace).not_to eq(namespace) - # end - # end - # end end describe 'security' do diff --git a/spec/controllers/projects/notes_controller_spec.rb b/spec/controllers/projects/notes_controller_spec.rb index 43afcc14957..5f5a789d5cc 100644 --- a/spec/controllers/projects/notes_controller_spec.rb +++ b/spec/controllers/projects/notes_controller_spec.rb @@ -59,6 +59,7 @@ describe Projects::NotesController do expect(note_json[:id]).to eq(note.id) expect(note_json[:discussion_html]).not_to be_nil expect(note_json[:diff_discussion_html]).to be_nil + expect(note_json[:discussion_line_code]).to be_nil end end @@ -74,6 +75,7 @@ describe Projects::NotesController do expect(note_json[:id]).to eq(note.id) expect(note_json[:discussion_html]).not_to be_nil expect(note_json[:diff_discussion_html]).not_to be_nil + expect(note_json[:discussion_line_code]).not_to be_nil end end @@ -92,6 +94,7 @@ describe Projects::NotesController do expect(note_json[:id]).to eq(note.id) expect(note_json[:discussion_html]).not_to be_nil expect(note_json[:diff_discussion_html]).to be_nil + expect(note_json[:discussion_line_code]).to be_nil end end @@ -104,6 +107,7 @@ describe Projects::NotesController do expect(note_json[:id]).to eq(note.id) expect(note_json[:discussion_html]).to be_nil expect(note_json[:diff_discussion_html]).to be_nil + expect(note_json[:discussion_line_code]).to be_nil end context 'when user cannot read commit' do @@ -133,6 +137,7 @@ describe Projects::NotesController do expect(note_json[:html]).not_to be_nil expect(note_json[:discussion_html]).to be_nil expect(note_json[:diff_discussion_html]).to be_nil + expect(note_json[:discussion_line_code]).to be_nil end end diff --git a/spec/factories/clusters/applications/helm.rb b/spec/factories/clusters/applications/helm.rb index 968a6a1a007..fd956097115 100644 --- a/spec/factories/clusters/applications/helm.rb +++ b/spec/factories/clusters/applications/helm.rb @@ -31,5 +31,10 @@ FactoryGirl.define do status(-1) status_reason 'something went wrong' end + + trait :timeouted do + installing + updated_at ClusterWaitForAppInstallationWorker::TIMEOUT.ago + end end end diff --git a/spec/factories/clusters/cluster.rb b/spec/factories/clusters/cluster.rb index 802981d47a0..c4261178f2d 100644 --- a/spec/factories/clusters/cluster.rb +++ b/spec/factories/clusters/cluster.rb @@ -14,7 +14,7 @@ FactoryGirl.define do platform_type :kubernetes platform_kubernetes do - create(:platform_kubernetes, :configured) + create(:cluster_platform_kubernetes, :configured) end end @@ -23,8 +23,8 @@ FactoryGirl.define do platform_type :kubernetes before(:create) do |cluster, evaluator| - cluster.platform_kubernetes = build(:platform_kubernetes, :configured) - cluster.provider_gcp = build(:provider_gcp, :created) + cluster.platform_kubernetes = build(:cluster_platform_kubernetes, :configured) + cluster.provider_gcp = build(:cluster_provider_gcp, :created) end end @@ -32,7 +32,7 @@ FactoryGirl.define do provider_type :gcp provider_gcp do - create(:provider_gcp, :creating) + create(:cluster_provider_gcp, :creating) end end end diff --git a/spec/factories/clusters/platforms/kubernetes.rb b/spec/factories/clusters/platforms/kubernetes.rb index 5d4e3e5cf5d..8b3e6ff35fa 100644 --- a/spec/factories/clusters/platforms/kubernetes.rb +++ b/spec/factories/clusters/platforms/kubernetes.rb @@ -1,5 +1,5 @@ FactoryGirl.define do - factory :platform_kubernetes, class: Clusters::Platforms::Kubernetes do + factory :cluster_platform_kubernetes, class: Clusters::Platforms::Kubernetes do cluster namespace nil api_url 'https://kubernetes.example.com' diff --git a/spec/factories/clusters/providers/gcp.rb b/spec/factories/clusters/providers/gcp.rb index 13bf50d7b7f..a815410512a 100644 --- a/spec/factories/clusters/providers/gcp.rb +++ b/spec/factories/clusters/providers/gcp.rb @@ -1,5 +1,5 @@ FactoryGirl.define do - factory :provider_gcp, class: Clusters::Providers::Gcp do + factory :cluster_provider_gcp, class: Clusters::Providers::Gcp do cluster gcp_project_id 'test-gcp-project' diff --git a/spec/fixtures/api/schemas/cluster_status.json b/spec/fixtures/api/schemas/cluster_status.json index 451ea50f0f9..489d563be2b 100644 --- a/spec/fixtures/api/schemas/cluster_status.json +++ b/spec/fixtures/api/schemas/cluster_status.json @@ -1,42 +1,38 @@ { "type": "object", "required" : [ - "status" + "status", + "applications" ], "properties" : { "status": { "type": "string" }, "status_reason": { "type": ["string", "null"] }, - "applications": { "$ref": "#/definitions/applications" } + "applications": { + "type": "array", + "items": { "$ref": "#/definitions/application_status" } + } }, "additionalProperties": false, "definitions": { - "applications": { - "type": "object", - "additionalProperties": false, - "properties" : { - "helm": { "$ref": "#/definitions/app_status" }, - "runner": { "$ref": "#/definitions/app_status" }, - "ingress": { "$ref": "#/definitions/app_status" }, - "prometheus": { "$ref": "#/definitions/app_status" } - } - }, - "app_status": { + "application_status": { "type": "object", "additionalProperties": false, "properties" : { + "name": { "type": "string" }, "status": { "type": { "enum": [ "installable", + "scheduled", "installing", "installed", - "error" + "errored" ] } }, "status_reason": { "type": ["string", "null"] } }, - "required" : [ "status" ] + "required" : [ "name", "status" ] } } } diff --git a/spec/javascripts/notes_spec.js b/spec/javascripts/notes_spec.js index 53d8faae911..928a4b461cc 100644 --- a/spec/javascripts/notes_spec.js +++ b/spec/javascripts/notes_spec.js @@ -343,6 +343,7 @@ import '~/notes'; diff_discussion_html: false, }; $form = jasmine.createSpyObj('$form', ['closest', 'find']); + $form.length = 1; row = jasmine.createSpyObj('row', ['prevAll', 'first', 'find']); notes = jasmine.createSpyObj('notes', [ @@ -371,13 +372,29 @@ import '~/notes'; $form.closest.and.returnValues(row, $form); $form.find.and.returnValues(discussionContainer); body.attr.and.returnValue(''); - - Notes.prototype.renderDiscussionNote.call(notes, note, $form); }); it('should call Notes.animateAppendNote', () => { + Notes.prototype.renderDiscussionNote.call(notes, note, $form); + expect(Notes.animateAppendNote).toHaveBeenCalledWith(note.discussion_html, $('.main-notes-list')); }); + + it('should append to row selected with line_code', () => { + $form.length = 0; + note.discussion_line_code = 'line_code'; + note.diff_discussion_html = '<tr></tr>'; + + const line = document.createElement('div'); + line.id = note.discussion_line_code; + document.body.appendChild(line); + + $form.closest.and.returnValues($form); + + Notes.prototype.renderDiscussionNote.call(notes, note, $form); + + expect(line.nextSibling.outerHTML).toEqual(note.diff_discussion_html); + }); }); describe('Discussion sub note', () => { diff --git a/spec/lib/gitlab/ci/cron_parser_spec.rb b/spec/lib/gitlab/ci/cron_parser_spec.rb index 809fda11879..2a3f7807fdb 100644 --- a/spec/lib/gitlab/ci/cron_parser_spec.rb +++ b/spec/lib/gitlab/ci/cron_parser_spec.rb @@ -77,8 +77,20 @@ describe Gitlab::Ci::CronParser do it_behaves_like "returns time in the future" - it 'converts time in server time zone' do - expect(subject.hour).to eq(hour_in_utc) + context 'when PST (Pacific Standard Time)' do + it 'converts time in server time zone' do + Timecop.freeze(Time.utc(2017, 1, 1)) do + expect(subject.hour).to eq(hour_in_utc) + end + end + end + + context 'when PDT (Pacific Daylight Time)' do + it 'converts time in server time zone' do + Timecop.freeze(Time.utc(2017, 6, 1)) do + expect(subject.hour).to eq(hour_in_utc) + end + end end end end @@ -100,8 +112,20 @@ describe Gitlab::Ci::CronParser do it_behaves_like "returns time in the future" - it 'converts time in server time zone' do - expect(subject.hour).to eq(hour_in_utc) + context 'when CET (Central European Time)' do + it 'converts time in server time zone' do + Timecop.freeze(Time.utc(2017, 1, 1)) do + expect(subject.hour).to eq(hour_in_utc) + end + end + end + + context 'when CEST (Central European Summer Time)' do + it 'converts time in server time zone' do + Timecop.freeze(Time.utc(2017, 6, 1)) do + expect(subject.hour).to eq(hour_in_utc) + end + end end end @@ -111,8 +135,20 @@ describe Gitlab::Ci::CronParser do it_behaves_like "returns time in the future" - it 'converts time in server time zone' do - expect(subject.hour).to eq(hour_in_utc) + context 'when EST (Eastern Standard Time)' do + it 'converts time in server time zone' do + Timecop.freeze(Time.utc(2017, 1, 1)) do + expect(subject.hour).to eq(hour_in_utc) + end + end + end + + context 'when EDT (Eastern Daylight Time)' do + it 'converts time in server time zone' do + Timecop.freeze(Time.utc(2017, 6, 1)) do + expect(subject.hour).to eq(hour_in_utc) + end + end end end end diff --git a/spec/lib/gitlab/git/repository_spec.rb b/spec/lib/gitlab/git/repository_spec.rb index bf6d199ebe2..1d4d0c300eb 100644 --- a/spec/lib/gitlab/git/repository_spec.rb +++ b/spec/lib/gitlab/git/repository_spec.rb @@ -559,10 +559,10 @@ describe Gitlab::Git::Repository, seed_helper: true do end end - describe "#remote_delete" do + describe "#remove_remote" do before(:all) do @repo = Gitlab::Git::Repository.new('default', TEST_MUTABLE_REPO_PATH, '') - @repo.remote_delete("expendable") + @repo.remove_remote("expendable") end it "should remove the remote" do @@ -575,14 +575,16 @@ describe Gitlab::Git::Repository, seed_helper: true do end end - describe "#remote_add" do + describe "#remote_update" do before(:all) do @repo = Gitlab::Git::Repository.new('default', TEST_MUTABLE_REPO_PATH, '') - @repo.remote_add("new_remote", SeedHelper::GITLAB_GIT_TEST_REPO_URL) + @repo.remote_update("expendable", url: TEST_NORMAL_REPO_PATH) end it "should add the remote" do - expect(@repo.rugged.remotes.each_name.to_a).to include("new_remote") + expect(@repo.rugged.remotes["expendable"].url).to( + eq(TEST_NORMAL_REPO_PATH) + ) end after(:all) do @@ -591,21 +593,58 @@ describe Gitlab::Git::Repository, seed_helper: true do end end - describe "#remote_update" do - before(:all) do - @repo = Gitlab::Git::Repository.new('default', TEST_MUTABLE_REPO_PATH, '') - @repo.remote_update("expendable", url: TEST_NORMAL_REPO_PATH) + describe '#fetch_mirror' do + let(:new_repository) do + Gitlab::Git::Repository.new('default', 'my_project.git', '') end - it "should add the remote" do - expect(@repo.rugged.remotes["expendable"].url).to( - eq(TEST_NORMAL_REPO_PATH) - ) + subject { new_repository.fetch_mirror(repository.path) } + + before do + Gitlab::Shell.new.add_repository('default', 'my_project') end - after(:all) do - FileUtils.rm_rf(TEST_MUTABLE_REPO_PATH) - ensure_seeds + after do + Gitlab::Shell.new.remove_repository(TestEnv.repos_path, 'my_project') + end + + it 'fetches a url as a mirror remote' do + subject + + expect(refs(new_repository.path)).to eq(refs(repository.path)) + end + + context 'with keep-around refs' do + let(:sha) { SeedRepo::Commit::ID } + let(:keep_around_ref) { "refs/keep-around/#{sha}" } + let(:tmp_ref) { "refs/tmp/#{SecureRandom.hex}" } + + before do + repository.rugged.references.create(keep_around_ref, sha, force: true) + repository.rugged.references.create(tmp_ref, sha, force: true) + end + + it 'includes the temporary and keep-around refs' do + subject + + expect(refs(new_repository.path)).to include(keep_around_ref) + expect(refs(new_repository.path)).to include(tmp_ref) + end + end + end + + describe '#remote_tags' do + let(:target_commit_id) { SeedRepo::Commit::ID } + + subject { repository.remote_tags('upstream') } + + it 'gets the remote tags' do + expect(repository).to receive(:list_remote_tags).with('upstream') + .and_return(["#{target_commit_id}\trefs/tags/v0.0.1\n"]) + + expect(subject.first).to be_an_instance_of(Gitlab::Git::Tag) + expect(subject.first.name).to eq('v0.0.1') + expect(subject.first.dereferenced_target.id).to eq(target_commit_id) end end @@ -1685,6 +1724,21 @@ describe Gitlab::Git::Repository, seed_helper: true do end end + describe '#fetch' do + let(:git_path) { Gitlab.config.git.bin_path } + let(:remote_name) { 'my_remote' } + + subject { repository.fetch(remote_name) } + + it 'fetches the remote and returns true if the command was successful' do + expect(repository).to receive(:popen) + .with(%W(#{git_path} fetch #{remote_name}), repository.path) + .and_return(['', 0]) + + expect(subject).to be(true) + end + end + def create_remote_branch(repository, remote_name, branch_name, source_branch_name) source_branch = repository.branches.find { |branch| branch.name == source_branch_name } rugged = repository.rugged @@ -1760,4 +1814,10 @@ describe Gitlab::Git::Repository, seed_helper: true do sha = Rugged::Commit.create(repo, options) repo.lookup(sha) end + + def refs(dir) + IO.popen(%W[git -C #{dir} for-each-ref], &:read).split("\n").map do |line| + line.split("\t").last + end + end end diff --git a/spec/lib/gitlab/import_export/all_models.yml b/spec/lib/gitlab/import_export/all_models.yml index 96efdd0949b..6eb266a7b94 100644 --- a/spec/lib/gitlab/import_export/all_models.yml +++ b/spec/lib/gitlab/import_export/all_models.yml @@ -147,7 +147,8 @@ deploy_keys: - user - deploy_keys_projects - projects -cluster: +clusters: +- application_helm - cluster_projects - projects - user @@ -160,6 +161,8 @@ provider_gcp: - cluster platform_kubernetes: - cluster +application_helm: +- cluster services: - project - service_hook @@ -191,6 +194,7 @@ project: - tags - chat_services - cluster +- clusters - cluster_project - creator - group @@ -299,4 +303,4 @@ push_event_payload: - event issue_assignees: - issue -- assignee
\ No newline at end of file +- assignee diff --git a/spec/models/clusters/platforms/kubernetes_spec.rb b/spec/models/clusters/platforms/kubernetes_spec.rb index e6ebe079ceb..ed76be703a5 100644 --- a/spec/models/clusters/platforms/kubernetes_spec.rb +++ b/spec/models/clusters/platforms/kubernetes_spec.rb @@ -9,7 +9,7 @@ describe Clusters::Platforms::Kubernetes, :use_clean_rails_memory_store_caching describe 'before_validation' do context 'when namespace includes upper case' do - let(:kubernetes) { create(:platform_kubernetes, :configured, namespace: namespace) } + let(:kubernetes) { create(:cluster_platform_kubernetes, :configured, namespace: namespace) } let(:namespace) { 'ABC' } it 'converts to lower case' do @@ -22,7 +22,7 @@ describe Clusters::Platforms::Kubernetes, :use_clean_rails_memory_store_caching subject { kubernetes.valid? } context 'when validates namespace' do - let(:kubernetes) { build(:platform_kubernetes, :configured, namespace: namespace) } + let(:kubernetes) { build(:cluster_platform_kubernetes, :configured, namespace: namespace) } context 'when namespace is blank' do let(:namespace) { '' } @@ -50,7 +50,7 @@ describe Clusters::Platforms::Kubernetes, :use_clean_rails_memory_store_caching end context 'when validates api_url' do - let(:kubernetes) { build(:platform_kubernetes, :configured) } + let(:kubernetes) { build(:cluster_platform_kubernetes, :configured) } before do kubernetes.api_url = api_url @@ -76,7 +76,7 @@ describe Clusters::Platforms::Kubernetes, :use_clean_rails_memory_store_caching end context 'when validates token' do - let(:kubernetes) { build(:platform_kubernetes, :configured) } + let(:kubernetes) { build(:cluster_platform_kubernetes, :configured) } before do kubernetes.token = token @@ -95,8 +95,8 @@ describe Clusters::Platforms::Kubernetes, :use_clean_rails_memory_store_caching let(:enabled) { true } let(:project) { create(:project) } let(:cluster) { build(:cluster, provider_type: :gcp, platform_type: :kubernetes, platform_kubernetes: platform, provider_gcp: provider, enabled: enabled, projects: [project]) } - let(:platform) { build(:platform_kubernetes, :configured) } - let(:provider) { build(:provider_gcp) } + let(:platform) { build(:cluster_platform_kubernetes, :configured) } + let(:provider) { build(:cluster_provider_gcp) } let(:kubernetes_service) { project.kubernetes_service } it 'updates KubernetesService' do @@ -126,8 +126,8 @@ describe Clusters::Platforms::Kubernetes, :use_clean_rails_memory_store_caching context 'when kubernetes_service has been configured without cluster integration' do let!(:project) { create(:project) } let(:cluster) { build(:cluster, provider_type: :gcp, platform_type: :kubernetes, platform_kubernetes: platform, provider_gcp: provider, projects: [project]) } - let(:platform) { build(:platform_kubernetes, :configured, api_url: 'https://111.111.111.111') } - let(:provider) { build(:provider_gcp) } + let(:platform) { build(:cluster_platform_kubernetes, :configured, api_url: 'https://111.111.111.111') } + let(:provider) { build(:cluster_provider_gcp) } before do create(:kubernetes_service, project: project) @@ -144,7 +144,7 @@ describe Clusters::Platforms::Kubernetes, :use_clean_rails_memory_store_caching let!(:cluster) { create(:cluster, :project, platform_kubernetes: kubernetes) } let(:project) { cluster.project } - let(:kubernetes) { create(:platform_kubernetes, :configured, namespace: namespace) } + let(:kubernetes) { create(:cluster_platform_kubernetes, :configured, namespace: namespace) } context 'when namespace is present' do let(:namespace) { 'namespace-123' } @@ -170,7 +170,7 @@ describe Clusters::Platforms::Kubernetes, :use_clean_rails_memory_store_caching describe '#default_namespace' do subject { kubernetes.default_namespace } - let(:kubernetes) { create(:platform_kubernetes, :configured) } + let(:kubernetes) { create(:cluster_platform_kubernetes, :configured) } context 'when cluster belongs to a project' do let!(:cluster) { create(:cluster, :project, platform_kubernetes: kubernetes) } diff --git a/spec/models/clusters/providers/gcp_spec.rb b/spec/models/clusters/providers/gcp_spec.rb index 99eb8c46e9a..ecd0a08c953 100644 --- a/spec/models/clusters/providers/gcp_spec.rb +++ b/spec/models/clusters/providers/gcp_spec.rb @@ -5,7 +5,7 @@ describe Clusters::Providers::Gcp do it { is_expected.to validate_presence_of(:zone) } describe 'default_value_for' do - let(:gcp) { build(:provider_gcp) } + let(:gcp) { build(:cluster_provider_gcp) } it "has default value" do expect(gcp.zone).to eq('us-central1-a') @@ -18,7 +18,7 @@ describe Clusters::Providers::Gcp do subject { gcp.valid? } context 'when validates gcp_project_id' do - let(:gcp) { build(:provider_gcp, gcp_project_id: gcp_project_id) } + let(:gcp) { build(:cluster_provider_gcp, gcp_project_id: gcp_project_id) } context 'when gcp_project_id is shorter than 1' do let(:gcp_project_id) { '' } @@ -46,7 +46,7 @@ describe Clusters::Providers::Gcp do end context 'when validates num_nodes' do - let(:gcp) { build(:provider_gcp, num_nodes: num_nodes) } + let(:gcp) { build(:cluster_provider_gcp, num_nodes: num_nodes) } context 'when num_nodes is string' do let(:num_nodes) { 'A3' } @@ -76,7 +76,7 @@ describe Clusters::Providers::Gcp do describe '#state_machine' do context 'when any => [:created]' do - let(:gcp) { build(:provider_gcp, :creating) } + let(:gcp) { build(:cluster_provider_gcp, :creating) } before do gcp.make_created @@ -90,7 +90,7 @@ describe Clusters::Providers::Gcp do end context 'when any => [:creating]' do - let(:gcp) { build(:provider_gcp) } + let(:gcp) { build(:cluster_provider_gcp) } context 'when operation_id is present' do let(:operation_id) { 'operation-xxx' } @@ -116,7 +116,7 @@ describe Clusters::Providers::Gcp do end context 'when any => [:errored]' do - let(:gcp) { build(:provider_gcp, :creating) } + let(:gcp) { build(:cluster_provider_gcp, :creating) } let(:status_reason) { 'err msg' } it 'nullify access_token and operation_id' do @@ -129,7 +129,7 @@ describe Clusters::Providers::Gcp do end context 'when status_reason is nil' do - let(:gcp) { build(:provider_gcp, :errored) } + let(:gcp) { build(:cluster_provider_gcp, :errored) } it 'does not set status_reason' do gcp.make_errored(nil) @@ -144,13 +144,13 @@ describe Clusters::Providers::Gcp do subject { gcp.on_creation? } context 'when status is creating' do - let(:gcp) { create(:provider_gcp, :creating) } + let(:gcp) { create(:cluster_provider_gcp, :creating) } it { is_expected.to be_truthy } end context 'when status is created' do - let(:gcp) { create(:provider_gcp, :created) } + let(:gcp) { create(:cluster_provider_gcp, :created) } it { is_expected.to be_falsey } end @@ -160,7 +160,7 @@ describe Clusters::Providers::Gcp do subject { gcp.api_client } context 'when status is creating' do - let(:gcp) { build(:provider_gcp, :creating) } + let(:gcp) { build(:cluster_provider_gcp, :creating) } it 'returns Cloud Platform API clinet' do expect(subject).to be_an_instance_of(GoogleApi::CloudPlatform::Client) @@ -169,13 +169,13 @@ describe Clusters::Providers::Gcp do end context 'when status is created' do - let(:gcp) { build(:provider_gcp, :created) } + let(:gcp) { build(:cluster_provider_gcp, :created) } it { is_expected.to be_nil } end context 'when status is errored' do - let(:gcp) { build(:provider_gcp, :errored) } + let(:gcp) { build(:cluster_provider_gcp, :errored) } it { is_expected.to be_nil } end diff --git a/spec/models/environment_spec.rb b/spec/models/environment_spec.rb index f75de0a0d88..1ce1d595c60 100644 --- a/spec/models/environment_spec.rb +++ b/spec/models/environment_spec.rb @@ -18,7 +18,6 @@ describe Environment do it { is_expected.to validate_length_of(:slug).is_at_most(24) } it { is_expected.to validate_length_of(:external_url).is_at_most(255) } - it { is_expected.to validate_uniqueness_of(:external_url).scoped_to(:project_id) } describe '.order_by_last_deployed_at' do let(:project) { create(:project, :repository) } diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index d7c07676911..8a6aa767ce6 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -2298,4 +2298,24 @@ describe Repository do project.commit_by(oid: '1' * 40) end end + + describe '#raw_repository' do + subject { repository.raw_repository } + + it 'returns a Gitlab::Git::Repository representation of the repository' do + expect(subject).to be_a(Gitlab::Git::Repository) + expect(subject.relative_path).to eq(project.disk_path + '.git') + expect(subject.gl_repository).to eq("project-#{project.id}") + end + + context 'with a wiki repository' do + let(:repository) { project.wiki.repository } + + it 'creates a Gitlab::Git::Repository with the proper attributes' do + expect(subject).to be_a(Gitlab::Git::Repository) + expect(subject.relative_path).to eq(project.disk_path + '.wiki.git') + expect(subject.gl_repository).to eq("wiki-#{project.id}") + end + end + end end diff --git a/spec/serializers/cluster_application_entity_spec.rb b/spec/serializers/cluster_application_entity_spec.rb new file mode 100644 index 00000000000..61cebcefa28 --- /dev/null +++ b/spec/serializers/cluster_application_entity_spec.rb @@ -0,0 +1,30 @@ +require 'spec_helper' + +describe ClusterApplicationEntity do + describe '#as_json' do + let(:application) { build(:applications_helm) } + subject { described_class.new(application).as_json } + + it 'has name' do + expect(subject[:name]).to eq(application.name) + end + + it 'has status' do + expect(subject[:status]).to eq(:installable) + end + + it 'has no status_reason' do + expect(subject[:status_reason]).to be_nil + end + + context 'when application is errored' do + let(:application) { build(:applications_helm, :errored) } + + it 'has corresponded data' do + expect(subject[:status]).to eq(:errored) + expect(subject[:status_reason]).not_to be_nil + expect(subject[:status_reason]).to eq(application.status_reason) + end + end + end +end diff --git a/spec/serializers/cluster_entity_spec.rb b/spec/serializers/cluster_entity_spec.rb index abfc3731fb2..67977e30264 100644 --- a/spec/serializers/cluster_entity_spec.rb +++ b/spec/serializers/cluster_entity_spec.rb @@ -8,7 +8,7 @@ describe ClusterEntity do let(:cluster) { create(:cluster, provider_type: :gcp, provider_gcp: provider) } context 'when status is creating' do - let(:provider) { create(:provider_gcp, :creating) } + let(:provider) { create(:cluster_provider_gcp, :creating) } it 'has corresponded data' do expect(subject[:status]).to eq(:creating) @@ -17,7 +17,7 @@ describe ClusterEntity do end context 'when status is errored' do - let(:provider) { create(:provider_gcp, :errored) } + let(:provider) { create(:cluster_provider_gcp, :errored) } it 'has corresponded data' do expect(subject[:status]).to eq(:errored) @@ -35,8 +35,17 @@ describe ClusterEntity do end end - it 'contains applications' do - expect(subject[:applications]).to eq({}) + context 'when no application has been installed' do + let(:cluster) { create(:cluster) } + subject { described_class.new(cluster).as_json[:applications]} + + it 'contains helm as installable' do + expect(subject).not_to be_empty + + helm = subject[0] + expect(helm[:name]).to eq('helm') + expect(helm[:status]).to eq(:installable) + end end end end diff --git a/spec/serializers/cluster_serializer_spec.rb b/spec/serializers/cluster_serializer_spec.rb index 04d8728303c..5e9f7a45891 100644 --- a/spec/serializers/cluster_serializer_spec.rb +++ b/spec/serializers/cluster_serializer_spec.rb @@ -6,10 +6,10 @@ describe ClusterSerializer do context 'when provider type is gcp' do let(:cluster) { create(:cluster, provider_type: :gcp, provider_gcp: provider) } - let(:provider) { create(:provider_gcp, :errored) } + let(:provider) { create(:cluster_provider_gcp, :errored) } it 'serializes only status' do - expect(subject.keys).to contain_exactly(:status, :status_reason) + expect(subject.keys).to contain_exactly(:status, :status_reason, :applications) end end diff --git a/spec/services/clusters/applications/check_installation_progress_service_spec.rb b/spec/services/clusters/applications/check_installation_progress_service_spec.rb new file mode 100644 index 00000000000..fe04fac9613 --- /dev/null +++ b/spec/services/clusters/applications/check_installation_progress_service_spec.rb @@ -0,0 +1,82 @@ +require 'spec_helper' + +describe Clusters::Applications::CheckInstallationProgressService do + RESCHEDULE_PHASES = Gitlab::Kubernetes::Pod::PHASES - [Gitlab::Kubernetes::Pod::SUCCEEDED, Gitlab::Kubernetes::Pod::FAILED].freeze + + let(:application) { create(:applications_helm, :installing) } + let(:service) { described_class.new(application) } + let(:phase) { Gitlab::Kubernetes::Pod::UNKNOWN } + let(:errors) { nil } + + shared_examples 'a terminated installation' do + it 'finalize the installation' do + expect(service).to receive(:finalize_installation).once + + service.execute + end + end + + shared_examples 'a not yet terminated installation' do |a_phase| + let(:phase) { a_phase } + + context "when phase is #{a_phase}" do + context 'when not timeouted' do + it 'reschedule a new check' do + expect(ClusterWaitForAppInstallationWorker).to receive(:perform_in).once + expect(service).not_to receive(:finalize_installation) + + service.execute + + expect(application).to be_installing + expect(application.status_reason).to be_nil + end + end + + context 'when timeouted' do + let(:application) { create(:applications_helm, :timeouted) } + + it_behaves_like 'a terminated installation' + + it 'make the application errored' do + expect(ClusterWaitForAppInstallationWorker).not_to receive(:perform_in) + + service.execute + + expect(application).to be_errored + expect(application.status_reason).to match(/\btimeouted\b/) + end + end + end + end + + before do + expect(service).to receive(:installation_phase).once.and_return(phase) + + allow(service).to receive(:installation_errors).and_return(errors) + allow(service).to receive(:finalize_installation).and_return(nil) + end + + describe '#execute' do + context 'when installation POD succeeded' do + let(:phase) { Gitlab::Kubernetes::Pod::SUCCEEDED } + + it_behaves_like 'a terminated installation' + end + + context 'when installation POD failed' do + let(:phase) { Gitlab::Kubernetes::Pod::FAILED } + let(:errors) { 'test installation failed' } + + it_behaves_like 'a terminated installation' + + it 'make the application errored' do + service.execute + + expect(application).to be_errored + expect(application.status_reason).to eq(errors) + end + end + + RESCHEDULE_PHASES.each { |phase| it_behaves_like 'a not yet terminated installation', phase } + end +end diff --git a/spec/services/clusters/applications/finalize_installation_service_spec.rb b/spec/services/clusters/applications/finalize_installation_service_spec.rb new file mode 100644 index 00000000000..08b7a80dfcd --- /dev/null +++ b/spec/services/clusters/applications/finalize_installation_service_spec.rb @@ -0,0 +1,32 @@ +require 'spec_helper' + +describe Clusters::Applications::FinalizeInstallationService do + describe '#execute' do + let(:application) { create(:applications_helm, :installing) } + let(:service) { described_class.new(application) } + + before do + expect_any_instance_of(Gitlab::Kubernetes::Helm).to receive(:delete_installation_pod!).with(application) + end + + context 'when installation POD succeeded' do + it 'make the application installed' do + service.execute + + expect(application).to be_installed + expect(application.status_reason).to be_nil + end + end + + context 'when installation POD failed' do + let(:application) { create(:applications_helm, :errored) } + + it 'make the application errored' do + service.execute + + expect(application).to be_errored + expect(application.status_reason).not_to be_nil + end + end + end +end diff --git a/spec/services/clusters/applications/install_service_spec.rb b/spec/services/clusters/applications/install_service_spec.rb new file mode 100644 index 00000000000..a646dac1cae --- /dev/null +++ b/spec/services/clusters/applications/install_service_spec.rb @@ -0,0 +1,54 @@ +require 'spec_helper' + +describe Clusters::Applications::InstallService do + describe '#execute' do + let(:application) { create(:applications_helm, :scheduled) } + let(:service) { described_class.new(application) } + + context 'when there are no errors' do + before do + expect_any_instance_of(Gitlab::Kubernetes::Helm).to receive(:install).with(application) + allow(ClusterWaitForAppInstallationWorker).to receive(:perform_in).and_return(nil) + end + + it 'make the application installing' do + service.execute + + expect(application).to be_installing + end + + it 'schedule async installation status check' do + expect(ClusterWaitForAppInstallationWorker).to receive(:perform_in).once + + service.execute + end + end + + context 'when k8s cluster communication fails' do + before do + error = KubeException.new(500, 'system failure', nil) + expect_any_instance_of(Gitlab::Kubernetes::Helm).to receive(:install).with(application).and_raise(error) + end + + it 'make the application errored' do + service.execute + + expect(application).to be_errored + expect(application.status_reason).to match(/kubernetes error:/i) + end + end + + context 'when application cannot be persisted' do + let(:application) { build(:applications_helm, :scheduled) } + + it 'make the application errored' do + expect(application).to receive(:make_installing!).once.and_raise(ActiveRecord::RecordInvalid) + expect_any_instance_of(Gitlab::Kubernetes::Helm).not_to receive(:install) + + service.execute + + expect(application).to be_errored + end + end + end +end diff --git a/spec/services/clusters/applications/schedule_installation_service_spec.rb b/spec/services/clusters/applications/schedule_installation_service_spec.rb new file mode 100644 index 00000000000..6ba587a41db --- /dev/null +++ b/spec/services/clusters/applications/schedule_installation_service_spec.rb @@ -0,0 +1,55 @@ +require 'spec_helper' + +describe Clusters::Applications::ScheduleInstallationService do + def count_scheduled + application_class&.with_status(:scheduled)&.count || 0 + end + + shared_examples 'a failing service' do + it 'raise an exception' do + expect(ClusterInstallAppWorker).not_to receive(:perform_async) + count_before = count_scheduled + + expect { service.execute }.to raise_error(StandardError) + expect(count_scheduled).to eq(count_before) + end + end + + describe '#execute' do + let(:application_class) { Clusters::Applications::Helm } + let(:cluster) { create(:cluster, :project, :provided_by_gcp) } + let(:project) { cluster.project } + let(:service) { described_class.new(project, nil, cluster: cluster, application_class: application_class) } + + it 'creates a new application' do + expect { service.execute }.to change { application_class.count }.by(1) + end + + it 'make the application scheduled' do + expect(ClusterInstallAppWorker).to receive(:perform_async).with(application_class.application_name, kind_of(Numeric)).once + + expect { service.execute }.to change { application_class.with_status(:scheduled).count }.by(1) + end + + context 'when installation is already in progress' do + let(:application) { create(:applications_helm, :installing) } + let(:cluster) { application.cluster } + + it_behaves_like 'a failing service' + end + + context 'when application_class is nil' do + let(:application_class) { nil } + + it_behaves_like 'a failing service' + end + + context 'when application cannot be persisted' do + before do + expect_any_instance_of(application_class).to receive(:make_scheduled!).once.and_raise(ActiveRecord::RecordInvalid) + end + + it_behaves_like 'a failing service' + end + end +end diff --git a/spec/services/clusters/create_service_spec.rb b/spec/services/clusters/create_service_spec.rb index 9c2c288a2fa..5b6edb73beb 100644 --- a/spec/services/clusters/create_service_spec.rb +++ b/spec/services/clusters/create_service_spec.rb @@ -61,57 +61,4 @@ describe Clusters::CreateService do end end end - - # TODO: This will be active in 10.3 - # context 'when provider is user' do - # context 'when correct params' do - # let(:params) do - # { - # name: 'test-cluster', - # platform_type: :kubernetes, - # provider_type: :user, - # platform_kubernetes_attributes: { - # namespace: 'custom-namespace', - # api_url: 'https://111.111.111.111', - # token: 'token' - # } - # } - # end - - # it 'creates a cluster object and performs a worker' do - # expect(ClusterProvisionWorker).to receive(:perform_async) - - # expect { result } - # .to change { Clusters::Cluster.count }.by(1) - # .and change { Clusters::Platforms::Kubernetes.count }.by(1) - - # expect(result.name).to eq('test-cluster') - # expect(result.user).to eq(user) - # expect(result.project).to eq(project) - # expect(result.provider).to be_nil - # expect(result.platform.namespace).to eq('custom-namespace') - # end - # end - - # context 'when invalid params' do - # let(:params) do - # { - # name: 'test-cluster', - # platform_type: :kubernetes, - # provider_type: :user, - # platform_kubernetes_attributes: { - # namespace: 'custom-namespace', - # api_url: '!!!!!', - # token: 'token' - # } - # } - # end - - # it 'returns an error' do - # # expect(ClusterProvisionWorker).not_to receive(:perform_async) - # expect { result }.to change { Clusters::Cluster.count }.by(0) - # expect(result.errors[:"platform_kubernetes.api_url"]).to be_present - # end - # end - # end end diff --git a/spec/services/clusters/gcp/fetch_operation_service_spec.rb b/spec/services/clusters/gcp/fetch_operation_service_spec.rb index 20d46608033..e2fa93904c5 100644 --- a/spec/services/clusters/gcp/fetch_operation_service_spec.rb +++ b/spec/services/clusters/gcp/fetch_operation_service_spec.rb @@ -4,7 +4,7 @@ describe Clusters::Gcp::FetchOperationService do include GoogleApi::CloudPlatformHelpers describe '#execute' do - let(:provider) { create(:provider_gcp, :creating) } + let(:provider) { create(:cluster_provider_gcp, :creating) } let(:gcp_project_id) { provider.gcp_project_id } let(:zone) { provider.zone } let(:operation_id) { provider.operation_id } diff --git a/spec/services/clusters/gcp/provision_service_spec.rb b/spec/services/clusters/gcp/provision_service_spec.rb index f5f9d4800fd..f48afdc83b2 100644 --- a/spec/services/clusters/gcp/provision_service_spec.rb +++ b/spec/services/clusters/gcp/provision_service_spec.rb @@ -4,7 +4,7 @@ describe Clusters::Gcp::ProvisionService do include GoogleApi::CloudPlatformHelpers describe '#execute' do - let(:provider) { create(:provider_gcp, :scheduled) } + let(:provider) { create(:cluster_provider_gcp, :scheduled) } let(:gcp_project_id) { provider.gcp_project_id } let(:zone) { provider.zone } diff --git a/spec/services/clusters/gcp/verify_provision_status_service_spec.rb b/spec/services/clusters/gcp/verify_provision_status_service_spec.rb index 666fcf13cac..2ee2fa51f63 100644 --- a/spec/services/clusters/gcp/verify_provision_status_service_spec.rb +++ b/spec/services/clusters/gcp/verify_provision_status_service_spec.rb @@ -4,7 +4,7 @@ describe Clusters::Gcp::VerifyProvisionStatusService do include GoogleApi::CloudPlatformHelpers describe '#execute' do - let(:provider) { create(:provider_gcp, :creating) } + let(:provider) { create(:cluster_provider_gcp, :creating) } let(:gcp_project_id) { provider.gcp_project_id } let(:zone) { provider.zone } let(:operation_id) { provider.operation_id } diff --git a/spec/support/google_api/cloud_platform_helpers.rb b/spec/support/google_api/cloud_platform_helpers.rb index 4b785611ab5..dabf0db7666 100644 --- a/spec/support/google_api/cloud_platform_helpers.rb +++ b/spec/support/google_api/cloud_platform_helpers.rb @@ -71,15 +71,9 @@ module GoogleApi "name": options[:name] || 'string', "description": options[:description] || 'string', "initialNodeCount": options[:initialNodeCount] || 'number', - # "nodeConfig": {, - # object(NodeConfig), - # },, "masterAuth": { "username": options[:username] || 'string', "password": options[:password] || 'string', - # "clientCertificateConfig": { - # object(ClientCertificateConfig) - # }, "clusterCaCertificate": options[:clusterCaCertificate] || load_sample_cert, "clientCertificate": options[:clientCertificate] || 'string', "clientKey": options[:clientKey] || 'string' @@ -88,36 +82,9 @@ module GoogleApi "monitoringService": options[:monitoringService] || 'string', "network": options[:network] || 'string', "clusterIpv4Cidr": options[:clusterIpv4Cidr] || 'string', - # "addonsConfig": {, - # object(AddonsConfig), - # },, "subnetwork": options[:subnetwork] || 'string', - # "nodePools": [, - # {, - # object(NodePool), - # }, - # ],, - # "locations": [, - # string, - # ],, "enableKubernetesAlpha": options[:enableKubernetesAlpha] || 'boolean', - # "resourceLabels": {, - # string: string,, - # ..., - # },, "labelFingerprint": options[:labelFingerprint] || 'string', - # "legacyAbac": {, - # object(LegacyAbac), - # }, - # "networkPolicy": {, - # object(NetworkPolicy), - # }, - # "ipAllocationPolicy": {, - # object(IPAllocationPolicy), - # }, - # "masterAuthorizedNetworksConfig": {, - # object(MasterAuthorizedNetworksConfig), - # }, "selfLink": options[:selfLink] || 'string', "zone": options[:zone] || 'string', "endpoint": options[:endpoint] || 'string', @@ -129,9 +96,6 @@ module GoogleApi "statusMessage": options[:statusMessage] || 'string', "nodeIpv4CidrSize": options[:nodeIpv4CidrSize] || 'number', "servicesIpv4Cidr": options[:servicesIpv4Cidr] || 'string', - # "instanceGroupUrls": [, - # string, - # ],, "currentNodeCount": options[:currentNodeCount] || 'number', "expireTime": options[:expireTime] || 'string' } diff --git a/spec/workers/cluster_provision_worker_spec.rb b/spec/workers/cluster_provision_worker_spec.rb index 85c7dc20ede..8054ec11a48 100644 --- a/spec/workers/cluster_provision_worker_spec.rb +++ b/spec/workers/cluster_provision_worker_spec.rb @@ -4,7 +4,7 @@ describe ClusterProvisionWorker do describe '#perform' do context 'when provider type is gcp' do let(:cluster) { create(:cluster, provider_type: :gcp, provider_gcp: provider) } - let(:provider) { create(:provider_gcp, :scheduled) } + let(:provider) { create(:cluster_provider_gcp, :scheduled) } it 'provision a cluster' do expect_any_instance_of(Clusters::Gcp::ProvisionService).to receive(:execute) diff --git a/spec/workers/wait_for_cluster_creation_worker_spec.rb b/spec/workers/wait_for_cluster_creation_worker_spec.rb index 29812408396..0e92b298178 100644 --- a/spec/workers/wait_for_cluster_creation_worker_spec.rb +++ b/spec/workers/wait_for_cluster_creation_worker_spec.rb @@ -4,7 +4,7 @@ describe WaitForClusterCreationWorker do describe '#perform' do context 'when provider type is gcp' do let(:cluster) { create(:cluster, provider_type: :gcp, provider_gcp: provider) } - let(:provider) { create(:provider_gcp, :creating) } + let(:provider) { create(:cluster_provider_gcp, :creating) } it 'provision a cluster' do expect_any_instance_of(Clusters::Gcp::VerifyProvisionStatusService).to receive(:execute) |