From 6d52ebdd13ad052bbf8bfa9efa4e45cafbce1fc2 Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Sun, 3 Jun 2018 14:05:54 -0400 Subject: Add flag to add annotations to a container Also add annotations from the image the container was created from. Signed-off-by: Matthew Heon Closes: #886 Approved by: rhatdan --- pkg/spec/createconfig.go | 47 +---------------------------------------------- pkg/spec/spec.go | 2 +- pkg/spec/spec_test.go | 6 ------ 3 files changed, 2 insertions(+), 53 deletions(-) (limited to 'pkg') diff --git a/pkg/spec/createconfig.go b/pkg/spec/createconfig.go index de6e0f593..25a0e26bd 100644 --- a/pkg/spec/createconfig.go +++ b/pkg/spec/createconfig.go @@ -16,7 +16,6 @@ import ( "github.com/opencontainers/selinux/go-selinux/label" "github.com/pkg/errors" "github.com/projectatomic/libpod/libpod" - ann "github.com/projectatomic/libpod/pkg/annotations" "github.com/sirupsen/logrus" "golang.org/x/sys/unix" ) @@ -67,6 +66,7 @@ type CreateResourceConfig struct { // CreateConfig is a pre OCI spec structure. It represents user input from varlink or the CLI type CreateConfig struct { Runtime *libpod.Runtime + Annotations map[string]string Args []string CapAdd []string // cap-add CapDrop []string // cap-drop @@ -219,51 +219,6 @@ func makeThrottleArray(throttleInput []string, rateType int) ([]spec.LinuxThrott return ltds, nil } -// GetAnnotations returns the all the annotations for the container -func (c *CreateConfig) GetAnnotations() map[string]string { - a := getDefaultAnnotations() - // TODO - Which annotations do we want added by default - // TODO - This should be added to the DB long term - if c.Tty { - a["io.kubernetes.cri-o.TTY"] = "true" - } - return a -} - -func getDefaultAnnotations() map[string]string { - var annotations map[string]string - annotations = make(map[string]string) - annotations[ann.Annotations] = "" - annotations[ann.ContainerID] = "" - annotations[ann.ContainerName] = "" - annotations[ann.ContainerType] = "sandbox" - annotations[ann.Created] = "" - annotations[ann.HostName] = "" - annotations[ann.IP] = "" - annotations[ann.Image] = "" - annotations[ann.ImageName] = "" - annotations[ann.ImageRef] = "" - annotations[ann.KubeName] = "" - annotations[ann.Labels] = "" - annotations[ann.LogPath] = "" - annotations[ann.Metadata] = "" - annotations[ann.Name] = "" - annotations[ann.PrivilegedRuntime] = "" - annotations[ann.ResolvPath] = "" - annotations[ann.HostnamePath] = "" - annotations[ann.SandboxID] = "" - annotations[ann.SandboxName] = "" - annotations[ann.ShmPath] = "" - annotations[ann.MountPoint] = "" - annotations[ann.TrustedSandbox] = "" - annotations[ann.TTY] = "false" - annotations[ann.Stdin] = "" - annotations[ann.StdinOnce] = "" - annotations[ann.Volumes] = "" - - return annotations -} - //GetVolumeMounts takes user provided input for bind mounts and creates Mount structs func (c *CreateConfig) GetVolumeMounts(specMounts []spec.Mount) ([]spec.Mount, error) { var m []spec.Mount diff --git a/pkg/spec/spec.go b/pkg/spec/spec.go index 5260b9b19..fdbbcd6ad 100644 --- a/pkg/spec/spec.go +++ b/pkg/spec/spec.go @@ -58,7 +58,7 @@ func CreateConfigToOCISpec(config *CreateConfig) (*spec.Spec, error) { //nolint g.SetProcessArgs(config.Command) g.SetProcessTerminal(config.Tty) - for key, val := range config.GetAnnotations() { + for key, val := range config.Annotations { g.AddAnnotation(key, val) } g.SetRootReadonly(config.ReadOnlyRootfs) diff --git a/pkg/spec/spec_test.go b/pkg/spec/spec_test.go index 2a040a9a0..de3605068 100644 --- a/pkg/spec/spec_test.go +++ b/pkg/spec/spec_test.go @@ -23,12 +23,6 @@ func TestCreateConfig_GetVolumeMounts(t *testing.T) { assert.True(t, reflect.DeepEqual(data, specMount[0])) } -func TestCreateConfig_GetAnnotations(t *testing.T) { - config := CreateConfig{} - annotations := config.GetAnnotations() - assert.True(t, reflect.DeepEqual("sandbox", annotations["io.kubernetes.cri-o.ContainerType"])) -} - func TestCreateConfig_GetTmpfsMounts(t *testing.T) { data := spec.Mount{ Destination: "/homer", -- cgit v1.2.3-54-g00ecf