Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion kubernetes/spec/config/kube_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,19 @@
end
end

context 'if empty user context is given' do
it 'should configure non user configuration' do
expected = Kubernetes::Configuration.new do |c|
c.scheme = 'http'
c.host = 'test-host:80'
end
actual = Kubernetes::Configuration.new

kube_config.configure(actual, 'empty_user')
expect(actual).to be_same_configuration_as(expected)
end
end

context 'if ssl context is given' do
it 'should configure ssl configuration' do
expected = Kubernetes::Configuration.new do |c|
Expand Down Expand Up @@ -214,7 +227,9 @@

context '#list_context_names' do
it 'should list context names' do
arr = %w[default no_user context_ssl context_insecure context_token].sort
# rubocop:disable LineLength
arr = %w[default no_user empty_user context_ssl context_insecure context_token].sort
# rubocop:enable LineLength
expect(kube_config.list_context_names.sort).to eq(arr)
end
end
Expand Down
8 changes: 8 additions & 0 deletions kubernetes/spec/fixtures/config/kube_config_hash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@
'cluster' => 'default'
}
}.freeze
TEST_CONTEXT_EMPTY_USER = {
'name' => 'empty_user',
'context' => {
'cluster' => 'default',
'user' => ''
}
}.freeze
TEST_CONTEXT_SSL = {
'name' => 'context_ssl',
'context' => {
Expand Down Expand Up @@ -164,6 +171,7 @@
'contexts' => [
TEST_CONTEXT_DEFAULT,
TEST_CONTEXT_NO_USER,
TEST_CONTEXT_EMPTY_USER,
TEST_CONTEXT_SSL,
TEST_CONTEXT_TOKEN,
TEST_CONTEXT_INSECURE
Expand Down
6 changes: 4 additions & 2 deletions kubernetes/src/kubernetes/config/kube_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ def find_context(name)
if context['cluster']
context['cluster'] = find_cluster(context['cluster'])
end
context['user'] = find_user(context['user']) if context['user']
if context['user'] && !context['user'].empty?
context['user'] = find_user(context['user'])
end
end
end

Expand All @@ -162,7 +164,7 @@ def find_by_name(list, key, name)
obj = list.find { |item| item['name'] == name }
raise ConfigError, "#{key}: #{name} not found" unless obj

obj[key].dup
obj[key].dup if obj[key]
end
end
# rubocop:enable ClassLength
Expand Down