Add support for annotations

Fix following issues:
- create container API handler ignores Annotations from HostConfig
- inspect container API handler does not provide Annotations as
  part of HostConfig

Signed-off-by: diplane <diplane3d@gmail.com>
This commit is contained in:
diplane
2024-03-21 19:59:36 +00:00
parent aaa6dc3cc6
commit 83fe867c14
4 changed files with 16 additions and 0 deletions

View File

@ -506,6 +506,10 @@ func (c *Container) generateInspectContainerHostConfig(ctrSpec *spec.Spec, named
// Annotations
if ctrSpec.Annotations != nil {
if len(ctrSpec.Annotations) != 0 {
hostConfig.Annotations = ctrSpec.Annotations
}
hostConfig.ContainerIDFile = ctrSpec.Annotations[define.InspectAnnotationCIDFile]
if ctrSpec.Annotations[define.InspectAnnotationAutoremove] == define.InspectResponseTrue {
hostConfig.AutoRemove = true

View File

@ -364,6 +364,9 @@ type InspectContainerHostConfig struct {
// It is not handled directly within libpod and is stored in an
// annotation.
AutoRemove bool `json:"AutoRemove"`
// Annotations are provided to the runtime when the container is
// started.
Annotations map[string]string `json:"Annotations"`
// VolumeDriver is presently unused and is retained for Docker
// compatibility.
VolumeDriver string `json:"VolumeDriver"`

View File

@ -451,6 +451,7 @@ func cliOpts(cc handlers.CreateContainerConfig, rtc *config.Config) (*entities.C
ReadOnly: cc.HostConfig.ReadonlyRootfs,
ReadWriteTmpFS: true, // podman default
Rm: cc.HostConfig.AutoRemove,
Annotation: stringMaptoArray(cc.HostConfig.Annotations),
SecurityOpt: cc.HostConfig.SecurityOpt,
StopSignal: cc.Config.StopSignal,
StopTimeout: rtc.Engine.StopTimeout, // podman default

View File

@ -0,0 +1,8 @@
# -*- sh -*-
podman pull $IMAGE &>/dev/null
t POST containers/create Image=$IMAGE HostConfig='{"annotations":{"foo":"bar","zoo":"boo"}}' 201 .Id~[0-9a-f]\\{64\\}
cid=$(jq -r '.Id' <<<"$output")
t GET containers/$cid/json 200 \
.HostConfig.Annotations.foo=bar \
.HostConfig.Annotations.zoo=boo \