Commit a4c7c850 authored by Peter Leitzen's avatar Peter Leitzen

Merge branch 'improve_cluster_applications_service' into 'master'

Adds additional error check for no deployment

See merge request gitlab-org/gitlab!32929
parents 1bc4196e 46568b57
...@@ -18,13 +18,9 @@ module Clusters ...@@ -18,13 +18,9 @@ module Clusters
raise ArgumentError, 'Artifact is not cluster_applications file type' unless artifact&.cluster_applications? raise ArgumentError, 'Artifact is not cluster_applications file type' unless artifact&.cluster_applications?
unless artifact.file.size < MAX_ACCEPTABLE_ARTIFACT_SIZE return error(too_big_error_message, :bad_request) unless artifact.file.size < MAX_ACCEPTABLE_ARTIFACT_SIZE
return error(too_big_error_message, :bad_request) return error(no_deployment_message, :bad_request) unless job.deployment
end return error(no_deployment_cluster_message, :bad_request) unless cluster
unless cluster
return error(s_('ClusterIntegration|No deployment cluster found for this job'))
end
parse!(artifact) parse!(artifact)
...@@ -61,7 +57,8 @@ module Clusters ...@@ -61,7 +57,8 @@ module Clusters
Clusters::Cluster.transaction do Clusters::Cluster.transaction do
RELEASE_NAMES.each do |release_name| RELEASE_NAMES.each do |release_name|
application = find_or_build_application(release_name) application_class = Clusters::Cluster::APPLICATIONS[release_name]
application = cluster.find_or_build_application(application_class)
release = release_by_name[release_name] release = release_by_name[release_name]
...@@ -80,16 +77,18 @@ module Clusters ...@@ -80,16 +77,18 @@ module Clusters
end end
end end
def find_or_build_application(application_name)
application_class = Clusters::Cluster::APPLICATIONS[application_name]
cluster.find_or_build_application(application_class)
end
def too_big_error_message def too_big_error_message
human_size = ActiveSupport::NumberHelper.number_to_human_size(MAX_ACCEPTABLE_ARTIFACT_SIZE) human_size = ActiveSupport::NumberHelper.number_to_human_size(MAX_ACCEPTABLE_ARTIFACT_SIZE)
s_('ClusterIntegration|Cluster_applications artifact too big. Maximum allowable size: %{human_size}') % { human_size: human_size } s_('ClusterIntegration|Cluster_applications artifact too big. Maximum allowable size: %{human_size}') % { human_size: human_size }
end end
def no_deployment_message
s_('ClusterIntegration|No deployment found for this job')
end
def no_deployment_cluster_message
s_('ClusterIntegration|No deployment cluster found for this job')
end
end end
end end
...@@ -4977,6 +4977,9 @@ msgstr "" ...@@ -4977,6 +4977,9 @@ msgstr ""
msgid "ClusterIntegration|No deployment cluster found for this job" msgid "ClusterIntegration|No deployment cluster found for this job"
msgstr "" msgstr ""
msgid "ClusterIntegration|No deployment found for this job"
msgstr ""
msgid "ClusterIntegration|No instance type found" msgid "ClusterIntegration|No instance type found"
msgstr "" msgstr ""
......
...@@ -85,9 +85,21 @@ describe Clusters::ParseClusterApplicationsArtifactService do ...@@ -85,9 +85,21 @@ describe Clusters::ParseClusterApplicationsArtifactService do
end end
end end
context 'job has no deployment cluster' do context 'job has no deployment' do
let(:job) { build(:ci_build) } let(:job) { build(:ci_build) }
it 'returns an error' do
result = described_class.new(job, user).execute(artifact)
expect(result[:status]).to eq(:error)
expect(result[:message]).to eq('No deployment found for this job')
end
end
context 'job has no deployment cluster' do
let(:deployment) { create(:deployment) }
let(:job) { deployment.deployable }
it 'returns an error' do it 'returns an error' do
result = described_class.new(job, user).execute(artifact) result = described_class.new(job, user).execute(artifact)
......
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