Skip to content

Commit

Permalink
Return error on missing host-gateway IP
Browse files Browse the repository at this point in the history
Signed-off-by: Gregor Eichelberger <[email protected]>
  • Loading branch information
geichelberger committed Jul 19, 2023
1 parent 870255d commit 9d93afa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions libnetwork/etchosts/hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,9 @@ func parseExtraHosts(extraHosts []string, hostContainersInternalIP string) (Host
}
ip := values[1]
if values[1] == HostGateway {
if hostContainersInternalIP == "" {
return nil, fmt.Errorf("unable to replace %q of host entry %q: host containers internal IP address is empty", HostGateway, entry)
}
ip = hostContainersInternalIP
}
e := HostEntry{IP: ip, Names: []string{values[0]}}
Expand Down
6 changes: 6 additions & 0 deletions libnetwork/etchosts/hosts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,12 @@ func TestNew(t *testing.T) {
extraHosts: []string{"name"},
wantErrString: "unable to parse host entry \"name\": incorrect format",
},
{
name: "invalid host-gateway",
baseFileContent: baseFileContent1Spaces,
extraHosts: []string{"gatewayname:host-gateway"},
wantErrString: "host containers internal IP address is empty",
},
}

for _, tt := range tests {
Expand Down

0 comments on commit 9d93afa

Please sign in to comment.