Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
Signed-off-by: Ziwen Ning <ningziwe@amazon.com>
  • Loading branch information
ningziwen committed Feb 20, 2023
1 parent c818c73 commit 3b653ea
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 8 deletions.
8 changes: 2 additions & 6 deletions cmd/nerdctl/container_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -716,14 +716,10 @@ func createContainer(ctx context.Context, cmd *cobra.Command, client *containerd
// If the IP Address is a string called "host-gateway", replace this value with the IP address stored
// in the daemon level HostGateway IP config variable.
if parts[1] == dockerops.HostGatewayName {
gateway, err := cmd.Flags().GetString("host-gateway-ip")
if err != nil {
return nil, nil, err
}
if gateway == "" {
if globalOptions.HostGatewayIP == "" {
return nil, nil, fmt.Errorf("unable to derive the IP value for host-gateway")
}
parts[1] = gateway
parts[1] = globalOptions.HostGatewayIP
extraHosts[i] = fmt.Sprintf(`%s:%s`, parts[0], parts[1])
}
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/nerdctl/container_run_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func TestRunAddHost(t *testing.T) {
s := http.Server{Addr: fmt.Sprintf(":%d", hostPort), Handler: nil, ReadTimeout: 30 * time.Second}
go s.ListenAndServe()
defer s.Shutdown(context.Background())
base.Cmd("run", "--rm", "--add-host", "test:host-gateway", testutil.AmazonLinux2Image, "curl", fmt.Sprintf("test:%d", hostPort)).AssertOutExactly(response)
base.Cmd("run", "--rm", "--add-host", "test:host-gateway", testutil.NginxAlpineImage, "curl", fmt.Sprintf("test:%d", hostPort)).AssertOutExactly(response)
}

func TestRunAddHostWithCustomHostGatewayIP(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions pkg/defaults/defaults_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ func HostsDirs() []string {
}
}

// HostGatewayIP returns the non-loop-back host ip if available and returns empty string if running into error.
func HostGatewayIP() string {
addrs, err := net.InterfaceAddrs()
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion pkg/testutil/testutil_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ func mirrorOf(s string) string {

var (
AlpineImage = mirrorOf("alpine:3.13")
AmazonLinux2Image = "public.ecr.aws/amazonlinux/amazonlinux:2"
NginxAlpineImage = mirrorOf("nginx:1.19-alpine")
NginxAlpineIndexHTMLSnippet = "<title>Welcome to nginx!</title>"
RegistryImage = mirrorOf("registry:2")
Expand Down

0 comments on commit 3b653ea

Please sign in to comment.