-
Notifications
You must be signed in to change notification settings - Fork 38.7k
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
write HostAliases to hosts file #45148
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,12 +119,14 @@ func TestHostsFileContent(t *testing.T) { | |
hostIP string | ||
hostName string | ||
hostDomainName string | ||
hostAliases []v1.HostAlias | ||
expectedContent string | ||
}{ | ||
{ | ||
"123.45.67.89", | ||
"podFoo", | ||
"", | ||
[]v1.HostAlias{}, | ||
`# Kubernetes-managed hosts file. | ||
127.0.0.1 localhost | ||
::1 localhost ip6-localhost ip6-loopback | ||
|
@@ -139,6 +141,7 @@ fe00::2 ip6-allrouters | |
"203.0.113.1", | ||
"podFoo", | ||
"domainFoo", | ||
[]v1.HostAlias{}, | ||
`# Kubernetes-managed hosts file. | ||
127.0.0.1 localhost | ||
::1 localhost ip6-localhost ip6-loopback | ||
|
@@ -147,12 +150,56 @@ fe00::0 ip6-mcastprefix | |
fe00::1 ip6-allnodes | ||
fe00::2 ip6-allrouters | ||
203.0.113.1 podFoo.domainFoo podFoo | ||
`, | ||
}, | ||
{ | ||
"203.0.113.1", | ||
"podFoo", | ||
"domainFoo", | ||
[]v1.HostAlias{ | ||
{IP: "123.45.67.89", Hostnames: []string{"foo", "bar", "baz"}}, | ||
}, | ||
`# Kubernetes-managed hosts file. | ||
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 | ||
203.0.113.1 podFoo.domainFoo podFoo | ||
123.45.67.89 foo | ||
123.45.67.89 bar | ||
123.45.67.89 baz | ||
`, | ||
}, | ||
{ | ||
"203.0.113.1", | ||
"podFoo", | ||
"domainFoo", | ||
[]v1.HostAlias{ | ||
{IP: "123.45.67.89", Hostnames: []string{"foo", "bar", "baz"}}, | ||
{IP: "456.78.90.123", Hostnames: []string{"park", "doo", "boo"}}, | ||
}, | ||
`# Kubernetes-managed hosts file. | ||
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 | ||
203.0.113.1 podFoo.domainFoo podFoo | ||
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 | ||
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. should we add validation that there are not duplicate hostnames in case someone adds: []v1.HostAlias{
{IP: "123.45.67.89", Hostnames: []string{"foo", "bar"}},
{IP: "456.78.90.123", Hostnames: []string{"foo", "bar"}},
} which results in
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. And shouldn't we validate for proper IPv4 IPs? :-) 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. 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. I think dups is fine - it's your own fault. |
||
`, | ||
}, | ||
} | ||
|
||
for _, testCase := range testCases { | ||
actualContent := string(hostsFileContent(testCase.hostIP, testCase.hostName, testCase.hostDomainName)) | ||
actualContent := string(hostsFileContent(testCase.hostIP, testCase.hostName, testCase.hostDomainName, testCase.hostAliases)) | ||
assert.Equal(t, testCase.expectedContent, actualContent, "hosts file content not expected") | ||
} | ||
} | ||
|
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.
Comment that this was previously validated to be a valid IP address and hostname?