Skip to content

Commit 6072004

Browse files
committed
Add time namespace / TimeOffsets check and helper
Signed-off-by: Etienne Champetier <[email protected]>
1 parent 0ea5ed0 commit 6072004

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

generate/config.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ func (g *Generator) initConfigLinuxIntelRdt() {
6666
}
6767
}
6868

69+
func (g *Generator) initConfigLinuxTimeOffsets() {
70+
g.initConfigLinux()
71+
if g.Config.Linux.TimeOffsets == nil {
72+
g.Config.Linux.TimeOffsets = map[string]rspec.LinuxTimeOffset{}
73+
}
74+
}
75+
6976
func (g *Generator) initConfigLinuxSysctl() {
7077
g.initConfigLinux()
7178
if g.Config.Linux.Sysctl == nil {

generate/generate.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616

1717
var (
1818
// Namespaces include the names of supported namespaces.
19-
Namespaces = []string{"network", "pid", "mount", "ipc", "uts", "user", "cgroup"}
19+
Namespaces = []string{"network", "pid", "mount", "ipc", "uts", "user", "cgroup", "time"}
2020

2121
// we don't care about order...and this is way faster...
2222
removeFunc = func(s []string, i int) []string {
@@ -627,6 +627,12 @@ func (g *Generator) SetLinuxIntelRdtL3CacheSchema(schema string) {
627627
g.Config.Linux.IntelRdt.L3CacheSchema = schema
628628
}
629629

630+
// SetLinuxTimeOffset sets g.Config.Linux.TimeOffsets[clock]
631+
func (g *Generator) SetLinuxTimeOffset(clock string, offset rspec.LinuxTimeOffset) {
632+
g.initConfigLinuxTimeOffsets()
633+
g.Config.Linux.TimeOffsets[clock] = offset
634+
}
635+
630636
// SetLinuxMountLabel sets g.Config.Linux.MountLabel.
631637
func (g *Generator) SetLinuxMountLabel(label string) {
632638
g.initConfigLinux()
@@ -1479,6 +1485,8 @@ func mapStrToNamespace(ns string, path string) (rspec.LinuxNamespace, error) {
14791485
return rspec.LinuxNamespace{Type: rspec.UserNamespace, Path: path}, nil
14801486
case "cgroup":
14811487
return rspec.LinuxNamespace{Type: rspec.CgroupNamespace, Path: path}, nil
1488+
case "time":
1489+
return rspec.LinuxNamespace{Type: rspec.TimeNamespace, Path: path}, nil
14821490
default:
14831491
return rspec.LinuxNamespace{}, fmt.Errorf("unrecognized namespace %q", ns)
14841492
}

validate/validate_linux.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ func (v *Validator) CheckLinux() (errs error) {
5454
rspec.UTSNamespace: {0, false},
5555
rspec.UserNamespace: {0, false},
5656
rspec.CgroupNamespace: {0, false},
57+
rspec.TimeNamespace: {0, false},
5758
}
5859

5960
for index := 0; index < len(v.spec.Linux.Namespaces); index++ {
@@ -93,6 +94,10 @@ func (v *Validator) CheckLinux() (errs error) {
9394
errs = multierror.Append(errs, fmt.Errorf("on Linux, hostname requires a new UTS namespace to be specified as well"))
9495
}
9596

97+
if !nsTypeList[rspec.TimeNamespace].newExist && len(v.spec.Linux.TimeOffsets) > 0 {
98+
errs = multierror.Append(errs, fmt.Errorf("TimeOffsets requires a new time namespace to be specified as well"))
99+
}
100+
96101
// Linux devices validation
97102
devList := make(map[string]bool)
98103
devTypeList := make(map[string]bool)

0 commit comments

Comments
 (0)