Merge pull request #869 from crosbymichael/anno
Add annotations to list and state output
This commit is contained in:
commit
d6189a05cf
|
@ -165,14 +165,16 @@ func CreateLibcontainerConfig(opts *CreateOpts) (*configs.Config, error) {
|
|||
if !filepath.IsAbs(rootfsPath) {
|
||||
rootfsPath = filepath.Join(cwd, rootfsPath)
|
||||
}
|
||||
labels := []string{}
|
||||
for k, v := range spec.Annotations {
|
||||
labels = append(labels, fmt.Sprintf("%s=%s", k, v))
|
||||
}
|
||||
config := &configs.Config{
|
||||
Rootfs: rootfsPath,
|
||||
NoPivotRoot: opts.NoPivotRoot,
|
||||
Readonlyfs: spec.Root.Readonly,
|
||||
Hostname: spec.Hostname,
|
||||
Labels: []string{
|
||||
"bundle=" + cwd,
|
||||
},
|
||||
Labels: append(labels, fmt.Sprintf("bundle=%s", cwd)),
|
||||
}
|
||||
|
||||
exists := false
|
||||
|
|
|
@ -100,3 +100,22 @@ func SearchLabels(labels []string, query string) string {
|
|||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// Annotations returns the bundle path and user defined annotations from the
|
||||
// libcontianer state. We need to remove the bundle because that is a label
|
||||
// added by libcontainer.
|
||||
func Annotations(labels []string) (bundle string, userAnnotations map[string]string) {
|
||||
userAnnotations = make(map[string]string)
|
||||
for _, l := range labels {
|
||||
parts := strings.SplitN(l, "=", 2)
|
||||
if len(parts) < 2 {
|
||||
continue
|
||||
}
|
||||
if parts[0] == "bundle" {
|
||||
bundle = parts[1]
|
||||
} else {
|
||||
userAnnotations[parts[0]] = parts[1]
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
9
list.go
9
list.go
|
@ -31,6 +31,8 @@ type containerState struct {
|
|||
Bundle string `json:"bundle"`
|
||||
// Created is the unix timestamp for the creation time of the container in UTC
|
||||
Created time.Time `json:"created"`
|
||||
// Annotations is the user defined annotations added to the config.
|
||||
Annotations map[string]string `json:"annotations,omitempty"`
|
||||
}
|
||||
|
||||
var listCommand = cli.Command{
|
||||
|
@ -116,12 +118,15 @@ func getContainers(context *cli.Context) ([]containerState, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
bundle, annotations := utils.Annotations(state.Config.Labels)
|
||||
s = append(s, containerState{
|
||||
ID: state.BaseState.ID,
|
||||
InitProcessPid: state.BaseState.InitProcessPid,
|
||||
Status: containerStatus.String(),
|
||||
Bundle: utils.SearchLabels(state.Config.Labels, "bundle"),
|
||||
Created: state.BaseState.Created})
|
||||
Bundle: bundle,
|
||||
Created: state.BaseState.Created,
|
||||
Annotations: annotations,
|
||||
})
|
||||
}
|
||||
}
|
||||
return s, nil
|
||||
|
|
9
state.go
9
state.go
|
@ -30,6 +30,8 @@ type cState struct {
|
|||
Status string `json:"status"`
|
||||
// Created is the unix timestamp for the creation time of the container in UTC
|
||||
Created time.Time `json:"created"`
|
||||
// Annotations is the user defined annotations added to the config.
|
||||
Annotations map[string]string `json:"annotations,omitempty"`
|
||||
}
|
||||
|
||||
var stateCommand = cli.Command{
|
||||
|
@ -53,14 +55,17 @@ instance of a container.`,
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
bundle, annotations := utils.Annotations(state.Config.Labels)
|
||||
cs := cState{
|
||||
Version: state.BaseState.Config.Version,
|
||||
ID: state.BaseState.ID,
|
||||
InitProcessPid: state.BaseState.InitProcessPid,
|
||||
Status: containerStatus.String(),
|
||||
Bundle: utils.SearchLabels(state.Config.Labels, "bundle"),
|
||||
Bundle: bundle,
|
||||
Rootfs: state.BaseState.Config.Rootfs,
|
||||
Created: state.BaseState.Created}
|
||||
Created: state.BaseState.Created,
|
||||
Annotations: annotations,
|
||||
}
|
||||
data, err := json.MarshalIndent(cs, "", " ")
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
Loading…
Reference in New Issue