Skip to content

Commit

Permalink
Add annotations and labels to the Spec.
Browse files Browse the repository at this point in the history
Signed-off-by: Vishnu kannan <vishnuk@google.com>
  • Loading branch information
vishh committed Mar 4, 2016
1 parent 0c2892b commit ce688a7
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
4 changes: 4 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ type Spec struct {
Mounts []Mount `json:"mounts"`
// Hooks are the commands run at various lifecycle events of the container.
Hooks Hooks `json:"hooks"`
// Labels is a map of string keys and values that can be used to group containers.
Labels map[string]string `json:"labels,omitempty"`
// Annotations is an unstructured key value map that may be set by external tools to store and retrieve arbitrary metadata.
Annotations map[string]string `json:"annotations,omitempty"`
}

// Process contains information to start a specific application inside the container.
Expand Down
75 changes: 75 additions & 0 deletions config.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,79 @@ If a hook returns a non-zero exit code, then an error is logged and the remainin
`args` and `env` are optional.
The semantics are the same as `Path`, `Args` and `Env` in [golang Cmd](https://golang.org/pkg/os/exec/#Cmd).

## Labels

_Labels_ are key/value pairs that can be optionally attached to containers.
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.
Labels can be used to select subsets of containers.
Each Key must be unique for a container.

```json
"labels": {
"key1": "value1",
"key2": "value2"
}
```

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.
Non-identifying information should be recorded using Annotations.

### Syntax and character set

_Labels_ are key value pairs.
Valid label keys have two segments: an optional prefix and name, separated by a slash (`/`).
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.
The prefix is optional.
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 (`/`).
If the prefix is omitted, the label key is presumed to be private to the user.

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.

### Label selectors

Labels do not provide uniqueness.
In general, we expect many containers to carry the same label(s).

Via a _label selector_, the client/user can identify a set of containers.

A label selector can be made of multiple _requirements_ which are comma-separated.
In the case of multiple requirements, all must be satisfied so the comma separator acts as an _AND_ logical operator.

An empty label selector (that is, one with zero requirements) selects all containers.

#### _Equality-based_ requirement

_Equality-_ or _inequality-based_ requirements allow filtering by label keys and values.
Matching containers must satisfy all of the specified label constraints, though they may have additional labels as well.
Three kinds of operators are admitted `=`,`==`,`!=`.
The first two represent _equality_ (and are simply synonyms), while the latter represents _inequality_. For example:

```
environment = production
tier != frontend
```

The former selects all resources with key equal to `environment` and value equal to `production`.
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.
One could filter for resources in `production` excluding `frontend` using the comma operator: `environment=production,tier!=frontend`

### CLI Examples

```console
$ runtime list -l enviroment=production,tier=frontend
```

## Annotations

Annotations are optional arbitrary non-identifying metadata that can be attached to containers.
This information may be large, may be structured or unstructured, may include characters not permitted by labels.
Annotations are key-value maps.

```json
"annotations": {
"key1" : "value1",
"key2" : "value2"
}
```

[uts-namespace]: http://man7.org/linux/man-pages/man7/namespaces.7.html
4 changes: 4 additions & 0 deletions state.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@ type State struct {
Pid int `json:"pid"`
// BundlePath is the path to the container's bundle directory.
BundlePath string `json:"bundlePath"`
// Labels is a map of string keys and values that can be used to group containers.
Labels map[string]string `json:"labels,omitempty"`
// Annotations is an unstructured key value map that may be set by external tools to store and retrieve arbitrary metadata.
Annotations map[string]string `json:"annotations,omitempty"`
}

0 comments on commit ce688a7

Please sign in to comment.