Change:
} } <del> func TestHostsFileContent(t *testing.T) { </del> <ins> func TestNodeHostsFileContent(t *testing.T) { testCases := []struct { hostsFileName   string expectedContent string }{ { "hosts_test_file1", `# 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_test_file2", `# 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 `, }, } for _, testCase := range testCases { tmpdir, err := writeHostsFile(testCase.hostsFileName, testCase.expectedContent) require.NoError(t, err, "could not create a temp hosts file") defer os.RemoveAll(tmpdir) actualContent, fileReadErr := nodeHostsFileContent(filepath.Join(tmpdir, testCase.hostsFileName)) require.NoError(t, fileReadErr, "could not create read hosts file") assert.Equal(t, testCase.expectedContent, string(actualContent), "hosts file content not expected") } } // writeHostsFile will write a hosts file into a temporary dir, and return that dir. // Caller is responsible for deleting the dir and its contents. func writeHostsFile(filename string, cfg string) (string, error) { tmpdir, err := ioutil.TempDir("", "kubelet=kubelet_pods_test.go=") if err != nil { return "", err } return tmpdir, ioutil.WriteFile(filepath.Join(tmpdir, filename), []byte(cfg), 0644) } func TestManagedHostsFileContent(t *testing.T) { </ins> testCases := []struct { hostIP          string hostName        string

Discussion:
Currently, kubelet mounts hosts file for pods. For hostNetwork pods, the behavior is different and instead, kubelet relies on docker (or whatever container runtime) to mount the host's hosts file. We should have kubelet handle hosts file for hostNetwork pods. This would have several benefits: control over hosts file in case the container runtime does something consistent behavior between hostNetwork and non-hostNetwork pods consistent behavior between different container runtimes -managed hosts file enables features like to be used for hostNetwork pods Implementation would require: kubelet's or its caller output different content based on hostNetwork. i. If it's not hostNetwork, use existing behavior. ii. If it's using hostNetwork, read the content from the host's hosts file. hostNetwork constraint in deciding whether to mount the file Open Questions: do we treat changes to the host's hosts file? should the file's content be static between container restarts of the same Pod? or should every container restart pick up the latest content of the hosts file? the former seems better for consistency, but letter might be more in line with other features that use host resources like host volumes. condition to manage hosts file also excludes windows even though windows also the use of hosts file and the same format. seems like this should be supported also. windows-support ships, should it have validation against windows platform? the tricky bit is the client, API, and minions' kubelet may be running on different platforms, and currently, there's no precedence to platform validation. /kind feature /sig node