This repository has been archived by the owner on Feb 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* allows externalTrafficPolicy=local to work with AWS [#157044566] Signed-off-by: Iain Sproat <[email protected]>
- Loading branch information
1 parent
86151d5
commit 9dc273c
Showing
3 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
<% require 'yaml' %><%= p('kube-proxy-configuration').to_yaml %> | ||
hostnameOverride: HOSTNAMEOVERRIDE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rspec' | ||
require 'spec_helper' | ||
require 'fileutils' | ||
require 'open3' | ||
|
||
def run_get_hostname_override(rendered_contents, executable_path) | ||
File.open(executable_path, 'w', 0o777) do |f| | ||
f.write(rendered_contents) | ||
end | ||
|
||
# exercise bash function by first changing path for any necessary executables to our mocks | ||
cmd = format('PATH=%<dirname>s:%<env_path>s /bin/bash -c "source %<exe>s && get_hostname_override"', | ||
dirname: File.dirname(executable_path), env_path: ENV['PATH'], exe: executable_path) | ||
# capturing stderr (ignored) prevents expected warnings from showing up in test console | ||
result, = Open3.capture3(cmd) | ||
result | ||
end | ||
|
||
describe 'kube-proxy can set hostnameOverride' do | ||
let(:config_properties) do | ||
{ | ||
'kube-proxy-configuration' => { 'mode': 'iptables' } | ||
} | ||
end | ||
let(:rendered_template) { compiled_template('kube-proxy', 'config/config.yml', config_properties, {}) } | ||
|
||
# Check that the config file has HOSTNAMEOVERRIDE so that start script can find | ||
# and replace it at runtime | ||
it 'kube-proxy config has HOSTNAMEOVERRIDE key word' do | ||
expect(rendered_template).to include('HOSTNAMEOVERRIDE') | ||
end | ||
end | ||
|
||
describe 'kube_proxy_ctl setting of hostnameOverride property' do | ||
let(:test_context) do | ||
mock_dir = '/tmp/kube_proxy_mock' | ||
FileUtils.remove_dir(mock_dir, true) | ||
FileUtils.mkdir(mock_dir) | ||
kube_proxy_ctl_file = mock_dir + '/kube_proxy_ctl' | ||
|
||
{ 'mock_dir' => mock_dir, 'kube_proxy_ctl_file' => kube_proxy_ctl_file } | ||
end | ||
after(:each) do | ||
FileUtils.remove_dir(test_context['mock_dir'], true) | ||
end | ||
|
||
describe 'when cloud-provider is AWS' do | ||
it 'sets hostname_override to aws container hostname' do | ||
expected_aws_hostname = 'foohost.aws.internal' | ||
|
||
echo_mock_file = test_context['mock_dir'] + '/curl' | ||
File.open(echo_mock_file, 'w', 0o777) do |f| | ||
f.write("#!/bin/bash\n") | ||
f.write("echo #{expected_aws_hostname}") | ||
end | ||
|
||
test_link = { 'cloud-provider' => { | ||
'instances' => [], | ||
'properties' => { | ||
'cloud-provider' => { | ||
'type' => 'aws', | ||
} | ||
} | ||
} } | ||
rendered_kube_proxy_ctl = compiled_template('kube-proxy', 'bin/kube_proxy_ctl', { 'cloud-provider' => 'aws' }, test_link) | ||
result = run_get_hostname_override(rendered_kube_proxy_ctl, test_context['kube_proxy_ctl_file']) | ||
|
||
expect(result).to include(expected_aws_hostname) | ||
end | ||
end | ||
end |