Skip to content

Commit 658737c

Browse files
committed
jail: add support for hostname
1 parent 91221a1 commit 658737c

6 files changed

Lines changed: 45 additions & 17 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ runj currently supports the following parts of the OCI runtime spec:
2727
- Process args
2828
- Process environment
2929
- Process terminal
30+
- Hostname
3031
- Mounts
3132

3233
## Getting started

cmd/runj/create.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,9 @@ written`)
162162
}
163163
var confPath string
164164
confPath, err = jail.CreateConfig(&jail.Config{
165-
Name: id,
166-
Root: rootPath,
165+
Name: id,
166+
Root: rootPath,
167+
Hostname: ociConfig.Hostname,
167168
})
168169
if err != nil {
169170
return err

jail/conf.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ const (
1414
confName = "jail.conf"
1515
configTemplate = `{{ .Name }} {
1616
path = "{{ .Root }}";
17+
{{- if ne .Hostname "" }}
18+
host.hostname = "{{.Hostname}}";
19+
{{- end }}
1720
persist;
1821
}
1922
`

jail/conf_test.go

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,40 @@
11
package jail
22

33
import (
4+
"fmt"
45
"io/ioutil"
6+
"path/filepath"
57
"testing"
68

79
"github.com/stretchr/testify/assert"
810
)
911

10-
func TestRenderConfigBasic(t *testing.T) {
11-
const (
12-
id = "basic"
13-
path = "/tmp/test/basic/root"
14-
)
15-
expected, err := ioutil.ReadFile("testdata/basic.conf")
16-
assert.NoError(t, err, "test data")
17-
actual, err := renderConfig(&Config{Name: id, Root: path})
18-
assert.NoError(t, err, "render")
19-
assert.Equal(t, string(expected), actual)
12+
func TestRenderConfigGolden(t *testing.T) {
13+
tests := []struct {
14+
// name is both used as the subtest name and is the name of the golden data file in testdata
15+
name string
16+
config Config
17+
}{{
18+
"basic",
19+
Config{
20+
Name: "basic",
21+
Root: "/tmp/test/basic/root",
22+
},
23+
}, {
24+
"hostname",
25+
Config{
26+
Name: "hostname",
27+
Root: "/tmp/test/hostname/root",
28+
Hostname: "test.hostname.example.com",
29+
},
30+
}}
31+
for _, tc := range tests {
32+
t.Run(tc.name, func(t *testing.T) {
33+
expected, err := ioutil.ReadFile(filepath.Join("testdata", fmt.Sprintf("%s.conf", tc.name)))
34+
assert.NoError(t, err, "test data")
35+
actual, err := renderConfig(&tc.config)
36+
assert.NoError(t, err, "render")
37+
assert.Equal(t, string(expected), actual)
38+
})
39+
}
2040
}

jail/testdata/hostname.conf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
hostname {
2+
path = "/tmp/test/hostname/root";
3+
host.hostname = "test.hostname.example.com";
4+
persist;
5+
}

runtimespec/config.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,9 @@ type Spec struct {
3030
// Root configures the container's root filesystem.
3131
Root *Root `json:"root,omitempty"`
3232

33-
// Modification by Samuel Karp
34-
/*
35-
// Hostname configures the container's hostname.
36-
Hostname string `json:"hostname,omitempty"`
37-
*/
33+
// Hostname configures the container's hostname.
34+
Hostname string `json:"hostname,omitempty"`
35+
3836
// Mounts configures additional mounts (on top of Root).
3937
Mounts []Mount `json:"mounts,omitempty"`
4038
/*

0 commit comments

Comments
 (0)