refactor entries added by hostAlias into a separate method and be explicit about the source

This commit is contained in:
Ricky Pai 2017-08-14 14:37:27 -07:00
parent a4996c99d4
commit ceb33bde29
2 changed files with 17 additions and 0 deletions

View File

@ -266,6 +266,19 @@ func managedHostsFileContent(hostIP, hostName, hostDomainName string, hostAliase
} else { } else {
buffer.WriteString(fmt.Sprintf("%s\t%s\n", hostIP, hostName)) buffer.WriteString(fmt.Sprintf("%s\t%s\n", hostIP, hostName))
} }
hostsFileContent := buffer.Bytes()
hostsFileContent = append(hostsFileContent, hostsEntriesFromHostAliases(hostAliases)...)
return hostsFileContent
}
func hostsEntriesFromHostAliases(hostAliases []v1.HostAlias) []byte {
if len(hostAliases) == 0 {
return []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 // write each IP/hostname pair as an entry into hosts file
for _, hostAlias := range hostAliases { for _, hostAlias := range hostAliases {
for _, hostname := range hostAlias.Hostnames { for _, hostname := range hostAlias.Hostnames {

View File

@ -287,6 +287,8 @@ fe00::0 ip6-mcastprefix
fe00::1 ip6-allnodes fe00::1 ip6-allnodes
fe00::2 ip6-allrouters fe00::2 ip6-allrouters
203.0.113.1 podFoo.domainFoo podFoo 203.0.113.1 podFoo.domainFoo podFoo
# Entries added by HostAliases.
123.45.67.89 foo 123.45.67.89 foo
123.45.67.89 bar 123.45.67.89 bar
123.45.67.89 baz 123.45.67.89 baz
@ -308,6 +310,8 @@ fe00::0 ip6-mcastprefix
fe00::1 ip6-allnodes fe00::1 ip6-allnodes
fe00::2 ip6-allrouters fe00::2 ip6-allrouters
203.0.113.1 podFoo.domainFoo podFoo 203.0.113.1 podFoo.domainFoo podFoo
# Entries added by HostAliases.
123.45.67.89 foo 123.45.67.89 foo
123.45.67.89 bar 123.45.67.89 bar
123.45.67.89 baz 123.45.67.89 baz