From 62cf771ad6d95221c174c32185b1292e2f1d3d28 Mon Sep 17 00:00:00 2001 From: Shubharanshu Mahapatra Date: Thu, 31 Oct 2024 06:28:28 +0530 Subject: [PATCH] feat: Add Support for Extra Hosts Signed-off-by: Shubharanshu Mahapatra --- api/handlers/container/create.go | 1 + api/handlers/container/create_test.go | 4 +++- api/types/container_types.go | 2 +- e2e/tests/container_create.go | 1 + 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/api/handlers/container/create.go b/api/handlers/container/create.go index c59ae847..b4221735 100644 --- a/api/handlers/container/create.go +++ b/api/handlers/container/create.go @@ -221,6 +221,7 @@ func (h *handler) create(w http.ResponseWriter, r *http.Request) { DNSResolvConfOptions: dnsOpt, // DNS options. DNSSearchDomains: req.HostConfig.DNSSearch, // Custom DNS search domains. PortMappings: portMappings, + AddHost: req.HostConfig.ExtraHosts, // Extra hosts. } ctx := namespaces.WithNamespace(r.Context(), h.Config.Namespace) diff --git a/api/handlers/container/create_test.go b/api/handlers/container/create_test.go index 4a906003..9c5475cb 100644 --- a/api/handlers/container/create_test.go +++ b/api/handlers/container/create_test.go @@ -305,7 +305,8 @@ var _ = Describe("Container Create API ", func() { "HostConfig": { "DNS": ["8.8.8.8"], "DNSOptions": ["test-opt"], - "DNSSearch": ["test.com"] + "DNSSearch": ["test.com"], + "ExtraHosts": ["test-host:127.0.0.1"] } }`) req, _ := http.NewRequest(http.MethodPost, "/containers/create", bytes.NewReader(body)) @@ -315,6 +316,7 @@ var _ = Describe("Container Create API ", func() { netOpt.DNSServers = []string{"8.8.8.8"} netOpt.DNSResolvConfOptions = []string{"test-opt"} netOpt.DNSSearchDomains = []string{"test.com"} + netOpt.AddHost = []string{"test-host:127.0.0.1"} service.EXPECT().Create(gomock.Any(), "test-image", nil, equalTo(createOpt), equalTo(netOpt)).Return( cid, nil) diff --git a/api/types/container_types.go b/api/types/container_types.go index 7090117b..800431ef 100644 --- a/api/types/container_types.go +++ b/api/types/container_types.go @@ -76,7 +76,7 @@ type ContainerHostConfig struct { DNS []string `json:"Dns"` // List of DNS server to lookup DNSOptions []string `json:"DnsOptions"` // List of DNSOption to look for DNSSearch []string `json:"DnsSearch"` // List of DNSSearch to look for - // TODO: ExtraHosts []string // List of extra hosts + ExtraHosts []string // List of extra hosts // TODO: GroupAdd []string // List of additional groups that the container process will run as // TODO: IpcMode IpcMode // IPC namespace to use for the container // TODO: Cgroup CgroupSpec // Cgroup to use for the container diff --git a/e2e/tests/container_create.go b/e2e/tests/container_create.go index a4ebe38a..957ed215 100644 --- a/e2e/tests/container_create.go +++ b/e2e/tests/container_create.go @@ -438,6 +438,7 @@ func ContainerCreate(opt *option.Option) { options.HostConfig.DNS = []string{"8.8.8.8"} options.HostConfig.DNSOptions = []string{"test-opt"} options.HostConfig.DNSSearch = []string{"test.com"} + options.HostConfig.ExtraHosts = []string{"test-host:127.0.0.1"} // create container statusCode, ctr := createContainer(uClient, url, testContainerName, options)