Skip to content

Commit

Permalink
feat: Add Support for Extra Hosts (#85)
Browse files Browse the repository at this point in the history
Signed-off-by: Shubharanshu Mahapatra <[email protected]>
  • Loading branch information
Shubhranshu153 authored Oct 31, 2024
1 parent 65fbf5a commit 5722300
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions api/handlers/container/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion api/handlers/container/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion api/types/container_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions e2e/tests/container_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5722300

Please sign in to comment.