Skip to content
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

Add support for time namespace #1151

Merged
merged 1 commit into from
Feb 1, 2023
Merged
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
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 @@ -770,3 +785,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 @@ -905,6 +905,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 @@ -926,6 +936,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 @@ -253,6 +253,12 @@
"personality": {
"type": "object",
"$ref": "defs-linux.json#/definitions/Personality"
},
"timeOffsets": {
"type": "object",
"additionalProperties": {
"$ref": "defs-linux.json#/definitions/TimeOffsets"
}
Comment on lines +257 to +261
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't seem correct.

I've opened a PR: #1193

}
}
}
Expand Down
14 changes: 13 additions & 1 deletion schema/defs-linux.json
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,8 @@
"uts",
"ipc",
"user",
"cgroup"
"cgroup",
"time"
]
},
"NamespaceReference": {
Expand All @@ -308,6 +309,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 @@ -349,6 +349,16 @@
}
]
},
"timeOffsets": {
"monotonic": {
"secs": 172800,
"nanosecs": 0
},
"boottime": {
"secs": 604800,
"nanosecs": 0
}
},
"namespaces": [
{
"type": "pid"
Expand All @@ -370,6 +380,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 @@ -182,6 +182,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 @@ -211,6 +213,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 @@ -223,6 +227,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