Skip to content

Add time namespace / TimeOffsets check and helper #784

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions generate/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ func (g *Generator) initConfigLinuxIntelRdt() {
}
}

func (g *Generator) initConfigLinuxTimeOffsets() {
g.initConfigLinux()
if g.Config.Linux.TimeOffsets == nil {
g.Config.Linux.TimeOffsets = map[string]rspec.LinuxTimeOffset{}
}
}

func (g *Generator) initConfigLinuxSysctl() {
g.initConfigLinux()
if g.Config.Linux.Sysctl == nil {
Expand Down
10 changes: 9 additions & 1 deletion generate/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

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

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

// SetLinuxTimeOffset sets g.Config.Linux.TimeOffsets[clock]
func (g *Generator) SetLinuxTimeOffset(clock string, offset rspec.LinuxTimeOffset) {
g.initConfigLinuxTimeOffsets()
g.Config.Linux.TimeOffsets[clock] = offset
}

// SetLinuxMountLabel sets g.Config.Linux.MountLabel.
func (g *Generator) SetLinuxMountLabel(label string) {
g.initConfigLinux()
Expand Down Expand Up @@ -1479,6 +1485,8 @@ func mapStrToNamespace(ns string, path string) (rspec.LinuxNamespace, error) {
return rspec.LinuxNamespace{Type: rspec.UserNamespace, Path: path}, nil
case "cgroup":
return rspec.LinuxNamespace{Type: rspec.CgroupNamespace, Path: path}, nil
case "time":
return rspec.LinuxNamespace{Type: rspec.TimeNamespace, Path: path}, nil
default:
return rspec.LinuxNamespace{}, fmt.Errorf("unrecognized namespace %q", ns)
}
Expand Down
5 changes: 5 additions & 0 deletions validate/validate_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func (v *Validator) CheckLinux() (errs error) {
rspec.UTSNamespace: {0, false},
rspec.UserNamespace: {0, false},
rspec.CgroupNamespace: {0, false},
rspec.TimeNamespace: {0, false},
}

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

if !nsTypeList[rspec.TimeNamespace].newExist && len(v.spec.Linux.TimeOffsets) > 0 {
errs = multierror.Append(errs, fmt.Errorf("TimeOffsets requires a new time namespace to be specified as well"))
}

// Linux devices validation
devList := make(map[string]bool)
devTypeList := make(map[string]bool)
Expand Down