Skip to content

Commit

Permalink
Merge pull request #2202 from zendesk/grosser/verify
Browse files Browse the repository at this point in the history
do not blow up with strange error when file is missing in repo or inv…
  • Loading branch information
grosser authored Aug 22, 2017
2 parents 8beb3ce + 3a55890 commit 384ef67
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
7 changes: 6 additions & 1 deletion plugins/kubernetes/app/models/kubernetes/deploy_executor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,12 @@ def verify_kubernetes_templates!
end

# make sure each set of templates is valid
configs = roles.map { |r| r.fetch(:role).role_config_file(@job.commit).primary }.compact
configs = roles.map do |r|
role = r.fetch(:role)
config = role.role_config_file(@job.commit)
raise Samson::Hooks::UserError, "Error parsing #{role.config_file}" unless config
config.primary
end.compact
Kubernetes::RoleVerifier.verify_group(configs)
end
end
Expand Down
2 changes: 1 addition & 1 deletion plugins/kubernetes/app/models/kubernetes/role.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def role_config_file(reference)
begin
RoleConfigFile.new(raw_template, config_file)
rescue Samson::Hooks::UserError
return
nil
end
end

Expand Down
10 changes: 10 additions & 0 deletions plugins/kubernetes/test/models/kubernetes/deploy_executor_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,16 @@ def worker_is_unstable
end
e.message.must_include "Missing env variables FOO, BAR"
end

it "fails before building when role config is missing" do
GitRepository.any_instance.stubs(:file_content).with('kubernetes/resque_worker.yml', commit, anything).
returns(nil)

e = assert_raises Samson::Hooks::UserError do
refute execute
end
e.message.must_include "Error parsing kubernetes/resque_worker.yml"
end
end

describe "role settings" do
Expand Down

0 comments on commit 384ef67

Please sign in to comment.