summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Fargher <proglottis@gmail.com>2019-06-18 00:01:56 +0000
committerThong Kuah <tkuah@gitlab.com>2019-06-18 00:01:56 +0000
commit6b9157d5dc9b45cc6d70f10d075bbf149af5f266 (patch)
tree29161152edd2c8cfbf1e4097beced805cdd47a72
parent04307096bcc776259d8080bebd688ff6073d07c4 (diff)
downloadgitlab-ce-6b9157d5dc9b45cc6d70f10d075bbf149af5f266.tar.gz
Make KubernetesService readonly
We are deprecating this service in favor of instance wide clusters. Therefore we removed some code that is not anymore needed for a readonly cluster and also we added some flags to allow for this deprecation. These flags are to be removed in the next release when we finally completelly remove KubernetesService.
-rw-r--r--.rubocop_todo.yml1
-rw-r--r--app/assets/stylesheets/pages/settings.scss5
-rw-r--r--app/helpers/services_helper.rb2
-rw-r--r--app/models/project_services/deployment_service.rb39
-rw-r--r--app/models/project_services/kubernetes_service.rb49
-rw-r--r--app/models/project_services/mock_deployment_service.rb16
-rw-r--r--app/views/admin/services/_deprecated_message.html.haml3
-rw-r--r--app/views/admin/services/_form.html.haml5
-rw-r--r--app/views/admin/services/edit.html.haml3
-rw-r--r--changelogs/unreleased/readonly_k8s_integration.yml5
-rw-r--r--locale/gitlab.pot6
-rw-r--r--spec/controllers/projects/branches_controller_spec.rb22
-rw-r--r--spec/controllers/projects/services_controller_spec.rb26
-rw-r--r--spec/factories/services.rb2
-rw-r--r--spec/features/projects/clusters/interchangeability_spec.rb16
-rw-r--r--spec/features/projects/environments/environment_spec.rb18
-rw-r--r--spec/features/projects/environments/environments_spec.rb18
-rw-r--r--spec/lib/gitlab/ci/build/policy/kubernetes_spec.rb18
-rw-r--r--spec/models/ci/pipeline_spec.rb37
-rw-r--r--spec/models/environment_spec.rb42
-rw-r--r--spec/models/project_services/kubernetes_service_spec.rb44
-rw-r--r--spec/models/project_spec.rb18
-rw-r--r--spec/models/service_spec.rb6
-rw-r--r--spec/requests/api/services_spec.rb10
-rw-r--r--spec/serializers/environment_entity_spec.rb10
-rw-r--r--spec/support/prometheus/additional_metrics_shared_examples.rb17
-rw-r--r--spec/support/shared_contexts/services_shared_context.rb3
-rw-r--r--spec/workers/reactive_caching_worker_spec.rb10
28 files changed, 132 insertions, 319 deletions
diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml
index 63b1685feda..698570efb07 100644
--- a/.rubocop_todo.yml
+++ b/.rubocop_todo.yml
@@ -799,7 +799,6 @@ Style/SelfAssignment:
Exclude:
- 'app/models/concerns/bulk_member_access_load.rb'
- 'app/serializers/base_serializer.rb'
- - 'spec/features/projects/clusters/interchangeability_spec.rb'
- 'spec/support/import_export/configuration_helper.rb'
# Offense count: 50
diff --git a/app/assets/stylesheets/pages/settings.scss b/app/assets/stylesheets/pages/settings.scss
index 0a9c56f5625..3b62121eb0d 100644
--- a/app/assets/stylesheets/pages/settings.scss
+++ b/app/assets/stylesheets/pages/settings.scss
@@ -340,6 +340,11 @@
.deprecated-service {
cursor: default;
+
+ a {
+ font-weight: $gl-font-weight-bold;
+ color: $white-light;
+ }
}
.personal-access-tokens-never-expires-label {
diff --git a/app/helpers/services_helper.rb b/app/helpers/services_helper.rb
index d4b50b7ecfb..01ccf163b45 100644
--- a/app/helpers/services_helper.rb
+++ b/app/helpers/services_helper.rb
@@ -39,7 +39,7 @@ module ServicesHelper
end
def disable_fields_service?(service)
- !current_controller?("admin/services") && service.deprecated?
+ service.is_a?(KubernetesService) || (!current_controller?("admin/services") && service.deprecated?)
end
extend self
diff --git a/app/models/project_services/deployment_service.rb b/app/models/project_services/deployment_service.rb
deleted file mode 100644
index 80aa2101509..00000000000
--- a/app/models/project_services/deployment_service.rb
+++ /dev/null
@@ -1,39 +0,0 @@
-# frozen_string_literal: true
-
-# Base class for deployment services
-#
-# These services integrate with a deployment solution like Kubernetes/OpenShift,
-# Mesosphere, etc, to provide additional features to environments.
-class DeploymentService < Service
- default_value_for :category, 'deployment'
-
- def self.supported_events
- %w()
- end
-
- def predefined_variables(project:)
- []
- end
-
- # Environments may have a number of terminals. Should return an array of
- # hashes describing them, e.g.:
- #
- # [{
- # :selectors => {"a" => "b", "foo" => "bar"},
- # :url => "wss://external.example.com/exec",
- # :headers => {"Authorization" => "Token xxx"},
- # :subprotocols => ["foo"],
- # :ca_pem => "----BEGIN CERTIFICATE...", # optional
- # :created_at => Time.now.utc
- # }]
- #
- # Selectors should be a set of values that uniquely identify a particular
- # terminal
- def terminals(environment)
- raise NotImplementedError
- end
-
- def can_test?
- false
- end
-end
diff --git a/app/models/project_services/kubernetes_service.rb b/app/models/project_services/kubernetes_service.rb
index aa6b4aa1d5e..edf7e886e77 100644
--- a/app/models/project_services/kubernetes_service.rb
+++ b/app/models/project_services/kubernetes_service.rb
@@ -5,10 +5,12 @@
# We'll move this class to Clusters::Platforms::Kubernetes, which contains exactly the same logic.
# After we've migrated data, we'll remove KubernetesService. This would happen in a few months.
# If you're modyfiyng this class, please note that you should update the same change in Clusters::Platforms::Kubernetes.
-class KubernetesService < DeploymentService
+class KubernetesService < Service
include Gitlab::Kubernetes
include ReactiveCaching
+ default_value_for :category, 'deployment'
+
self.reactive_cache_key = ->(service) { [service.class.model_name.singular, service.project_id] }
# Namespace defaults to the project path, but can be overridden in case that
@@ -32,7 +34,10 @@ class KubernetesService < DeploymentService
before_validation :enforce_namespace_to_lower_case
- validate :deprecation_validation, unless: :template?
+ attr_accessor :skip_deprecation_validation
+
+ validate :deprecation_validation, unless: :skip_deprecation_validation
+
validates :namespace,
allow_blank: true,
length: 1..63,
@@ -44,6 +49,14 @@ class KubernetesService < DeploymentService
after_save :clear_reactive_cache!
+ def self.supported_events
+ %w()
+ end
+
+ def can_test?
+ false
+ end
+
def initialize_properties
self.properties = {} if properties.nil?
end
@@ -56,11 +69,6 @@ class KubernetesService < DeploymentService
'Kubernetes / OpenShift integration'
end
- def help
- 'To enable terminal access to Kubernetes environments, label your ' \
- 'deployments with `app=$CI_ENVIRONMENT_SLUG`'
- end
-
def self.to_param
'kubernetes'
end
@@ -153,14 +161,25 @@ class KubernetesService < DeploymentService
end
def deprecated?
- !active
+ true
+ end
+
+ def editable?
+ false
end
def deprecation_message
- content = _("Kubernetes service integration has been deprecated. %{deprecated_message_content} your Kubernetes clusters using the new <a href=\"%{url}\"/>Kubernetes Clusters</a> page") % {
- deprecated_message_content: deprecated_message_content,
- url: Gitlab::Routing.url_helpers.project_clusters_path(project)
- }
+ content = if project
+ _("Kubernetes service integration has been deprecated. %{deprecated_message_content} your Kubernetes clusters using the new <a href=\"%{url}\"/>Kubernetes Clusters</a> page") % {
+ deprecated_message_content: deprecated_message_content,
+ url: Gitlab::Routing.url_helpers.project_clusters_path(project)
+ }
+ else
+ _("The instance-level Kubernetes service integration is deprecated. Your data has been migrated to an <a href=\"%{url}\"/>instance-level cluster</a>.") % {
+ url: Gitlab::Routing.url_helpers.admin_clusters_path
+ }
+ end
+
content.html_safe
end
@@ -243,10 +262,6 @@ class KubernetesService < DeploymentService
end
def deprecated_message_content
- if active?
- _("Your Kubernetes cluster information on this page is still editable, but you are advised to disable and reconfigure")
- else
- _("Fields on this page are now uneditable, you can configure")
- end
+ _("Fields on this page are now uneditable, you can configure")
end
end
diff --git a/app/models/project_services/mock_deployment_service.rb b/app/models/project_services/mock_deployment_service.rb
index 7ab1687f8ba..1103cb11e73 100644
--- a/app/models/project_services/mock_deployment_service.rb
+++ b/app/models/project_services/mock_deployment_service.rb
@@ -1,6 +1,8 @@
# frozen_string_literal: true
-class MockDeploymentService < DeploymentService
+class MockDeploymentService < Service
+ default_value_for :category, 'deployment'
+
def title
'Mock deployment'
end
@@ -17,4 +19,16 @@ class MockDeploymentService < DeploymentService
def terminals(environment)
[]
end
+
+ def self.supported_events
+ %w()
+ end
+
+ def predefined_variables(project:)
+ []
+ end
+
+ def can_test?
+ false
+ end
end
diff --git a/app/views/admin/services/_deprecated_message.html.haml b/app/views/admin/services/_deprecated_message.html.haml
new file mode 100644
index 00000000000..fea9506a4bb
--- /dev/null
+++ b/app/views/admin/services/_deprecated_message.html.haml
@@ -0,0 +1,3 @@
+.flash-container.flash-container-page
+ .flash-alert.deprecated-service
+ %span= @service.deprecation_message
diff --git a/app/views/admin/services/_form.html.haml b/app/views/admin/services/_form.html.haml
index 1798b44bbb7..97373a3c350 100644
--- a/app/views/admin/services/_form.html.haml
+++ b/app/views/admin/services/_form.html.haml
@@ -6,5 +6,6 @@
= form_for :service, url: admin_application_settings_service_path, method: :put, html: { class: 'fieldset-form' } do |form|
= render 'shared/service_settings', form: form, subject: @service
- .footer-block.row-content-block
- = form.submit 'Save', class: 'btn btn-success'
+ - unless @service.is_a?(KubernetesService)
+ .footer-block.row-content-block
+ = form.submit 'Save', class: 'btn btn-success'
diff --git a/app/views/admin/services/edit.html.haml b/app/views/admin/services/edit.html.haml
index 512176649e6..79f5ab0d77d 100644
--- a/app/views/admin/services/edit.html.haml
+++ b/app/views/admin/services/edit.html.haml
@@ -1,4 +1,7 @@
- add_to_breadcrumbs "Service Templates", admin_application_settings_services_path
- breadcrumb_title @service.title
- page_title @service.title, "Service Templates"
+
+= render 'deprecated_message' if @service.deprecation_message
+
= render 'form'
diff --git a/changelogs/unreleased/readonly_k8s_integration.yml b/changelogs/unreleased/readonly_k8s_integration.yml
new file mode 100644
index 00000000000..718705e8750
--- /dev/null
+++ b/changelogs/unreleased/readonly_k8s_integration.yml
@@ -0,0 +1,5 @@
+---
+title: Make Kubernetes service templates readonly
+merge_request: 29044
+author:
+type: removed
diff --git a/locale/gitlab.pot b/locale/gitlab.pot
index 186c4cb2dba..0cabaeabb9a 100644
--- a/locale/gitlab.pot
+++ b/locale/gitlab.pot
@@ -9999,6 +9999,9 @@ msgstr ""
msgid "The import will time out after %{timeout}. For repositories that take longer, use a clone/push combination."
msgstr ""
+msgid "The instance-level Kubernetes service integration is deprecated. Your data has been migrated to an <a href=\"%{url}\"/>instance-level cluster</a>."
+msgstr ""
+
msgid "The invitation could not be accepted."
msgstr ""
@@ -11943,9 +11946,6 @@ msgstr ""
msgid "Your Groups"
msgstr ""
-msgid "Your Kubernetes cluster information on this page is still editable, but you are advised to disable and reconfigure"
-msgstr ""
-
msgid "Your Primary Email will be used for avatar detection."
msgstr ""
diff --git a/spec/controllers/projects/branches_controller_spec.rb b/spec/controllers/projects/branches_controller_spec.rb
index c778b7888dc..cf201c9f735 100644
--- a/spec/controllers/projects/branches_controller_spec.rb
+++ b/spec/controllers/projects/branches_controller_spec.rb
@@ -123,7 +123,11 @@ describe Projects::BranchesController do
expect(response).to redirect_to project_tree_path(project, branch)
end
- shared_examples 'same behavior between KubernetesService and Platform::Kubernetes' do
+ context 'when user configured kubernetes from CI/CD > Clusters' do
+ before do
+ create(:cluster, :provided_by_gcp, projects: [project])
+ end
+
it 'redirects to autodeploy setup page' do
result = { status: :success, branch: double(name: branch) }
@@ -143,22 +147,6 @@ describe Projects::BranchesController do
end
end
- context 'when user configured kubernetes from Integration > Kubernetes' do
- before do
- project.services << build(:kubernetes_service)
- end
-
- it_behaves_like 'same behavior between KubernetesService and Platform::Kubernetes'
- end
-
- context 'when user configured kubernetes from CI/CD > Clusters' do
- before do
- create(:cluster, :provided_by_gcp, projects: [project])
- end
-
- it_behaves_like 'same behavior between KubernetesService and Platform::Kubernetes'
- end
-
it 'redirects to autodeploy setup page' do
result = { status: :success, branch: double(name: branch) }
diff --git a/spec/controllers/projects/services_controller_spec.rb b/spec/controllers/projects/services_controller_spec.rb
index 3608d175d50..5c7f8d95f82 100644
--- a/spec/controllers/projects/services_controller_spec.rb
+++ b/spec/controllers/projects/services_controller_spec.rb
@@ -141,20 +141,6 @@ describe Projects::ServicesController do
end
end
- context 'with a deprecated service' do
- let(:service) { create(:kubernetes_service, project: project) }
-
- before do
- put :update,
- params: { namespace_id: project.namespace, project_id: project, id: service.to_param, service: { namespace: 'updated_namespace' } }
- end
-
- it 'does not update the service' do
- service.reload
- expect(service.namespace).not_to eq('updated_namespace')
- end
- end
-
context 'when activating JIRA service from a template' do
let(:template_service) { create(:jira_service, project: project, template: true) }
@@ -168,20 +154,10 @@ describe Projects::ServicesController do
describe "GET #edit" do
before do
- get :edit, params: { namespace_id: project.namespace, project_id: project, id: service_id }
+ get :edit, params: { namespace_id: project.namespace, project_id: project, id: 'jira' }
end
context 'with approved services' do
- let(:service_id) { 'jira' }
-
- it 'renders edit page' do
- expect(response).to be_success
- end
- end
-
- context 'with a deprecated service' do
- let(:service_id) { 'kubernetes' }
-
it 'renders edit page' do
expect(response).to be_success
end
diff --git a/spec/factories/services.rb b/spec/factories/services.rb
index 0d8c26a2ee9..763909f30bd 100644
--- a/spec/factories/services.rb
+++ b/spec/factories/services.rb
@@ -24,6 +24,8 @@ FactoryBot.define do
api_url: 'https://kubernetes.example.com',
token: 'a' * 40
})
+
+ skip_deprecation_validation true
end
factory :mock_deployment_service do
diff --git a/spec/features/projects/clusters/interchangeability_spec.rb b/spec/features/projects/clusters/interchangeability_spec.rb
deleted file mode 100644
index 0033e12b6b1..00000000000
--- a/spec/features/projects/clusters/interchangeability_spec.rb
+++ /dev/null
@@ -1,16 +0,0 @@
-require 'spec_helper'
-
-describe 'Interchangeability between KubernetesService and Platform::Kubernetes' do
- EXCEPT_METHODS = %i[test title description help fields initialize_properties namespace namespace= api_url api_url= deprecated? deprecation_message].freeze
- EXCEPT_METHODS_GREP_V = %w[_touched? _changed? _was].freeze
-
- it 'Clusters::Platform::Kubernetes covers core interfaces in KubernetesService' do
- expected_interfaces = KubernetesService.instance_methods(false)
- expected_interfaces = expected_interfaces - EXCEPT_METHODS
- EXCEPT_METHODS_GREP_V.each do |g|
- expected_interfaces = expected_interfaces.grep_v(/#{Regexp.escape(g)}\z/)
- end
-
- expect(expected_interfaces - Clusters::Platforms::Kubernetes.instance_methods).to be_empty
- end
-end
diff --git a/spec/features/projects/environments/environment_spec.rb b/spec/features/projects/environments/environment_spec.rb
index da4ef6428d4..fbaf12be64e 100644
--- a/spec/features/projects/environments/environment_spec.rb
+++ b/spec/features/projects/environments/environment_spec.rb
@@ -155,7 +155,10 @@ describe 'Environment' do
end
context 'with terminal' do
- shared_examples 'same behavior between KubernetesService and Platform::Kubernetes' do
+ context 'when user configured kubernetes from CI/CD > Clusters' do
+ let!(:cluster) { create(:cluster, :project, :provided_by_gcp) }
+ let(:project) { cluster.project }
+
context 'for project maintainer' do
let(:role) { :maintainer }
@@ -191,19 +194,6 @@ describe 'Environment' do
end
end
end
-
- context 'when user configured kubernetes from Integration > Kubernetes' do
- let(:project) { create(:kubernetes_project, :test_repo) }
-
- it_behaves_like 'same behavior between 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 'same behavior between KubernetesService and Platform::Kubernetes'
- end
end
context 'when environment is available' do
diff --git a/spec/features/projects/environments/environments_spec.rb b/spec/features/projects/environments/environments_spec.rb
index 7b7e45312d9..1b5d9083932 100644
--- a/spec/features/projects/environments/environments_spec.rb
+++ b/spec/features/projects/environments/environments_spec.rb
@@ -248,7 +248,10 @@ describe 'Environments page', :js do
end
context 'when kubernetes terminal is available' do
- shared_examples 'same behavior between KubernetesService and Platform::Kubernetes' do
+ context 'when user configured kubernetes from CI/CD > Clusters' do
+ let(:cluster) { create(:cluster, :provided_by_gcp, projects: [create(:project, :repository)]) }
+ let(:project) { cluster.project }
+
context 'for project maintainer' do
let(:role) { :maintainer }
@@ -265,19 +268,6 @@ describe 'Environments page', :js do
end
end
end
-
- context 'when user configured kubernetes from Integration > Kubernetes' do
- let(:project) { create(:kubernetes_project, :test_repo) }
-
- it_behaves_like 'same behavior between KubernetesService and Platform::Kubernetes'
- end
-
- context 'when user configured kubernetes from CI/CD > Clusters' do
- let(:cluster) { create(:cluster, :provided_by_gcp, projects: [create(:project, :repository)]) }
- let(:project) { cluster.project }
-
- it_behaves_like 'same behavior between KubernetesService and Platform::Kubernetes'
- end
end
end
diff --git a/spec/lib/gitlab/ci/build/policy/kubernetes_spec.rb b/spec/lib/gitlab/ci/build/policy/kubernetes_spec.rb
index 4884d5f8ba4..4510b82ca9d 100644
--- a/spec/lib/gitlab/ci/build/policy/kubernetes_spec.rb
+++ b/spec/lib/gitlab/ci/build/policy/kubernetes_spec.rb
@@ -4,24 +4,14 @@ describe Gitlab::Ci::Build::Policy::Kubernetes do
let(:pipeline) { create(:ci_pipeline, project: project) }
context 'when kubernetes service is active' do
- shared_examples 'same behavior between KubernetesService and Platform::Kubernetes' do
- it 'is satisfied by a kubernetes pipeline' do
- expect(described_class.new('active'))
- .to be_satisfied_by(pipeline)
- end
- end
-
- context 'when user configured kubernetes from Integration > Kubernetes' do
- let(:project) { create(:kubernetes_project) }
-
- it_behaves_like 'same behavior between 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 'same behavior between KubernetesService and Platform::Kubernetes'
+ it 'is satisfied by a kubernetes pipeline' do
+ expect(described_class.new('active'))
+ .to be_satisfied_by(pipeline)
+ end
end
end
diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb
index c4e54be673f..6ebc6337d50 100644
--- a/spec/models/ci/pipeline_spec.rb
+++ b/spec/models/ci/pipeline_spec.rb
@@ -962,7 +962,11 @@ describe Ci::Pipeline, :mailer do
end
context 'when kubernetes is active' do
- shared_examples 'same behavior between KubernetesService and Platform::Kubernetes' do
+ context 'when user configured kubernetes from CI/CD > Clusters' do
+ let!(:cluster) { create(:cluster, :project, :provided_by_gcp) }
+ let(:project) { cluster.project }
+ let(:pipeline) { build(:ci_pipeline, project: project, config: config) }
+
it 'returns seeds for kubernetes dependent job' do
seeds = pipeline.stage_seeds
@@ -971,21 +975,6 @@ describe Ci::Pipeline, :mailer do
expect(seeds.dig(1, 0, :name)).to eq 'production'
end
end
-
- context 'when user configured kubernetes from Integration > Kubernetes' do
- let(:project) { create(:kubernetes_project) }
- let(:pipeline) { build(:ci_pipeline, project: project, config: config) }
-
- it_behaves_like 'same behavior between 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 }
- let(:pipeline) { build(:ci_pipeline, project: project, config: config) }
-
- it_behaves_like 'same behavior between KubernetesService and Platform::Kubernetes'
- end
end
context 'when kubernetes is not active' do
@@ -1679,23 +1668,13 @@ describe Ci::Pipeline, :mailer do
describe '#has_kubernetes_active?' do
context 'when kubernetes is active' do
- shared_examples 'same behavior between KubernetesService and Platform::Kubernetes' do
- it 'returns true' do
- expect(pipeline).to have_kubernetes_active
- end
- end
-
- context 'when user configured kubernetes from Integration > Kubernetes' do
- let(:project) { create(:kubernetes_project) }
-
- it_behaves_like 'same behavior between 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 'same behavior between KubernetesService and Platform::Kubernetes'
+ it 'returns true' do
+ expect(pipeline).to have_kubernetes_active
+ end
end
end
diff --git a/spec/models/environment_spec.rb b/spec/models/environment_spec.rb
index 7233d2454c6..379dda1f5c4 100644
--- a/spec/models/environment_spec.rb
+++ b/spec/models/environment_spec.rb
@@ -515,29 +515,19 @@ describe Environment do
context 'when the environment is available' do
context 'with a deployment service' do
- shared_examples 'same behavior between KubernetesService and Platform::Kubernetes' do
- context 'and a deployment' do
+ context 'when user configured kubernetes from CI/CD > Clusters' do
+ let!(:cluster) { create(:cluster, :project, :provided_by_gcp) }
+ let(:project) { cluster.project }
+
+ context 'with deployment' do
let!(:deployment) { create(:deployment, :success, environment: environment) }
it { is_expected.to be_truthy }
end
- context 'but no deployments' do
+ context 'without deployments' do
it { is_expected.to be_falsy }
end
end
-
- context 'when user configured kubernetes from Integration > Kubernetes' do
- let(:project) { create(:kubernetes_project) }
-
- it_behaves_like 'same behavior between 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 'same behavior between KubernetesService and Platform::Kubernetes'
- end
end
context 'without a deployment service' do
@@ -546,8 +536,6 @@ describe Environment do
end
context 'when the environment is unavailable' do
- let(:project) { create(:kubernetes_project) }
-
before do
environment.stop
end
@@ -590,7 +578,10 @@ describe Environment do
allow(environment).to receive(:has_terminals?).and_return(true)
end
- shared_examples 'same behavior between KubernetesService and Platform::Kubernetes' do
+ context 'when user configured kubernetes from CI/CD > Clusters' do
+ let!(:cluster) { create(:cluster, :project, :provided_by_gcp) }
+ let(:project) { cluster.project }
+
it 'returns the terminals from the deployment service' do
expect(environment.deployment_platform)
.to receive(:terminals).with(environment)
@@ -599,19 +590,6 @@ describe Environment do
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 'same behavior between 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 'same behavior between KubernetesService and Platform::Kubernetes'
- end
end
context 'when the environment does not have terminals' do
diff --git a/spec/models/project_services/kubernetes_service_spec.rb b/spec/models/project_services/kubernetes_service_spec.rb
index 2fce120381b..34ee1eafd5c 100644
--- a/spec/models/project_services/kubernetes_service_spec.rb
+++ b/spec/models/project_services/kubernetes_service_spec.rb
@@ -17,6 +17,7 @@ describe KubernetesService, :use_clean_rails_memory_store_caching do
context 'when service is active' do
before do
subject.active = true
+ subject.skip_deprecation_validation = true
end
it { is_expected.not_to validate_presence_of(:namespace) }
@@ -67,6 +68,7 @@ describe KubernetesService, :use_clean_rails_memory_store_caching do
before do
kubernetes_service.update_attribute(:active, false)
+ kubernetes_service.skip_deprecation_validation = false
kubernetes_service.properties['namespace'] = "foo"
end
@@ -80,19 +82,11 @@ describe KubernetesService, :use_clean_rails_memory_store_caching do
end
end
- context 'with a non-deprecated service' do
- let(:kubernetes_service) { create(:kubernetes_service) }
-
- it 'updates attributes' do
- kubernetes_service.properties['namespace'] = 'foo'
- expect(kubernetes_service.save).to be_truthy
- end
- end
-
context 'with an active and deprecated service' do
let(:kubernetes_service) { create(:kubernetes_service) }
before do
+ kubernetes_service.skip_deprecation_validation = false
kubernetes_service.active = false
kubernetes_service.properties['namespace'] = 'foo'
kubernetes_service.save
@@ -110,19 +104,6 @@ describe KubernetesService, :use_clean_rails_memory_store_caching do
expect(kubernetes_service.properties['namespace']).to eq("foo")
end
end
-
- context 'with a template service' do
- let(:kubernetes_service) { create(:kubernetes_service, template: true, active: false) }
-
- before do
- kubernetes_service.properties['namespace'] = 'foo'
- end
-
- it 'updates attributes' do
- expect(kubernetes_service.save).to be_truthy
- expect(kubernetes_service.properties['namespace']).to eq('foo')
- end
- end
end
describe '#initialize_properties' do
@@ -393,17 +374,8 @@ describe KubernetesService, :use_clean_rails_memory_store_caching do
describe "#deprecated?" do
let(:kubernetes_service) { create(:kubernetes_service) }
- context 'with an active kubernetes service' do
- it 'returns false' do
- expect(kubernetes_service.deprecated?).to be_falsy
- end
- end
-
- context 'with a inactive kubernetes service' do
- it 'returns true' do
- kubernetes_service.update_attribute(:active, false)
- expect(kubernetes_service.deprecated?).to be_truthy
- end
+ it 'returns true' do
+ expect(kubernetes_service.deprecated?).to be_truthy
end
end
@@ -414,12 +386,6 @@ describe KubernetesService, :use_clean_rails_memory_store_caching do
expect(kubernetes_service.deprecation_message).to match(/Kubernetes service integration has been deprecated/)
end
- context 'if the services is active' do
- it 'returns a message' do
- expect(kubernetes_service.deprecation_message).to match(/Your Kubernetes cluster information on this page is still editable/)
- end
- end
-
context 'if the service is not active' do
it 'returns a message' do
kubernetes_service.update_attribute(:active, false)
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index 269d2bb90d3..20b98b5eb85 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -2652,7 +2652,10 @@ describe Project do
end
context 'when project has a deployment service' do
- shared_examples 'same behavior between KubernetesService and Platform::Kubernetes' do
+ context 'when user configured kubernetes from CI/CD > Clusters and KubernetesNamespace migration has not been executed' do
+ let!(:cluster) { create(:cluster, :project, :provided_by_gcp) }
+ let(:project) { cluster.project }
+
it 'returns variables from this service' do
expect(project.deployment_variables).to include(
{ key: 'KUBE_TOKEN', value: project.deployment_platform.token, public: false, masked: true }
@@ -2660,19 +2663,6 @@ describe Project do
end
end
- context 'when user configured kubernetes from Integration > Kubernetes' do
- let(:project) { create(:kubernetes_project) }
-
- it_behaves_like 'same behavior between KubernetesService and Platform::Kubernetes'
- end
-
- context 'when user configured kubernetes from CI/CD > Clusters and KubernetesNamespace migration has not been executed' do
- let!(:cluster) { create(:cluster, :project, :provided_by_gcp) }
- let(:project) { cluster.project }
-
- it_behaves_like 'same behavior between KubernetesService and Platform::Kubernetes'
- end
-
context 'when user configured kubernetes from CI/CD > Clusters and KubernetesNamespace migration has been executed' do
let!(:kubernetes_namespace) { create(:cluster_kubernetes_namespace, :with_token) }
let!(:cluster) { kubernetes_namespace.cluster }
diff --git a/spec/models/service_spec.rb b/spec/models/service_spec.rb
index c9439b0846d..d442c73c118 100644
--- a/spec/models/service_spec.rb
+++ b/spec/models/service_spec.rb
@@ -82,7 +82,7 @@ describe Service do
context 'when template is invalid' do
it 'sets service template to inactive when template is invalid' do
project = create(:project)
- template = KubernetesService.new(template: true, active: true)
+ template = build(:prometheus_service, template: true, active: true, properties: {})
template.save(validate: false)
service = described_class.build_from_template(project.id, template)
@@ -309,10 +309,10 @@ describe Service do
end
describe '.find_by_template' do
- let!(:kubernetes_service) { create(:kubernetes_service, template: true) }
+ let!(:service) { create(:service, template: true) }
it 'returns service template' do
- expect(KubernetesService.find_by_template).to eq(kubernetes_service)
+ expect(described_class.find_by_template).to eq(service)
end
end
diff --git a/spec/requests/api/services_spec.rb b/spec/requests/api/services_spec.rb
index 8065c077ca0..3f79e332b90 100644
--- a/spec/requests/api/services_spec.rb
+++ b/spec/requests/api/services_spec.rb
@@ -10,7 +10,10 @@ describe API::Services do
end
Service.available_services_names.each do |service|
- describe "PUT /projects/:id/services/#{service.dasherize}" do
+ # TODO: Remove below `if: (service != "kubernetes")` in the next release
+ # KubernetesService was deprecated and it can't be updated. Right now it's
+ # only readable. It should be completely removed in the next iteration.
+ describe "PUT /projects/:id/services/#{service.dasherize}", if: (service != "kubernetes") do
include_context service
it "updates #{service} settings" do
@@ -59,7 +62,10 @@ describe API::Services do
end
end
- describe "DELETE /projects/:id/services/#{service.dasherize}" do
+ # TODO: Remove below `if: (service != "kubernetes")` in the next release
+ # KubernetesService was deprecated and it can't be updated. Right now it's
+ # only readable. It should be completely removed in the next iteration.
+ describe "DELETE /projects/:id/services/#{service.dasherize}", if: (service != "kubernetes") do
include_context service
before do
diff --git a/spec/serializers/environment_entity_spec.rb b/spec/serializers/environment_entity_spec.rb
index c2312734042..906449f470b 100644
--- a/spec/serializers/environment_entity_spec.rb
+++ b/spec/serializers/environment_entity_spec.rb
@@ -59,15 +59,5 @@ describe EnvironmentEntity do
expect(subject[:cluster_type]).to eq('project_type')
end
end
-
- context 'when deployment platform is a Kubernetes Service' do
- before do
- create(:kubernetes_service, project: project)
- end
-
- it 'does not include cluster_type' do
- expect(subject).not_to include(:cluster_type)
- end
- end
end
end
diff --git a/spec/support/prometheus/additional_metrics_shared_examples.rb b/spec/support/prometheus/additional_metrics_shared_examples.rb
index 8044b061ca5..de21e808932 100644
--- a/spec/support/prometheus/additional_metrics_shared_examples.rb
+++ b/spec/support/prometheus/additional_metrics_shared_examples.rb
@@ -44,7 +44,9 @@ RSpec.shared_examples 'additional metrics query' do
end
describe 'project has Kubernetes service' do
- shared_examples 'same behavior between KubernetesService and Platform::Kubernetes' do
+ context 'when user configured kubernetes from CI/CD > Clusters' do
+ let!(:cluster) { create(:cluster, :project, :provided_by_gcp) }
+ let(:project) { cluster.project }
let(:environment) { create(:environment, slug: 'environment-slug', project: project) }
let(:kube_namespace) { project.deployment_platform.kubernetes_namespace_for(project) }
@@ -56,19 +58,6 @@ RSpec.shared_examples 'additional metrics query' do
subject.query(*query_params)
end
end
-
- context 'when user configured kubernetes from Integration > Kubernetes' do
- let(:project) { create(:kubernetes_project) }
-
- it_behaves_like 'same behavior between 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 'same behavior between KubernetesService and Platform::Kubernetes'
- end
end
describe 'project without Kubernetes service' do
diff --git a/spec/support/shared_contexts/services_shared_context.rb b/spec/support/shared_contexts/services_shared_context.rb
index 089f1798cd2..0c3a24d206f 100644
--- a/spec/support/shared_contexts/services_shared_context.rb
+++ b/spec/support/shared_contexts/services_shared_context.rb
@@ -37,8 +37,7 @@ Service.available_services_names.each do |service|
def initialize_service(service)
service_item = project.find_or_initialize_service(service)
service_item.properties = service_attrs
- service_item.active = true if service == "kubernetes"
- service_item.save
+ service_item.save!
service_item
end
end
diff --git a/spec/workers/reactive_caching_worker_spec.rb b/spec/workers/reactive_caching_worker_spec.rb
index 2395e6ec947..b8ca6063ccd 100644
--- a/spec/workers/reactive_caching_worker_spec.rb
+++ b/spec/workers/reactive_caching_worker_spec.rb
@@ -6,16 +6,6 @@ describe ReactiveCachingWorker do
let(:service) { project.deployment_platform }
describe '#perform' do
- context 'when user configured kubernetes from Integration > Kubernetes' do
- let(:project) { create(:kubernetes_project) }
-
- it 'calls #exclusively_update_reactive_cache!' do
- expect_any_instance_of(KubernetesService).to receive(:exclusively_update_reactive_cache!)
-
- described_class.new.perform("KubernetesService", service.id)
- end
- end
-
context 'when user configured kubernetes from CI/CD > Clusters' do
let!(:cluster) { create(:cluster, :project, :provided_by_gcp) }
let(:project) { cluster.project }