Skip to content

Commit

Permalink
Merge pull request #1151 from KentaTada/add-time-namespac
Browse files Browse the repository at this point in the history
Add support for time namespace
  • Loading branch information
hqhq authored Feb 1, 2023
2 parents 0ff8cd9 + 36bb632 commit 7301c34
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 1 deletion.
16 changes: 16 additions & 0 deletions config-linux.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ The following parameters can be specified to set up namespaces:
* **`uts`** the container will be able to have its own hostname and domain name.
* **`user`** the container will be able to remap user and group IDs from the host to local users and groups within the container.
* **`cgroup`** the container will have an isolated view of the cgroup hierarchy.
* **`time`** the container will be able to have its own clocks.
* **`path`** *(string, OPTIONAL)* - namespace file.
This value MUST be an absolute path in the [runtime mount namespace](glossary.md#runtime-namespace).
The runtime MUST place the container process in the namespace associated with that `path`.
Expand Down Expand Up @@ -70,6 +71,9 @@ If a `namespaces` field contains duplicated namespaces with same `type`, the run
},
{
"type": "cgroup"
},
{
"type": "time"
}
]
```
Expand Down Expand Up @@ -107,6 +111,17 @@ Note that the number of mapping entries MAY be limited by the [kernel][user-name
]
```

## <a name="configLinuxTimeOffset" />Offset for Time Namespace

**`timeOffsets`** (object, OPTIONAL) sets the offset for Time Namespace. For more information
see the [time_namespaces](time_namespaces.7).

The name of the clock is the entry key.
Entry values are objects with the following properties:

* **`secs`** *(int64, OPTIONAL)* - is the offset of clock (in seconds) in the container.
* **`nanosecs`** *(uint32, OPTIONAL)* - is the offset of clock (in nanoseconds) in the container.

## <a name="configLinuxDevices" />Devices

**`devices`** (array of objects, OPTIONAL) lists devices that MUST be available in the container.
Expand Down Expand Up @@ -939,3 +954,4 @@ subset of the available options.
[zero.4]: http://man7.org/linux/man-pages/man4/zero.4.html
[user-namespaces]: http://man7.org/linux/man-pages/man7/user_namespaces.7.html
[intel-rdt-cat-kernel-interface]: https://www.kernel.org/doc/Documentation/x86/intel_rdt_ui.txt
[time_namespaces.7]: https://man7.org/linux/man-pages/man7/time_namespaces.7.html
13 changes: 13 additions & 0 deletions config.md
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,16 @@ Here is a full example `config.json` for reference.
}
]
},
"timeOffsets": {
"monotonic": {
"secs": 172800,
"nanosecs": 0
},
"boottime": {
"secs": 604800,
"nanosecs": 0
}
},
"namespaces": [
{
"type": "pid"
Expand All @@ -949,6 +959,9 @@ Here is a full example `config.json` for reference.
},
{
"type": "cgroup"
},
{
"type": "time"
}
],
"maskedPaths": [
Expand Down
6 changes: 6 additions & 0 deletions schema/config-linux.json
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,12 @@
"personality": {
"type": "object",
"$ref": "defs-linux.json#/definitions/Personality"
},
"timeOffsets": {
"type": "object",
"additionalProperties": {
"$ref": "defs-linux.json#/definitions/TimeOffsets"
}
}
}
}
Expand Down
14 changes: 13 additions & 1 deletion schema/defs-linux.json
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,8 @@
"uts",
"ipc",
"user",
"cgroup"
"cgroup",
"time"
]
},
"NamespaceReference": {
Expand All @@ -311,6 +312,17 @@
"required": [
"type"
]
},
"TimeOffsets": {
"type": "object",
"properties": {
"secs": {
"$ref": "defs.json#/definitions/int64"
},
"nanosecs": {
"$ref": "defs.json#/definitions/uint32"
}
}
}
}
}
13 changes: 13 additions & 0 deletions schema/test/config/good/spec-example.json
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,16 @@
}
]
},
"timeOffsets": {
"monotonic": {
"secs": 172800,
"nanosecs": 0
},
"boottime": {
"secs": 604800,
"nanosecs": 0
}
},
"namespaces": [
{
"type": "pid"
Expand All @@ -373,6 +383,9 @@
},
{
"type": "cgroup"
},
{
"type": "time"
}
],
"maskedPaths": [
Expand Down
12 changes: 12 additions & 0 deletions specs-go/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ type Linux struct {
IntelRdt *LinuxIntelRdt `json:"intelRdt,omitempty"`
// Personality contains configuration for the Linux personality syscall
Personality *LinuxPersonality `json:"personality,omitempty"`
// TimeOffsets specifies the offset for supporting time namespaces.
TimeOffsets map[string]LinuxTimeOffset `json:"timeOffsets,omitempty"`
}

// LinuxNamespace is the configuration for a Linux namespace
Expand Down Expand Up @@ -220,6 +222,8 @@ const (
UserNamespace LinuxNamespaceType = "user"
// CgroupNamespace for isolating cgroup hierarchies
CgroupNamespace LinuxNamespaceType = "cgroup"
// TimeNamespace for isolating the clocks
TimeNamespace LinuxNamespaceType = "time"
)

// LinuxIDMapping specifies UID/GID mappings
Expand All @@ -232,6 +236,14 @@ type LinuxIDMapping struct {
Size uint32 `json:"size"`
}

// LinuxTimeOffset specifies the offset for Time Namespace
type LinuxTimeOffset struct {
// Secs is the offset of clock (in secs) in the container
Secs int64 `json:"secs,omitempty"`
// Nanosecs is the additional offset for Secs (in nanosecs)
Nanosecs uint32 `json:"nanosecs,omitempty"`
}

// POSIXRlimit type and restrictions
type POSIXRlimit struct {
// Type of the rlimit to set
Expand Down

0 comments on commit 7301c34

Please sign in to comment.