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) {
|
if !filepath.IsAbs(rootfsPath) {
|
||||||
rootfsPath = filepath.Join(cwd, 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{
|
config := &configs.Config{
|
||||||
Rootfs: rootfsPath,
|
Rootfs: rootfsPath,
|
||||||
NoPivotRoot: opts.NoPivotRoot,
|
NoPivotRoot: opts.NoPivotRoot,
|
||||||
Readonlyfs: spec.Root.Readonly,
|
Readonlyfs: spec.Root.Readonly,
|
||||||
Hostname: spec.Hostname,
|
Hostname: spec.Hostname,
|
||||||
Labels: []string{
|
Labels: append(labels, fmt.Sprintf("bundle=%s", cwd)),
|
||||||
"bundle=" + cwd,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exists := false
|
exists := false
|
||||||
|
|
|
@ -100,3 +100,22 @@ func SearchLabels(labels []string, query string) string {
|
||||||
}
|
}
|
||||||
return ""
|
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"`
|
Bundle string `json:"bundle"`
|
||||||
// Created is the unix timestamp for the creation time of the container in UTC
|
// Created is the unix timestamp for the creation time of the container in UTC
|
||||||
Created time.Time `json:"created"`
|
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{
|
var listCommand = cli.Command{
|
||||||
|
@ -116,12 +118,15 @@ func getContainers(context *cli.Context) ([]containerState, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
bundle, annotations := utils.Annotations(state.Config.Labels)
|
||||||
s = append(s, containerState{
|
s = append(s, containerState{
|
||||||
ID: state.BaseState.ID,
|
ID: state.BaseState.ID,
|
||||||
InitProcessPid: state.BaseState.InitProcessPid,
|
InitProcessPid: state.BaseState.InitProcessPid,
|
||||||
Status: containerStatus.String(),
|
Status: containerStatus.String(),
|
||||||
Bundle: utils.SearchLabels(state.Config.Labels, "bundle"),
|
Bundle: bundle,
|
||||||
Created: state.BaseState.Created})
|
Created: state.BaseState.Created,
|
||||||
|
Annotations: annotations,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return s, nil
|
return s, nil
|
||||||
|
|
9
state.go
9
state.go
|
@ -30,6 +30,8 @@ type cState struct {
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
// Created is the unix timestamp for the creation time of the container in UTC
|
// Created is the unix timestamp for the creation time of the container in UTC
|
||||||
Created time.Time `json:"created"`
|
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{
|
var stateCommand = cli.Command{
|
||||||
|
@ -53,14 +55,17 @@ instance of a container.`,
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
bundle, annotations := utils.Annotations(state.Config.Labels)
|
||||||
cs := cState{
|
cs := cState{
|
||||||
Version: state.BaseState.Config.Version,
|
Version: state.BaseState.Config.Version,
|
||||||
ID: state.BaseState.ID,
|
ID: state.BaseState.ID,
|
||||||
InitProcessPid: state.BaseState.InitProcessPid,
|
InitProcessPid: state.BaseState.InitProcessPid,
|
||||||
Status: containerStatus.String(),
|
Status: containerStatus.String(),
|
||||||
Bundle: utils.SearchLabels(state.Config.Labels, "bundle"),
|
Bundle: bundle,
|
||||||
Rootfs: state.BaseState.Config.Rootfs,
|
Rootfs: state.BaseState.Config.Rootfs,
|
||||||
Created: state.BaseState.Created}
|
Created: state.BaseState.Created,
|
||||||
|
Annotations: annotations,
|
||||||
|
}
|
||||||
data, err := json.MarshalIndent(cs, "", " ")
|
data, err := json.MarshalIndent(cs, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in New Issue