Skip to content

Commit ce688a7

Browse files
committed
Add annotations and labels to the Spec.
Signed-off-by: Vishnu kannan <[email protected]>
1 parent 0c2892b commit ce688a7

File tree

3 files changed

+83
-0
lines changed

3 files changed

+83
-0
lines changed

config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ type Spec struct {
1818
Mounts []Mount `json:"mounts"`
1919
// Hooks are the commands run at various lifecycle events of the container.
2020
Hooks Hooks `json:"hooks"`
21+
// Labels is a map of string keys and values that can be used to group containers.
22+
Labels map[string]string `json:"labels,omitempty"`
23+
// Annotations is an unstructured key value map that may be set by external tools to store and retrieve arbitrary metadata.
24+
Annotations map[string]string `json:"annotations,omitempty"`
2125
}
2226

2327
// Process contains information to start a specific application inside the container.

config.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,4 +231,79 @@ If a hook returns a non-zero exit code, then an error is logged and the remainin
231231
`args` and `env` are optional.
232232
The semantics are the same as `Path`, `Args` and `Env` in [golang Cmd](https://golang.org/pkg/os/exec/#Cmd).
233233

234+
## Labels
235+
236+
_Labels_ are key/value pairs that can be optionally attached to containers.
237+
Labels are intended to be used to specify identifying attributes of containers that are meaningful and relevant to users, but which do not directly imply semantics to the runtime.
238+
Labels can be used to select subsets of containers.
239+
Each Key must be unique for a container.
240+
241+
```json
242+
"labels": {
243+
"key1": "value1",
244+
"key2": "value2"
245+
}
246+
```
247+
248+
Since labels will be used to sorting and grouping in UIs, CLIs, etc., we don't want to pollute labels with non-identifying, especially large and/or structured, data.
249+
Non-identifying information should be recorded using Annotations.
250+
251+
### Syntax and character set
252+
253+
_Labels_ are key value pairs.
254+
Valid label keys have two segments: an optional prefix and name, separated by a slash (`/`).
255+
The name segment is required and must be 63 characters or less, beginning and ending with an alphanumeric character (`[a-z0-9A-Z]`) with dashes (`-`), underscores (`_`), dots (`.`), and alphanumerics between.
256+
The prefix is optional.
257+
If specified, the prefix must be a DNS subdomain: a series of DNS labels separated by dots (`.`), not longer than 253 characters in total, followed by a slash (`/`).
258+
If the prefix is omitted, the label key is presumed to be private to the user.
259+
260+
Valid label values must be 63 characters or less and must be empty or begin and end with an alphanumeric character (`[a-z0-9A-Z]`) with dashes (`-`), underscores (`_`), dots (`.`), and alphanumerics between.
261+
262+
### Label selectors
263+
264+
Labels do not provide uniqueness.
265+
In general, we expect many containers to carry the same label(s).
266+
267+
Via a _label selector_, the client/user can identify a set of containers.
268+
269+
A label selector can be made of multiple _requirements_ which are comma-separated.
270+
In the case of multiple requirements, all must be satisfied so the comma separator acts as an _AND_ logical operator.
271+
272+
An empty label selector (that is, one with zero requirements) selects all containers.
273+
274+
#### _Equality-based_ requirement
275+
276+
_Equality-_ or _inequality-based_ requirements allow filtering by label keys and values.
277+
Matching containers must satisfy all of the specified label constraints, though they may have additional labels as well.
278+
Three kinds of operators are admitted `=`,`==`,`!=`.
279+
The first two represent _equality_ (and are simply synonyms), while the latter represents _inequality_. For example:
280+
281+
```
282+
environment = production
283+
tier != frontend
284+
```
285+
286+
The former selects all resources with key equal to `environment` and value equal to `production`.
287+
The latter selects all resources with key equal to `tier` and value distinct from `frontend`, and all resources with no labels with the `tier` key.
288+
One could filter for resources in `production` excluding `frontend` using the comma operator: `environment=production,tier!=frontend`
289+
290+
### CLI Examples
291+
292+
```console
293+
$ runtime list -l enviroment=production,tier=frontend
294+
```
295+
296+
## Annotations
297+
298+
Annotations are optional arbitrary non-identifying metadata that can be attached to containers.
299+
This information may be large, may be structured or unstructured, may include characters not permitted by labels.
300+
Annotations are key-value maps.
301+
302+
```json
303+
"annotations": {
304+
"key1" : "value1",
305+
"key2" : "value2"
306+
}
307+
```
308+
234309
[uts-namespace]: http://man7.org/linux/man-pages/man7/namespaces.7.html

state.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,8 @@ type State struct {
1313
Pid int `json:"pid"`
1414
// BundlePath is the path to the container's bundle directory.
1515
BundlePath string `json:"bundlePath"`
16+
// Labels is a map of string keys and values that can be used to group containers.
17+
Labels map[string]string `json:"labels,omitempty"`
18+
// Annotations is an unstructured key value map that may be set by external tools to store and retrieve arbitrary metadata.
19+
Annotations map[string]string `json:"annotations,omitempty"`
1620
}

0 commit comments

Comments
 (0)