Merge branch 'dm-invalid-active-service-template' into 'master'

Deactivate new KubernetesService created from active template to prevent project creation from failing

Closes gitlab-ee#6753

See merge request gitlab-org/gitlab-ce!20400
This commit is contained in:
Robert Speicher 2018-07-05 15:58:09 +00:00
commit 7eddfef439
4 changed files with 8 additions and 3 deletions

View file

@ -240,7 +240,7 @@ class KubernetesService < DeploymentService
end
def deprecation_validation
return if active_changed?(from: true, to: false)
return if active_changed?(from: true, to: false) || (new_record? && !active?)
if deprecated?
errors[:base] << deprecation_message

View file

@ -281,9 +281,9 @@ class Service < ActiveRecord::Base
def self.build_from_template(project_id, template)
service = template.dup
service.active = false unless service.valid?
service.template = false
service.project_id = project_id
service.active = false if service.active? && !service.valid?
service
end

View file

@ -0,0 +1,5 @@
---
title: Deactivate new KubernetesService created from active template to prevent project creation from failing
merge_request:
author:
type: fixed

View file

@ -78,7 +78,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 = JiraService.new(template: true, active: true)
template = KubernetesService.new(template: true, active: true)
template.save(validate: false)
service = described_class.build_from_template(project.id, template)