Skip to content
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
8 changes: 5 additions & 3 deletions libcontainer/specconv/spec_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions libcontainer/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 7 additions & 2 deletions list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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
Expand Down