Skip to content

Commit 5a6139a

Browse files
authored
Fix issue where container IP is occasionally empty for Kubernetes pods in HostNetwork mode (#1280)
This patch addresses a problem where the hostname specified in the hostname file does not match the entry in the etc-hosts file when using Kubernetes HostNetwork mode. The mismatch leads to scenarios where the container IP is retrieved as empty. To resolve this issue, the fix implements a check to compare the container's hostname against the daemon's hostname when HostNetwork mode is enabled. If they are identical, the container will inherit the daemon's IP address, ensuring consistency and preventing the container's IP from being empty. This adjustment ensures reliable IP address assignment and mitigates the risk of networking issues within the Kubernetes cluster.
1 parent c6f96d2 commit 5a6139a

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

pkg/helper/docker_center.go

+3
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,9 @@ func getIPByHosts(hostFileName, hostname string) string {
476476
return util.ReadFirstBlock(line)
477477
}
478478
}
479+
if util.GetHostName() == hostname {
480+
return util.GetIPAddress()
481+
}
479482
return ""
480483
}
481484

0 commit comments

Comments
 (0)