-
Notifications
You must be signed in to change notification settings - Fork 40k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support HostAlias for HostNetwork Pods #50646
Merged
k8s-github-robot
merged 3 commits into
kubernetes:master
from
evie404:rpai/hostalias_hostnetwork
Aug 24, 2017
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -184,11 +184,23 @@ func TestMakeMounts(t *testing.T) { | |
|
||
func TestNodeHostsFileContent(t *testing.T) { | ||
testCases := []struct { | ||
hostsFileName string | ||
expectedContent string | ||
hostsFileName string | ||
hostAliases []v1.HostAlias | ||
rawHostsFileContent string | ||
expectedHostsFileContent string | ||
}{ | ||
{ | ||
"hosts_test_file1", | ||
[]v1.HostAlias{}, | ||
`# hosts file for testing. | ||
127.0.0.1 localhost | ||
::1 localhost ip6-localhost ip6-loopback | ||
fe00::0 ip6-localnet | ||
fe00::0 ip6-mcastprefix | ||
fe00::1 ip6-allnodes | ||
fe00::2 ip6-allrouters | ||
123.45.67.89 some.domain | ||
`, | ||
`# hosts file for testing. | ||
127.0.0.1 localhost | ||
::1 localhost ip6-localhost ip6-loopback | ||
|
@@ -201,6 +213,70 @@ fe00::2 ip6-allrouters | |
}, | ||
{ | ||
"hosts_test_file2", | ||
[]v1.HostAlias{}, | ||
`# another hosts file for testing. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to this test? It's already tested in above? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tests different file path just to be exhaustive |
||
127.0.0.1 localhost | ||
::1 localhost ip6-localhost ip6-loopback | ||
fe00::0 ip6-localnet | ||
fe00::0 ip6-mcastprefix | ||
fe00::1 ip6-allnodes | ||
fe00::2 ip6-allrouters | ||
12.34.56.78 another.domain | ||
`, | ||
`# another hosts file for testing. | ||
127.0.0.1 localhost | ||
::1 localhost ip6-localhost ip6-loopback | ||
fe00::0 ip6-localnet | ||
fe00::0 ip6-mcastprefix | ||
fe00::1 ip6-allnodes | ||
fe00::2 ip6-allrouters | ||
12.34.56.78 another.domain | ||
`, | ||
}, | ||
{ | ||
"hosts_test_file1_with_host_aliases", | ||
[]v1.HostAlias{ | ||
{IP: "123.45.67.89", Hostnames: []string{"foo", "bar", "baz"}}, | ||
}, | ||
`# hosts file for testing. | ||
127.0.0.1 localhost | ||
::1 localhost ip6-localhost ip6-loopback | ||
fe00::0 ip6-localnet | ||
fe00::0 ip6-mcastprefix | ||
fe00::1 ip6-allnodes | ||
fe00::2 ip6-allrouters | ||
123.45.67.89 some.domain | ||
`, | ||
`# hosts file for testing. | ||
127.0.0.1 localhost | ||
::1 localhost ip6-localhost ip6-loopback | ||
fe00::0 ip6-localnet | ||
fe00::0 ip6-mcastprefix | ||
fe00::1 ip6-allnodes | ||
fe00::2 ip6-allrouters | ||
123.45.67.89 some.domain | ||
|
||
# Entries added by HostAliases. | ||
123.45.67.89 foo | ||
123.45.67.89 bar | ||
123.45.67.89 baz | ||
`, | ||
}, | ||
{ | ||
"hosts_test_file2_with_host_aliases", | ||
[]v1.HostAlias{ | ||
{IP: "123.45.67.89", Hostnames: []string{"foo", "bar", "baz"}}, | ||
{IP: "456.78.90.123", Hostnames: []string{"park", "doo", "boo"}}, | ||
}, | ||
`# another hosts file for testing. | ||
127.0.0.1 localhost | ||
::1 localhost ip6-localhost ip6-loopback | ||
fe00::0 ip6-localnet | ||
fe00::0 ip6-mcastprefix | ||
fe00::1 ip6-allnodes | ||
fe00::2 ip6-allrouters | ||
12.34.56.78 another.domain | ||
`, | ||
`# another hosts file for testing. | ||
127.0.0.1 localhost | ||
::1 localhost ip6-localhost ip6-loopback | ||
|
@@ -209,18 +285,26 @@ fe00::0 ip6-mcastprefix | |
fe00::1 ip6-allnodes | ||
fe00::2 ip6-allrouters | ||
12.34.56.78 another.domain | ||
|
||
# Entries added by HostAliases. | ||
123.45.67.89 foo | ||
123.45.67.89 bar | ||
123.45.67.89 baz | ||
456.78.90.123 park | ||
456.78.90.123 doo | ||
456.78.90.123 boo | ||
`, | ||
}, | ||
} | ||
|
||
for _, testCase := range testCases { | ||
tmpdir, err := writeHostsFile(testCase.hostsFileName, testCase.expectedContent) | ||
tmpdir, err := writeHostsFile(testCase.hostsFileName, testCase.rawHostsFileContent) | ||
require.NoError(t, err, "could not create a temp hosts file") | ||
defer os.RemoveAll(tmpdir) | ||
|
||
actualContent, fileReadErr := nodeHostsFileContent(filepath.Join(tmpdir, testCase.hostsFileName)) | ||
actualContent, fileReadErr := nodeHostsFileContent(filepath.Join(tmpdir, testCase.hostsFileName), testCase.hostAliases) | ||
require.NoError(t, fileReadErr, "could not create read hosts file") | ||
assert.Equal(t, testCase.expectedContent, string(actualContent), "hosts file content not expected") | ||
assert.Equal(t, testCase.expectedHostsFileContent, string(actualContent), "hosts file content not expected") | ||
} | ||
} | ||
|
||
|
@@ -287,6 +371,8 @@ fe00::0 ip6-mcastprefix | |
fe00::1 ip6-allnodes | ||
fe00::2 ip6-allrouters | ||
203.0.113.1 podFoo.domainFoo podFoo | ||
|
||
# Entries added by HostAliases. | ||
123.45.67.89 foo | ||
123.45.67.89 bar | ||
123.45.67.89 baz | ||
|
@@ -308,6 +394,8 @@ fe00::0 ip6-mcastprefix | |
fe00::1 ip6-allnodes | ||
fe00::2 ip6-allrouters | ||
203.0.113.1 podFoo.domainFoo podFoo | ||
|
||
# Entries added by HostAliases. | ||
123.45.67.89 foo | ||
123.45.67.89 bar | ||
123.45.67.89 baz | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test seems to be only testing
nodeHostsFileContent()
?Any test to verify that
hostNetwork=true
hostAlias ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in
ensureHostsFile
,nodeHostsFileContent
is only called whenhostNetwork=true
. so this is already testing the case.