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
branch_name = sanitize(strip_tags(params[: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)
.execute(branch_name, ref)
......
......@@ -10,7 +10,7 @@ module AutoDevopsHelper
def auto_devops_warning_message(project)
missing_domain = !project.auto_devops&.has_domain?
missing_service = !project.kubernetes_service&.active?
missing_service = !project.deployment_platform&.active?
if missing_service
params = {
......
......@@ -365,7 +365,7 @@ module Ci
end
def has_kubernetes_active?
project.kubernetes_service&.active?
project.deployment_platform&.active?
end
def has_stage_seeds?
......
......@@ -138,11 +138,11 @@ class Environment < ActiveRecord::Base
end
def has_terminals?
project.deployment_service.present? && available? && last_deployment.present?
project.deployment_platform.present? && available? && last_deployment.present?
end
def terminals
project.deployment_service.terminals(self) if has_terminals?
project.deployment_platform.terminals(self) if has_terminals?
end
def has_metrics?
......
......@@ -123,7 +123,7 @@ class Project < ActiveRecord::Base
has_one :bugzilla_service
has_one :gitlab_issue_tracker_service, inverse_of: :project
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 :mock_ci_service
has_one :mock_deployment_service
......@@ -902,16 +902,11 @@ class Project < ActiveRecord::Base
@ci_service ||= ci_services.reorder(nil).find_by(active: true)
end
def deployment_services
services.where(category: :deployment)
end
def deployment_service
deployment_platform
end
def kubernetes_service
deployment_platform
# 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 ||= services.where(category: :deployment).reorder(nil).find_by(active: true)
end
def monitoring_services
......@@ -1556,9 +1551,9 @@ class Project < ActiveRecord::Base
end
def deployment_variables
return [] unless deployment_service
return [] unless deployment_platform
deployment_service.predefined_variables
deployment_platform.predefined_variables
end
def auto_devops_variables
......@@ -1851,11 +1846,4 @@ class Project < ActiveRecord::Base
raise ex
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
......@@ -5,7 +5,7 @@
.col-sm-4
= render 'sidebar'
.col-sm-8
- if @project.kubernetes_service&.active?
- if @project.deployment_platform&.active?
%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')
......
......@@ -147,7 +147,7 @@
%ul
%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.
- 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.
= f.submit 'Rename project', class: "btn btn-warning"
- if can?(current_user, :change_namespace, @project)
......
......@@ -67,7 +67,7 @@
- if koding_enabled? && @repository.koding_yml.blank?
%li.missing
= 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
= 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') }
......
......@@ -76,7 +76,7 @@ module Gitlab
timeframe_start: timeframe_start,
timeframe_end: timeframe_end,
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}"}
}
end
......
......@@ -113,12 +113,10 @@ describe Projects::BranchesController do
expect(response).to redirect_to project_tree_path(project, branch)
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
result = { status: :success, branch: double(name: branch) }
project.services << build(:kubernetes_service)
expect_any_instance_of(CreateBranchService).to receive(:execute).and_return(result)
expect(SystemNoteService).to receive(:new_issue_branch).and_return(true)
......@@ -133,24 +131,20 @@ describe Projects::BranchesController do
end
end
context 'when user configured kubernetes from CI/CD > Clusters' do
it 'redirects to autodeploy setup page' do
result = { status: :success, branch: double(name: branch) }
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)
context 'when user configured kubernetes from Integration > Kubernetes' do
before do
project.services << build(:kubernetes_service)
end
post :create,
namespace_id: project.namespace.to_param,
project_id: project.to_param,
branch_name: branch,
issue_iid: issue.iid
it_behaves_like 'correct behavior on KubernetesService and Platform::Kubernetes'
end
expect(response.location).to include(project_new_blob_path(project, branch))
expect(response).to have_gitlab_http_status(302)
context 'when user configured kubernetes from CI/CD > Clusters' do
before do
create(:cluster, :provided_by_gcp, projects: [project])
end
it_behaves_like 'correct behavior on KubernetesService and Platform::Kubernetes'
end
end
......
......@@ -4,13 +4,7 @@ describe 'Auto deploy' do
let(:user) { create(:user) }
let(:project) { create(:project, :repository) }
context 'when user configured kubernetes from Integration > Kubernetes' do
before do
create :kubernetes_service, project: project
project.team << [user, :master]
sign_in user
end
shared_examples 'correct behavior on KubernetesService and Platform::Kubernetes' do
context 'when no deployment service is active' do
before do
project.kubernetes_service.update!(active: false)
......@@ -55,54 +49,23 @@ describe 'Auto deploy' do
end
end
context 'when user configured kubernetes from CI/CD > Clusters' do
context 'when user configured kubernetes from Integration > Kubernetes' do
before do
create(:cluster, :provided_by_gcp, projects: [project])
create :kubernetes_service, project: project
project.team << [user, :master]
sign_in user
end
context 'when no deployment service is active' do
before do
project.kubernetes_service.update!(active: false)
end
it 'does not show a button to set up auto deploy' do
visit project_path(project)
expect(page).to have_no_content('Set up auto deploy')
end
it_behaves_like 'correct behavior on KubernetesService and Platform::Kubernetes'
end
context 'when a deployment service is active' do
context 'when user configured kubernetes from CI/CD > Clusters' do
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'
create(:cluster, :provided_by_gcp, projects: [project])
project.team << [user, :master]
sign_in user
end
wait_for_requests
click_button 'Commit changes'
expect(page).to have_content('New Merge Request From auto-deploy into master')
end
end
it_behaves_like 'correct behavior on KubernetesService and Platform::Kubernetes'
end
end
require 'spec_helper'
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_GREP_V = %w[_touched? _changed? _was]
......@@ -15,31 +13,4 @@ feature 'Interchangeability between KubernetesService and Platform::Kubernetes'
expect(expected_interfaces - Clusters::Platforms::Kubernetes.instance_methods).to be_empty
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
......@@ -93,52 +93,52 @@ describe Clusters::Platforms::Kubernetes, :use_clean_rails_memory_store_caching
end
describe 'after_save from Clusters::Cluster' do
context 'when platform_kubernetes is being cerated' do
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(:cluster_platform_kubernetes, :configured) }
let(:provider) { build(:cluster_provider_gcp) }
let(:kubernetes_service) { project.kubernetes_service }
it 'updates KubernetesService' do
cluster.save!
expect(kubernetes_service.active).to eq(enabled)
expect(kubernetes_service.api_url).to eq(platform.api_url)
expect(kubernetes_service.namespace).to eq(platform.namespace)
expect(kubernetes_service.ca_pem).to eq(platform.ca_cert)
end
end
context 'when platform_kubernetes has been created' do
let(:enabled) { false }
let!(:project) { create(:project) }
let!(:cluster) { create(:cluster, :provided_by_gcp, projects: [project]) }
let(:platform) { cluster.platform }
let(:kubernetes_service) { project.kubernetes_service }
it 'updates KubernetesService' do
cluster.update(enabled: enabled)
expect(kubernetes_service.active).to eq(enabled)
end
end
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(:cluster_platform_kubernetes, :configured, api_url: 'https://111.111.111.111') }
let(:provider) { build(:cluster_provider_gcp) }
before do
create(:kubernetes_service, project: project)
end
it 'raises an error' do
expect { cluster.save! }.to raise_error('Kubernetes service already configured')
end
end
# context 'when platform_kubernetes is being cerated' do
# 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(:cluster_platform_kubernetes, :configured) }
# let(:provider) { build(:cluster_provider_gcp) }
# let(:kubernetes_service) { project.kubernetes_service }
# it 'updates KubernetesService' do
# cluster.save!
# expect(kubernetes_service.active).to eq(enabled)
# expect(kubernetes_service.api_url).to eq(platform.api_url)
# expect(kubernetes_service.namespace).to eq(platform.namespace)
# expect(kubernetes_service.ca_pem).to eq(platform.ca_cert)
# end
# end
# context 'when platform_kubernetes has been created' do
# let(:enabled) { false }
# let!(:project) { create(:project) }
# let!(:cluster) { create(:cluster, :provided_by_gcp, projects: [project]) }
# let(:platform) { cluster.platform }
# let(:kubernetes_service) { project.kubernetes_service }
# it 'updates KubernetesService' do
# cluster.update(enabled: enabled)
# expect(kubernetes_service.active).to eq(enabled)
# end
# end
# 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(:cluster_platform_kubernetes, :configured, api_url: 'https://111.111.111.111') }
# let(:provider) { build(:cluster_provider_gcp) }
# before do
# create(:kubernetes_service, project: project)
# end
# it 'raises an error' do
# expect { cluster.save! }.to raise_error('Kubernetes service already configured')
# end
# end
end
describe '#actual_namespace' do
......
......@@ -369,7 +369,6 @@ describe Environment do
end
describe '#terminals' do
let(:project) { create(:kubernetes_project) }
subject { environment.terminals }
context 'when the environment has terminals' do
......@@ -377,8 +376,9 @@ describe Environment do
allow(environment).to receive(:has_terminals?).and_return(true)
end
shared_examples 'correct behavior on KubernetesService and Platform::Kubernetes' do
it 'returns the terminals from the deployment service' do
expect(project.deployment_service)
expect(project.deployment_platform)
.to receive(:terminals).with(environment)
.and_return(:fake_terminals)
......@@ -386,6 +386,20 @@ describe Environment do
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
context 'when the environment does not have terminals' do
before do
allow(environment).to receive(:has_terminals?).and_return(false)
......
......@@ -5,7 +5,7 @@ describe KubernetesService, :use_clean_rails_memory_store_caching do
include ReactiveCachingHelpers
let(:project) { build_stubbed(:kubernetes_project) }
let(:service) { project.kubernetes_service }
let(:service) { project.deployment_platform }
describe 'Associations' do
it { is_expected.to belong_to :project }
......
......@@ -2002,10 +2002,10 @@ describe Project do
end
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
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
......@@ -2013,14 +2013,14 @@ describe Project do
context 'when user configured kubernetes from Integration > Kubernetes' do
let(:project) { create(:kubernetes_project) }
it_behaves_like 'correct behavior with variables'
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 with variables'
it_behaves_like 'correct behavior on KubernetesService and Platform::Kubernetes'
end
end
end
......@@ -3096,4 +3096,21 @@ describe Project do
expect(project.wiki_repository_exists?).to eq(false)
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
......@@ -43,7 +43,7 @@ RSpec.shared_examples 'additional metrics query' do
describe 'project has Kubernetes service' do
shared_examples 'correct behavior with metrics' do
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'
......
require 'spec_helper'
describe ReactiveCachingWorker do
let(:service) { project.deployment_service }
let(:service) { project.deployment_platform }
subject { described_class.new.perform("KubernetesService", service.id) }
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