Add crio annotations to container endpoint
Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
This commit is contained in:
parent
2e3d5240c2
commit
50baca10e9
7 changed files with 77 additions and 65 deletions
|
@ -384,7 +384,7 @@ func (c *ContainerServer) LoadSandbox(id string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
scontainer, err := oci.NewContainer(m.Annotations[annotations.ContainerID], cname, sandboxPath, m.Annotations[annotations.LogPath], sb.NetNs(), labels, kubeAnnotations, "", "", "", nil, id, false, false, false, privileged, trusted, sandboxDir, created, m.Annotations["org.opencontainers.image.stopSignal"])
|
scontainer, err := oci.NewContainer(m.Annotations[annotations.ContainerID], cname, sandboxPath, m.Annotations[annotations.LogPath], sb.NetNs(), labels, m.Annotations, kubeAnnotations, "", "", "", nil, id, false, false, false, privileged, trusted, sandboxDir, created, m.Annotations["org.opencontainers.image.stopSignal"])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -507,7 +507,7 @@ func (c *ContainerServer) LoadContainer(id string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
ctr, err := oci.NewContainer(id, name, containerPath, m.Annotations[annotations.LogPath], sb.NetNs(), labels, kubeAnnotations, img, imgName, imgRef, &metadata, sb.ID(), tty, stdin, stdinOnce, sb.Privileged(), sb.Trusted(), containerDir, created, m.Annotations["org.opencontainers.image.stopSignal"])
|
ctr, err := oci.NewContainer(id, name, containerPath, m.Annotations[annotations.LogPath], sb.NetNs(), labels, m.Annotations, kubeAnnotations, img, imgName, imgRef, &metadata, sb.ID(), tty, stdin, stdinOnce, sb.Privileged(), sb.Trusted(), containerDir, created, m.Annotations["org.opencontainers.image.stopSignal"])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,22 +22,23 @@ const (
|
||||||
|
|
||||||
// Container represents a runtime container.
|
// Container represents a runtime container.
|
||||||
type Container struct {
|
type Container struct {
|
||||||
id string
|
id string
|
||||||
name string
|
name string
|
||||||
logPath string
|
logPath string
|
||||||
labels fields.Set
|
labels fields.Set
|
||||||
annotations fields.Set
|
annotations fields.Set
|
||||||
image string
|
crioAnnotations fields.Set
|
||||||
sandbox string
|
image string
|
||||||
netns ns.NetNS
|
sandbox string
|
||||||
terminal bool
|
netns ns.NetNS
|
||||||
stdin bool
|
terminal bool
|
||||||
stdinOnce bool
|
stdin bool
|
||||||
privileged bool
|
stdinOnce bool
|
||||||
trusted bool
|
privileged bool
|
||||||
state *ContainerState
|
trusted bool
|
||||||
metadata *pb.ContainerMetadata
|
state *ContainerState
|
||||||
opLock sync.Locker
|
metadata *pb.ContainerMetadata
|
||||||
|
opLock sync.Locker
|
||||||
// this is the /var/run/storage/... directory, erased on reboot
|
// this is the /var/run/storage/... directory, erased on reboot
|
||||||
bundlePath string
|
bundlePath string
|
||||||
// this is the /var/lib/storage/... directory
|
// this is the /var/lib/storage/... directory
|
||||||
|
@ -68,31 +69,32 @@ type ContainerState struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewContainer creates a container object.
|
// NewContainer creates a container object.
|
||||||
func NewContainer(id string, name string, bundlePath string, logPath string, netns ns.NetNS, labels map[string]string, annotations map[string]string, image string, imageName string, imageRef string, metadata *pb.ContainerMetadata, sandbox string, terminal bool, stdin bool, stdinOnce bool, privileged bool, trusted bool, dir string, created time.Time, stopSignal string) (*Container, error) {
|
func NewContainer(id string, name string, bundlePath string, logPath string, netns ns.NetNS, labels map[string]string, crioAnnotations map[string]string, annotations map[string]string, image string, imageName string, imageRef string, metadata *pb.ContainerMetadata, sandbox string, terminal bool, stdin bool, stdinOnce bool, privileged bool, trusted bool, dir string, created time.Time, stopSignal string) (*Container, error) {
|
||||||
state := &ContainerState{}
|
state := &ContainerState{}
|
||||||
state.Created = created
|
state.Created = created
|
||||||
c := &Container{
|
c := &Container{
|
||||||
id: id,
|
id: id,
|
||||||
name: name,
|
name: name,
|
||||||
bundlePath: bundlePath,
|
bundlePath: bundlePath,
|
||||||
logPath: logPath,
|
logPath: logPath,
|
||||||
labels: labels,
|
labels: labels,
|
||||||
sandbox: sandbox,
|
sandbox: sandbox,
|
||||||
netns: netns,
|
netns: netns,
|
||||||
terminal: terminal,
|
terminal: terminal,
|
||||||
stdin: stdin,
|
stdin: stdin,
|
||||||
stdinOnce: stdinOnce,
|
stdinOnce: stdinOnce,
|
||||||
privileged: privileged,
|
privileged: privileged,
|
||||||
trusted: trusted,
|
trusted: trusted,
|
||||||
metadata: metadata,
|
metadata: metadata,
|
||||||
annotations: annotations,
|
annotations: annotations,
|
||||||
image: image,
|
crioAnnotations: crioAnnotations,
|
||||||
imageName: imageName,
|
image: image,
|
||||||
imageRef: imageRef,
|
imageName: imageName,
|
||||||
dir: dir,
|
imageRef: imageRef,
|
||||||
state: state,
|
dir: dir,
|
||||||
stopSignal: stopSignal,
|
state: state,
|
||||||
opLock: new(sync.Mutex),
|
stopSignal: stopSignal,
|
||||||
|
opLock: new(sync.Mutex),
|
||||||
}
|
}
|
||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
|
@ -163,6 +165,11 @@ func (c *Container) Annotations() map[string]string {
|
||||||
return c.annotations
|
return c.annotations
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CrioAnnotations returns the crio annotations of the container.
|
||||||
|
func (c *Container) CrioAnnotations() map[string]string {
|
||||||
|
return c.crioAnnotations
|
||||||
|
}
|
||||||
|
|
||||||
// Image returns the image of the container.
|
// Image returns the image of the container.
|
||||||
func (c *Container) Image() string {
|
func (c *Container) Image() string {
|
||||||
return c.image
|
return c.image
|
||||||
|
|
|
@ -862,6 +862,7 @@ func (s *Server) createSandboxContainer(ctx context.Context, containerID string,
|
||||||
specgen.AddAnnotation(annotations.Stdin, fmt.Sprintf("%v", containerConfig.Stdin))
|
specgen.AddAnnotation(annotations.Stdin, fmt.Sprintf("%v", containerConfig.Stdin))
|
||||||
specgen.AddAnnotation(annotations.StdinOnce, fmt.Sprintf("%v", containerConfig.StdinOnce))
|
specgen.AddAnnotation(annotations.StdinOnce, fmt.Sprintf("%v", containerConfig.StdinOnce))
|
||||||
specgen.AddAnnotation(annotations.Image, image)
|
specgen.AddAnnotation(annotations.Image, image)
|
||||||
|
specgen.AddAnnotation(annotations.ResolvPath, sb.InfraContainer().CrioAnnotations()[annotations.ResolvPath])
|
||||||
|
|
||||||
created := time.Now()
|
created := time.Now()
|
||||||
specgen.AddAnnotation(annotations.Created, created.Format(time.RFC3339Nano))
|
specgen.AddAnnotation(annotations.Created, created.Format(time.RFC3339Nano))
|
||||||
|
@ -1000,7 +1001,9 @@ func (s *Server) createSandboxContainer(ctx context.Context, containerID string,
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
container, err := oci.NewContainer(containerID, containerName, containerInfo.RunDir, logPath, sb.NetNs(), labels, kubeAnnotations, image, imageName, imageRef, metadata, sb.ID(), containerConfig.Tty, containerConfig.Stdin, containerConfig.StdinOnce, sb.Privileged(), sb.Trusted(), containerInfo.Dir, created, containerImageConfig.Config.StopSignal)
|
crioAnnotations := specgen.Spec().Annotations
|
||||||
|
|
||||||
|
container, err := oci.NewContainer(containerID, containerName, containerInfo.RunDir, logPath, sb.NetNs(), labels, crioAnnotations, kubeAnnotations, image, imageName, imageRef, metadata, sb.ID(), containerConfig.Tty, containerConfig.Stdin, containerConfig.StdinOnce, sb.Privileged(), sb.Trusted(), containerInfo.Dir, created, containerImageConfig.Config.StopSignal)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,16 +46,17 @@ func (s *Server) getContainerInfo(id string, getContainerFunc func(id string) *o
|
||||||
return types.ContainerInfo{}, errSandboxNotFound
|
return types.ContainerInfo{}, errSandboxNotFound
|
||||||
}
|
}
|
||||||
return types.ContainerInfo{
|
return types.ContainerInfo{
|
||||||
Name: ctr.Name(),
|
Name: ctr.Name(),
|
||||||
Pid: ctrState.Pid,
|
Pid: ctrState.Pid,
|
||||||
Image: ctr.Image(),
|
Image: ctr.Image(),
|
||||||
CreatedTime: ctrState.Created.UnixNano(),
|
CreatedTime: ctrState.Created.UnixNano(),
|
||||||
Labels: ctr.Labels(),
|
Labels: ctr.Labels(),
|
||||||
Annotations: ctr.Annotations(),
|
Annotations: ctr.Annotations(),
|
||||||
Root: ctr.MountPoint(),
|
CrioAnnotations: ctr.CrioAnnotations(),
|
||||||
LogPath: ctr.LogPath(),
|
Root: ctr.MountPoint(),
|
||||||
Sandbox: ctr.Sandbox(),
|
LogPath: ctr.LogPath(),
|
||||||
IP: sb.IP(),
|
Sandbox: ctr.Sandbox(),
|
||||||
|
IP: sb.IP(),
|
||||||
}, nil
|
}, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,7 +67,7 @@ func TestGetContainerInfo(t *testing.T) {
|
||||||
"io.kubernetes.test1": "value1",
|
"io.kubernetes.test1": "value1",
|
||||||
}
|
}
|
||||||
getContainerFunc := func(id string) *oci.Container {
|
getContainerFunc := func(id string) *oci.Container {
|
||||||
container, err := oci.NewContainer("testid", "testname", "", "/container/logs", mockNetNS{}, labels, annotations, "imageName", "imageName", "imageRef", &runtime.ContainerMetadata{}, "testsandboxid", false, false, false, false, false, "/root/for/container", created, "SIGKILL")
|
container, err := oci.NewContainer("testid", "testname", "", "/container/logs", mockNetNS{}, labels, annotations, annotations, "imageName", "imageName", "imageRef", &runtime.ContainerMetadata{}, "testsandboxid", false, false, false, false, false, "/root/for/container", created, "SIGKILL")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -181,7 +181,7 @@ func TestGetContainerInfoCtrStateNil(t *testing.T) {
|
||||||
labels := map[string]string{}
|
labels := map[string]string{}
|
||||||
annotations := map[string]string{}
|
annotations := map[string]string{}
|
||||||
getContainerFunc := func(id string) *oci.Container {
|
getContainerFunc := func(id string) *oci.Container {
|
||||||
container, err := oci.NewContainer("testid", "testname", "", "/container/logs", mockNetNS{}, labels, annotations, "imageName", "imageName", "imageRef", &runtime.ContainerMetadata{}, "testsandboxid", false, false, false, false, false, "/root/for/container", created, "SIGKILL")
|
container, err := oci.NewContainer("testid", "testname", "", "/container/logs", mockNetNS{}, labels, annotations, annotations, "imageName", "imageName", "imageRef", &runtime.ContainerMetadata{}, "testsandboxid", false, false, false, false, false, "/root/for/container", created, "SIGKILL")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -212,7 +212,7 @@ func TestGetContainerInfoSandboxNotFound(t *testing.T) {
|
||||||
labels := map[string]string{}
|
labels := map[string]string{}
|
||||||
annotations := map[string]string{}
|
annotations := map[string]string{}
|
||||||
getContainerFunc := func(id string) *oci.Container {
|
getContainerFunc := func(id string) *oci.Container {
|
||||||
container, err := oci.NewContainer("testid", "testname", "", "/container/logs", mockNetNS{}, labels, annotations, "imageName", "imageName", "imageRef", &runtime.ContainerMetadata{}, "testsandboxid", false, false, false, false, false, "/root/for/container", created, "SIGKILL")
|
container, err := oci.NewContainer("testid", "testname", "", "/container/logs", mockNetNS{}, labels, annotations, annotations, "imageName", "imageName", "imageRef", &runtime.ContainerMetadata{}, "testsandboxid", false, false, false, false, false, "/root/for/container", created, "SIGKILL")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -472,7 +472,7 @@ func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest
|
||||||
g.AddAnnotation(annotations.HostnamePath, hostnamePath)
|
g.AddAnnotation(annotations.HostnamePath, hostnamePath)
|
||||||
sb.AddHostnamePath(hostnamePath)
|
sb.AddHostnamePath(hostnamePath)
|
||||||
|
|
||||||
container, err := oci.NewContainer(id, containerName, podContainer.RunDir, logPath, sb.NetNs(), labels, kubeAnnotations, "", "", "", nil, id, false, false, false, sb.Privileged(), sb.Trusted(), podContainer.Dir, created, podContainer.Config.Config.StopSignal)
|
container, err := oci.NewContainer(id, containerName, podContainer.RunDir, logPath, sb.NetNs(), labels, g.Spec().Annotations, kubeAnnotations, "", "", "", nil, id, false, false, false, sb.Privileged(), sb.Trusted(), podContainer.Dir, created, podContainer.Config.Config.StopSignal)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,16 +2,17 @@ package types
|
||||||
|
|
||||||
// ContainerInfo stores information about containers
|
// ContainerInfo stores information about containers
|
||||||
type ContainerInfo struct {
|
type ContainerInfo struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Pid int `json:"pid"`
|
Pid int `json:"pid"`
|
||||||
Image string `json:"image"`
|
Image string `json:"image"`
|
||||||
CreatedTime int64 `json:"created_time"`
|
CreatedTime int64 `json:"created_time"`
|
||||||
Labels map[string]string `json:"labels"`
|
Labels map[string]string `json:"labels"`
|
||||||
Annotations map[string]string `json:"annotations"`
|
Annotations map[string]string `json:"annotations"`
|
||||||
LogPath string `json:"log_path"`
|
CrioAnnotations map[string]string `json:"crio_annotations"`
|
||||||
Root string `json:"root"`
|
LogPath string `json:"log_path"`
|
||||||
Sandbox string `json:"sandbox"`
|
Root string `json:"root"`
|
||||||
IP string `json:"ip_address"`
|
Sandbox string `json:"sandbox"`
|
||||||
|
IP string `json:"ip_address"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// CrioInfo stores information about the crio daemon
|
// CrioInfo stores information about the crio daemon
|
||||||
|
|
Loading…
Reference in a new issue