Merge pull request #69303 from appian/host_aliases_on_same_line

Write HostAliases aliases on same line per host IP
This commit is contained in:
k8s-ci-robot 2018-11-15 14:59:52 -08:00 committed by GitHub
commit e4ee887121
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 23 deletions

View File

@ -356,11 +356,9 @@ func hostsEntriesFromHostAliases(hostAliases []v1.HostAlias) []byte {
var buffer bytes.Buffer
buffer.WriteString("\n")
buffer.WriteString("# Entries added by HostAliases.\n")
// write each IP/hostname pair as an entry into hosts file
// for each IP, write all aliases onto single line in hosts file
for _, hostAlias := range hostAliases {
for _, hostname := range hostAlias.Hostnames {
buffer.WriteString(fmt.Sprintf("%s\t%s\n", hostAlias.IP, hostname))
}
buffer.WriteString(fmt.Sprintf("%s\t%s\n", hostAlias.IP, strings.Join(hostAlias.Hostnames, "\t")))
}
return buffer.Bytes()
}

View File

@ -183,9 +183,7 @@ 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
123.45.67.89 foo bar baz
`,
},
{
@ -214,12 +212,8 @@ 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
123.45.67.89 foo bar baz
456.78.90.123 park doo boo
`,
},
}
@ -300,9 +294,7 @@ 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
123.45.67.89 foo bar baz
`,
},
{
@ -323,12 +315,8 @@ 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
456.78.90.123 park
456.78.90.123 doo
456.78.90.123 boo
123.45.67.89 foo bar baz
456.78.90.123 park doo boo
`,
},
}

View File

@ -175,7 +175,7 @@ var _ = framework.KubeDescribe("Kubelet", func() {
buf.ReadFrom(rc)
hostsFileContent := buf.String()
if !strings.Contains(hostsFileContent, "123.45.67.89\tfoo") || !strings.Contains(hostsFileContent, "123.45.67.89\tbar") {
if !strings.Contains(hostsFileContent, "123.45.67.89\tfoo\tbar") {
return fmt.Errorf("expected hosts file to contain entries from HostAliases. Got:\n%+v", hostsFileContent)
}