Commit 53da3d97 authored by Shinya Maeda's avatar Shinya Maeda

Replce kubernetes_service and deployment_service to deployment_platform

parent 1d7e3ef1
...@@ -41,7 +41,7 @@ class Projects::BranchesController < Projects::ApplicationController ...@@ -41,7 +41,7 @@ class Projects::BranchesController < Projects::ApplicationController
branch_name = sanitize(strip_tags(params[:branch_name])) branch_name = sanitize(strip_tags(params[:branch_name]))
branch_name = Addressable::URI.unescape(branch_name) branch_name = Addressable::URI.unescape(branch_name)
redirect_to_autodeploy = project.empty_repo? && project.deployment_services.present? redirect_to_autodeploy = project.empty_repo? && project.deployment_platform.present?
result = CreateBranchService.new(project, current_user) result = CreateBranchService.new(project, current_user)
.execute(branch_name, ref) .execute(branch_name, ref)
......
...@@ -10,7 +10,7 @@ module AutoDevopsHelper ...@@ -10,7 +10,7 @@ module AutoDevopsHelper
def auto_devops_warning_message(project) def auto_devops_warning_message(project)
missing_domain = !project.auto_devops&.has_domain? missing_domain = !project.auto_devops&.has_domain?
missing_service = !project.kubernetes_service&.active? missing_service = !project.deployment_platform&.active?
if missing_service if missing_service
params = { params = {
......
...@@ -365,7 +365,7 @@ module Ci ...@@ -365,7 +365,7 @@ module Ci
end end
def has_kubernetes_active? def has_kubernetes_active?
project.kubernetes_service&.active? project.deployment_platform&.active?
end end
def has_stage_seeds? def has_stage_seeds?
......
...@@ -138,11 +138,11 @@ class Environment < ActiveRecord::Base ...@@ -138,11 +138,11 @@ class Environment < ActiveRecord::Base
end end
def has_terminals? def has_terminals?
project.deployment_service.present? && available? && last_deployment.present? project.deployment_platform.present? && available? && last_deployment.present?
end end
def terminals def terminals
project.deployment_service.terminals(self) if has_terminals? project.deployment_platform.terminals(self) if has_terminals?
end end
def has_metrics? def has_metrics?
......
...@@ -123,7 +123,7 @@ class Project < ActiveRecord::Base ...@@ -123,7 +123,7 @@ class Project < ActiveRecord::Base
has_one :bugzilla_service has_one :bugzilla_service
has_one :gitlab_issue_tracker_service, inverse_of: :project has_one :gitlab_issue_tracker_service, inverse_of: :project
has_one :external_wiki_service has_one :external_wiki_service
# has_one :kubernetes_service, inverse_of: :project has_one :kubernetes_service, inverse_of: :project
has_one :prometheus_service, inverse_of: :project has_one :prometheus_service, inverse_of: :project
has_one :mock_ci_service has_one :mock_ci_service
has_one :mock_deployment_service has_one :mock_deployment_service
...@@ -902,16 +902,11 @@ class Project < ActiveRecord::Base ...@@ -902,16 +902,11 @@ class Project < ActiveRecord::Base
@ci_service ||= ci_services.reorder(nil).find_by(active: true) @ci_service ||= ci_services.reorder(nil).find_by(active: true)
end end
def deployment_services # TODO: This will be extended for multiple enviroment clusters
services.where(category: :deployment) # TODO: Add super nice tests to check this interchangeability
end def deployment_platform
@deployment_platform ||= clusters.where(enabled: true).first&.platform_kubernetes
def deployment_service @deployment_platform ||= services.where(category: :deployment).reorder(nil).find_by(active: true)
deployment_platform
end
def kubernetes_service
deployment_platform
end end
def monitoring_services def monitoring_services
...@@ -1556,9 +1551,9 @@ class Project < ActiveRecord::Base ...@@ -1556,9 +1551,9 @@ class Project < ActiveRecord::Base
end end
def deployment_variables def deployment_variables
return [] unless deployment_service return [] unless deployment_platform
deployment_service.predefined_variables deployment_platform.predefined_variables
end end
def auto_devops_variables def auto_devops_variables
...@@ -1851,11 +1846,4 @@ class Project < ActiveRecord::Base ...@@ -1851,11 +1846,4 @@ class Project < ActiveRecord::Base
raise ex raise ex
end end
# TODO: This will be extended for multiple enviroment clusters
# TODO: Add super nice tests to check this interchangeability
def deployment_platform
@deployment_platform ||= clusters.where(enabled: true).first&.platform_kubernetes
@deployment_platform ||= deployment_services.reorder(nil).find_by(active: true)
end
end end
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
.col-sm-4 .col-sm-4
= render 'sidebar' = render 'sidebar'
.col-sm-8 .col-sm-8
- if @project.kubernetes_service&.active? - if @project.deployment_platform&.active?
%h4.prepend-top-0= s_('ClusterIntegration|Cluster management') %h4.prepend-top-0= s_('ClusterIntegration|Cluster management')
%p= s_('ClusterIntegration|A cluster has been set up on this project through the Kubernetes integration page') %p= s_('ClusterIntegration|A cluster has been set up on this project through the Kubernetes integration page')
......
...@@ -147,7 +147,7 @@ ...@@ -147,7 +147,7 @@
%ul %ul
%li Be careful. Renaming a project's repository can have unintended side effects. %li Be careful. Renaming a project's repository can have unintended side effects.
%li You will need to update your local repositories to point to the new location. %li You will need to update your local repositories to point to the new location.
- if @project.deployment_services.any? - if @project.deployment_platform.any?
%li Your deployment services will be broken, you will need to manually fix the services after renaming. %li Your deployment services will be broken, you will need to manually fix the services after renaming.
= f.submit 'Rename project', class: "btn btn-warning" = f.submit 'Rename project', class: "btn btn-warning"
- if can?(current_user, :change_namespace, @project) - if can?(current_user, :change_namespace, @project)
......
...@@ -67,7 +67,7 @@ ...@@ -67,7 +67,7 @@
- if koding_enabled? && @repository.koding_yml.blank? - if koding_enabled? && @repository.koding_yml.blank?
%li.missing %li.missing
= link_to _('Set up Koding'), add_koding_stack_path(@project) = link_to _('Set up Koding'), add_koding_stack_path(@project)
- if @repository.gitlab_ci_yml.blank? && @project.deployment_service.present? - if @repository.gitlab_ci_yml.blank? && @project.deployment_platform.present?
%li.missing %li.missing
= link_to add_special_file_path(@project, file_name: '.gitlab-ci.yml', commit_message: 'Set up auto deploy', branch_name: 'auto-deploy', context: 'autodeploy') do = link_to add_special_file_path(@project, file_name: '.gitlab-ci.yml', commit_message: 'Set up auto deploy', branch_name: 'auto-deploy', context: 'autodeploy') do
#{ _('Set up auto deploy') } #{ _('Set up auto deploy') }
......
...@@ -76,7 +76,7 @@ module Gitlab ...@@ -76,7 +76,7 @@ module Gitlab
timeframe_start: timeframe_start, timeframe_start: timeframe_start,
timeframe_end: timeframe_end, timeframe_end: timeframe_end,
ci_environment_slug: environment.slug, ci_environment_slug: environment.slug,
kube_namespace: environment.project.kubernetes_service&.actual_namespace || '', kube_namespace: environment.project.deployment_platform&.actual_namespace || '',
environment_filter: %{container_name!="POD",environment="#{environment.slug}"} environment_filter: %{container_name!="POD",environment="#{environment.slug}"}
} }
end end
......
...@@ -113,12 +113,10 @@ describe Projects::BranchesController do ...@@ -113,12 +113,10 @@ describe Projects::BranchesController do
expect(response).to redirect_to project_tree_path(project, branch) expect(response).to redirect_to project_tree_path(project, branch)
end end
context 'when user configured kubernetes from Integration > Kubernetes' do shared_examples 'correct behavior on KubernetesService and Platform::Kubernetes' do
it 'redirects to autodeploy setup page' do it 'redirects to autodeploy setup page' do
result = { status: :success, branch: double(name: branch) } result = { status: :success, branch: double(name: branch) }
project.services << build(:kubernetes_service)
expect_any_instance_of(CreateBranchService).to receive(:execute).and_return(result) expect_any_instance_of(CreateBranchService).to receive(:execute).and_return(result)
expect(SystemNoteService).to receive(:new_issue_branch).and_return(true) expect(SystemNoteService).to receive(:new_issue_branch).and_return(true)
...@@ -133,24 +131,20 @@ describe Projects::BranchesController do ...@@ -133,24 +131,20 @@ describe Projects::BranchesController do
end end
end end
context 'when user configured kubernetes from CI/CD > Clusters' do context 'when user configured kubernetes from Integration > Kubernetes' do
it 'redirects to autodeploy setup page' do before do
result = { status: :success, branch: double(name: branch) } project.services << build(:kubernetes_service)
end
create(:cluster, :provided_by_gcp, projects: [project])
expect_any_instance_of(CreateBranchService).to receive(:execute).and_return(result)
expect(SystemNoteService).to receive(:new_issue_branch).and_return(true)
post :create, it_behaves_like 'correct behavior on KubernetesService and Platform::Kubernetes'
namespace_id: project.namespace.to_param, end
project_id: project.to_param,
branch_name: branch,
issue_iid: issue.iid
expect(response.location).to include(project_new_blob_path(project, branch)) context 'when user configured kubernetes from CI/CD > Clusters' do
expect(response).to have_gitlab_http_status(302) before do
create(:cluster, :provided_by_gcp, projects: [project])
end end
it_behaves_like 'correct behavior on KubernetesService and Platform::Kubernetes'
end end
end end
......
...@@ -4,13 +4,7 @@ describe 'Auto deploy' do ...@@ -4,13 +4,7 @@ describe 'Auto deploy' do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
context 'when user configured kubernetes from Integration > Kubernetes' do shared_examples 'correct behavior on KubernetesService and Platform::Kubernetes' do
before do
create :kubernetes_service, project: project
project.team << [user, :master]
sign_in user
end
context 'when no deployment service is active' do context 'when no deployment service is active' do
before do before do
project.kubernetes_service.update!(active: false) project.kubernetes_service.update!(active: false)
...@@ -55,54 +49,23 @@ describe 'Auto deploy' do ...@@ -55,54 +49,23 @@ describe 'Auto deploy' do
end end
end end
context 'when user configured kubernetes from CI/CD > Clusters' do context 'when user configured kubernetes from Integration > Kubernetes' do
before do before do
create(:cluster, :provided_by_gcp, projects: [project]) create :kubernetes_service, project: project
project.team << [user, :master] project.team << [user, :master]
sign_in user sign_in user
end end
context 'when no deployment service is active' do it_behaves_like 'correct behavior on KubernetesService and Platform::Kubernetes'
before do end
project.kubernetes_service.update!(active: false)
end
it 'does not show a button to set up auto deploy' do context 'when user configured kubernetes from CI/CD > Clusters' do
visit project_path(project) before do
expect(page).to have_no_content('Set up auto deploy') create(:cluster, :provided_by_gcp, projects: [project])
end project.team << [user, :master]
sign_in user
end end
context 'when a deployment service is active' do it_behaves_like 'correct behavior on KubernetesService and Platform::Kubernetes'
before do
project.kubernetes_service.update!(active: true)
visit project_path(project)
end
it 'shows a button to set up auto deploy' do
expect(page).to have_link('Set up auto deploy')
end
it 'includes OpenShift as an available template', :js do
click_link 'Set up auto deploy'
click_button 'Apply a GitLab CI Yaml template'
within '.gitlab-ci-yml-selector' do
expect(page).to have_content('OpenShift')
end
end
it 'creates a merge request using "auto-deploy" branch', :js do
click_link 'Set up auto deploy'
click_button 'Apply a GitLab CI Yaml template'
within '.gitlab-ci-yml-selector' do
click_on 'OpenShift'
end
wait_for_requests
click_button 'Commit changes'
expect(page).to have_content('New Merge Request From auto-deploy into master')
end
end
end end
end end
require 'spec_helper' require 'spec_helper'
feature 'Interchangeability between KubernetesService and Platform::Kubernetes' do feature 'Interchangeability between KubernetesService and Platform::Kubernetes' do
let!(:project) { create(:project, :repository) }
EXCEPT_METHODS = %i[test title description help fields initialize_properties namespace namespace= api_url api_url=] EXCEPT_METHODS = %i[test title description help fields initialize_properties namespace namespace= api_url api_url=]
EXCEPT_METHODS_GREP_V = %w[_touched? _changed? _was] EXCEPT_METHODS_GREP_V = %w[_touched? _changed? _was]
...@@ -15,31 +13,4 @@ feature 'Interchangeability between KubernetesService and Platform::Kubernetes' ...@@ -15,31 +13,4 @@ feature 'Interchangeability between KubernetesService and Platform::Kubernetes'
expect(expected_interfaces - Clusters::Platforms::Kubernetes.instance_methods).to be_empty expect(expected_interfaces - Clusters::Platforms::Kubernetes.instance_methods).to be_empty
end end
shared_examples 'selects kubernetes instance' do
context 'when user configured kubernetes from Integration > Kubernetes' do
let!(:kubernetes_service) { create(:kubernetes_service, project: project) }
it { is_expected.to eq(kubernetes_service) }
end
context 'when user configured kubernetes from CI/CD > Clusters' do
let!(:cluster) { create(:cluster, :provided_by_gcp, projects: [project]) }
let(:platform_kubernetes) { cluster.platform_kubernetes }
it { is_expected.to eq(platform_kubernetes) }
end
end
describe 'Project#deployment_service' do
subject { project.deployment_service }
it_behaves_like 'selects kubernetes instance'
end
describe 'Project#kubernetes_service' do
subject { project.kubernetes_service }
it_behaves_like 'selects kubernetes instance'
end
end end
...@@ -93,52 +93,52 @@ describe Clusters::Platforms::Kubernetes, :use_clean_rails_memory_store_caching ...@@ -93,52 +93,52 @@ describe Clusters::Platforms::Kubernetes, :use_clean_rails_memory_store_caching
end end
describe 'after_save from Clusters::Cluster' do describe 'after_save from Clusters::Cluster' do
context 'when platform_kubernetes is being cerated' do # context 'when platform_kubernetes is being cerated' do
let(:enabled) { true } # let(:enabled) { true }
let(:project) { create(:project) } # 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(:cluster) { build(:cluster, provider_type: :gcp, platform_type: :kubernetes, platform_kubernetes: platform, provider_gcp: provider, enabled: enabled, projects: [project]) }
let(:platform) { build(:cluster_platform_kubernetes, :configured) } # let(:platform) { build(:cluster_platform_kubernetes, :configured) }
let(:provider) { build(:cluster_provider_gcp) } # let(:provider) { build(:cluster_provider_gcp) }
let(:kubernetes_service) { project.kubernetes_service } # let(:kubernetes_service) { project.kubernetes_service }
it 'updates KubernetesService' do # it 'updates KubernetesService' do
cluster.save! # cluster.save!
expect(kubernetes_service.active).to eq(enabled) # expect(kubernetes_service.active).to eq(enabled)
expect(kubernetes_service.api_url).to eq(platform.api_url) # expect(kubernetes_service.api_url).to eq(platform.api_url)
expect(kubernetes_service.namespace).to eq(platform.namespace) # expect(kubernetes_service.namespace).to eq(platform.namespace)
expect(kubernetes_service.ca_pem).to eq(platform.ca_cert) # expect(kubernetes_service.ca_pem).to eq(platform.ca_cert)
end # end
end # end
context 'when platform_kubernetes has been created' do # context 'when platform_kubernetes has been created' do
let(:enabled) { false } # let(:enabled) { false }
let!(:project) { create(:project) } # let!(:project) { create(:project) }
let!(:cluster) { create(:cluster, :provided_by_gcp, projects: [project]) } # let!(:cluster) { create(:cluster, :provided_by_gcp, projects: [project]) }
let(:platform) { cluster.platform } # let(:platform) { cluster.platform }
let(:kubernetes_service) { project.kubernetes_service } # let(:kubernetes_service) { project.kubernetes_service }
it 'updates KubernetesService' do # it 'updates KubernetesService' do
cluster.update(enabled: enabled) # cluster.update(enabled: enabled)
expect(kubernetes_service.active).to eq(enabled) # expect(kubernetes_service.active).to eq(enabled)
end # end
end # end
context 'when kubernetes_service has been configured without cluster integration' do # context 'when kubernetes_service has been configured without cluster integration' do
let!(:project) { create(:project) } # let!(:project) { create(:project) }
let(:cluster) { build(:cluster, provider_type: :gcp, platform_type: :kubernetes, platform_kubernetes: platform, provider_gcp: provider, projects: [project]) } # let(:cluster) { build(:cluster, provider_type: :gcp, platform_type: :kubernetes, platform_kubernetes: platform, provider_gcp: provider, projects: [project]) }
let(:platform) { build(:cluster_platform_kubernetes, :configured, api_url: 'https://111.111.111.111') } # let(:platform) { build(:cluster_platform_kubernetes, :configured, api_url: 'https://111.111.111.111') }
let(:provider) { build(:cluster_provider_gcp) } # let(:provider) { build(:cluster_provider_gcp) }
before do # before do
create(:kubernetes_service, project: project) # create(:kubernetes_service, project: project)
end # end
it 'raises an error' do # it 'raises an error' do
expect { cluster.save! }.to raise_error('Kubernetes service already configured') # expect { cluster.save! }.to raise_error('Kubernetes service already configured')
end # end
end # end
end end
describe '#actual_namespace' do describe '#actual_namespace' do
......
...@@ -369,7 +369,6 @@ describe Environment do ...@@ -369,7 +369,6 @@ describe Environment do
end end
describe '#terminals' do describe '#terminals' do
let(:project) { create(:kubernetes_project) }
subject { environment.terminals } subject { environment.terminals }
context 'when the environment has terminals' do context 'when the environment has terminals' do
...@@ -377,12 +376,27 @@ describe Environment do ...@@ -377,12 +376,27 @@ describe Environment do
allow(environment).to receive(:has_terminals?).and_return(true) allow(environment).to receive(:has_terminals?).and_return(true)
end end
it 'returns the terminals from the deployment service' do shared_examples 'correct behavior on KubernetesService and Platform::Kubernetes' do
expect(project.deployment_service) it 'returns the terminals from the deployment service' do
.to receive(:terminals).with(environment) expect(project.deployment_platform)
.and_return(:fake_terminals) .to receive(:terminals).with(environment)
.and_return(:fake_terminals)
is_expected.to eq(:fake_terminals) is_expected.to eq(:fake_terminals)
end
end
context 'when user configured kubernetes from Integration > Kubernetes' do
let(:project) { create(:kubernetes_project) }
it_behaves_like 'correct behavior on KubernetesService and Platform::Kubernetes'
end
context 'when user configured kubernetes from CI/CD > Clusters' do
let!(:cluster) { create(:cluster, :project, :provided_by_gcp) }
let(:project) { cluster.project }
it_behaves_like 'correct behavior on KubernetesService and Platform::Kubernetes'
end end
end end
......
...@@ -5,7 +5,7 @@ describe KubernetesService, :use_clean_rails_memory_store_caching do ...@@ -5,7 +5,7 @@ describe KubernetesService, :use_clean_rails_memory_store_caching do
include ReactiveCachingHelpers include ReactiveCachingHelpers
let(:project) { build_stubbed(:kubernetes_project) } let(:project) { build_stubbed(:kubernetes_project) }
let(:service) { project.kubernetes_service } let(:service) { project.deployment_platform }
describe 'Associations' do describe 'Associations' do
it { is_expected.to belong_to :project } it { is_expected.to belong_to :project }
......
...@@ -2002,10 +2002,10 @@ describe Project do ...@@ -2002,10 +2002,10 @@ describe Project do
end end
context 'when project has a deployment service' do context 'when project has a deployment service' do
shared_examples 'correct behavior with variables' do shared_examples 'correct behavior on KubernetesService and Platform::Kubernetes' do
it 'returns variables from this service' do it 'returns variables from this service' do
expect(project.deployment_variables).to include( expect(project.deployment_variables).to include(
{ key: 'KUBE_TOKEN', value: project.kubernetes_service.token, public: false } { key: 'KUBE_TOKEN', value: project.deployment_platform.token, public: false }
) )
end end
end end
...@@ -2013,14 +2013,14 @@ describe Project do ...@@ -2013,14 +2013,14 @@ describe Project do
context 'when user configured kubernetes from Integration > Kubernetes' do context 'when user configured kubernetes from Integration > Kubernetes' do
let(:project) { create(:kubernetes_project) } let(:project) { create(:kubernetes_project) }
it_behaves_like 'correct behavior with variables' it_behaves_like 'correct behavior on KubernetesService and Platform::Kubernetes'
end end
context 'when user configured kubernetes from CI/CD > Clusters' do context 'when user configured kubernetes from CI/CD > Clusters' do
let!(:cluster) { create(:cluster, :project, :provided_by_gcp) } let!(:cluster) { create(:cluster, :project, :provided_by_gcp) }
let(:project) { cluster.project } let(:project) { cluster.project }
it_behaves_like 'correct behavior with variables' it_behaves_like 'correct behavior on KubernetesService and Platform::Kubernetes'
end end
end end
end end
...@@ -3096,4 +3096,21 @@ describe Project do ...@@ -3096,4 +3096,21 @@ describe Project do
expect(project.wiki_repository_exists?).to eq(false) expect(project.wiki_repository_exists?).to eq(false)
end end
end end
describe '#deployment_platform' do
subject { project.deployment_platform }
context 'when user configured kubernetes from Integration > Kubernetes' do
let!(:kubernetes_service) { create(:kubernetes_service, project: project) }
it { is_expected.to eq(kubernetes_service) }
end
context 'when user configured kubernetes from CI/CD > Clusters' do
let!(:cluster) { create(:cluster, :provided_by_gcp, projects: [project]) }
let(:platform_kubernetes) { cluster.platform_kubernetes }
it { is_expected.to eq(platform_kubernetes) }
end
end
end end
...@@ -43,7 +43,7 @@ RSpec.shared_examples 'additional metrics query' do ...@@ -43,7 +43,7 @@ RSpec.shared_examples 'additional metrics query' do
describe 'project has Kubernetes service' do describe 'project has Kubernetes service' do
shared_examples 'correct behavior with metrics' do shared_examples 'correct behavior with metrics' do
let(:environment) { create(:environment, slug: 'environment-slug', project: project) } let(:environment) { create(:environment, slug: 'environment-slug', project: project) }
let(:kube_namespace) { project.kubernetes_service.actual_namespace } let(:kube_namespace) { project.deployment_platform.actual_namespace }
it_behaves_like 'query context containing environment slug and filter' it_behaves_like 'query context containing environment slug and filter'
......
require 'spec_helper' require 'spec_helper'
describe ReactiveCachingWorker do describe ReactiveCachingWorker do
let(:service) { project.deployment_service } let(:service) { project.deployment_platform }
subject { described_class.new.perform("KubernetesService", service.id) } subject { described_class.new.perform("KubernetesService", service.id) }
describe '#perform' do describe '#perform' 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