Adding Kubernetes cluster fails in 12.2 (NoMethodError in outbound_local_requests_whitelist_arrays)
Summary
Adding a new Kubernetes cluster using GitLab e01e78c5 fails with a 500 error.
Steps to reproduce
- Upgrade to 12.2.0-pre (e01e78c5).
- Add Kubernetes cluster. (I only tested to add to group.)
What is the current bug behavior?
The outbound whitelist check tries to read an array from the databases application_settings
table.
The new column is created without a default value, so it contains NULL
, which is converted to nil
.
Saving application settings once saves the correct array in the database and makes adding clusters work.
What is the expected correct behavior?
Don't fail on database return NULL
.
Relevant logs and/or screenshots
NoMethodError (undefined method `each' for nil:NilClass):
app/models/application_setting_implementation.rb:169:in `block in outbound_local_requests_whitelist_arrays'
lib/gitlab/utils/strong_memoize.rb:30:in `strong_memoize'
app/models/application_setting_implementation.rb:165:in `outbound_local_requests_whitelist_arrays'
lib/gitlab/current_settings.rb:15:in `method_missing'
lib/gitlab/url_blocker.rb:128:in `validate_local_request'
lib/gitlab/url_blocker.rb:61:in `validate!'
app/validators/addressable_url_validator.rb:75:in `validate_each'
app/services/clusters/create_service.rb:28:in `block in execute'
app/services/clusters/create_service.rb:27:in `tap'
app/services/clusters/create_service.rb:27:in `execute'
Output of checks
(If you are reporting a bug on GitLab.com, write: This bug happens on GitLab.com)
Possible fixes
--- a/app/models/application_setting_implementation.rb
+++ b/app/models/application_setting_implementation.rb
@@ -166,7 +166,7 @@ module ApplicationSettingImplementation
ip_whitelist = []
domain_whitelist = []
- self.outbound_local_requests_whitelist.each do |str|
+ self.outbound_local_requests_whitelist&.each do |str|
ip_obj = Gitlab::Utils.string_to_ip_object(str)
if ip_obj