Thanks to visit codestin.com
Credit goes to github.com

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
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ require (
github.com/google/renameio v1.0.0
github.com/google/uuid v1.2.0
github.com/grpc-ecosystem/go-grpc-middleware v1.2.2
github.com/hpcloud/tail v1.0.0
github.com/json-iterator/go v1.1.10
github.com/onsi/ginkgo v1.15.2
github.com/onsi/gomega v1.11.0
Expand Down
113 changes: 0 additions & 113 deletions internal/lib/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,87 +4,9 @@ import (
"fmt"

"github.com/containers/podman/v3/pkg/registrar"
cstorage "github.com/containers/storage"
"github.com/cri-o/cri-o/internal/lib/sandbox"
"github.com/cri-o/cri-o/internal/oci"
"github.com/pkg/errors"
)

// GetStorageContainer searches for a container with the given name or ID in the given store
func (c *ContainerServer) GetStorageContainer(container string) (*cstorage.Container, error) {
ociCtr, err := c.LookupContainer(container)
if err != nil {
return nil, err
}
return c.store.Container(ociCtr.ID())
}

// GetContainerTopLayerID gets the ID of the top layer of the given container
func (c *ContainerServer) GetContainerTopLayerID(containerID string) (string, error) {
ctr, err := c.GetStorageContainer(containerID)
if err != nil {
return "", err
}
return ctr.LayerID, nil
}

// GetContainerRwSize Gets the size of the mutable top layer of the container
func (c *ContainerServer) GetContainerRwSize(containerID string) (int64, error) {
container, err := c.store.Container(containerID)
if err != nil {
return 0, err
}

// Get the size of the top layer by calculating the size of the diff
// between the layer and its parent. The top layer of a container is
// the only RW layer, all others are immutable
layer, err := c.store.Layer(container.LayerID)
if err != nil {
return 0, err
}
return c.store.DiffSize(layer.Parent, layer.ID)
}

// GetContainerRootFsSize gets the size of the container's root filesystem
// A container FS is split into two parts. The first is the top layer, a
// mutable layer, and the rest is the RootFS: the set of immutable layers
// that make up the image on which the container is based
func (c *ContainerServer) GetContainerRootFsSize(containerID string) (int64, error) {
container, err := c.store.Container(containerID)
if err != nil {
return 0, err
}

// Ignore the size of the top layer. The top layer is a mutable RW layer
// and is not considered a part of the rootfs
rwLayer, err := c.store.Layer(container.LayerID)
if err != nil {
return 0, err
}
layer, err := c.store.Layer(rwLayer.Parent)
if err != nil {
return 0, err
}

size := int64(0)
for layer.Parent != "" {
layerSize, err := c.store.DiffSize(layer.Parent, layer.ID)
if err != nil {
return 0, errors.Wrapf(err, "getting diffsize of layer %q and its parent %q", layer.ID, layer.Parent)
}
size += layerSize
layer, err = c.store.Layer(layer.Parent)
if err != nil {
return 0, err
}
}
// Get the size of the last layer. Has to be outside of the loop
// because the parent of the last layer is "", andlstore.Get("")
// will return an error
layerSize, err := c.store.DiffSize(layer.Parent, layer.ID)
return size + layerSize, err
}

// GetContainerFromShortID gets an oci container matching the specified full or partial id
func (c *ContainerServer) GetContainerFromShortID(cid string) (*oci.Container, error) {
if cid == "" {
Expand All @@ -108,23 +30,6 @@ func (c *ContainerServer) GetContainerFromShortID(cid string) (*oci.Container, e
return ctr, nil
}

func (c *ContainerServer) getSandboxFromRequest(pid string) (*sandbox.Sandbox, error) {
if pid == "" {
return nil, fmt.Errorf("pod ID should not be empty")
}

podID, err := c.podIDIndex.Get(pid)
if err != nil {
return nil, fmt.Errorf("pod with ID starting with %s not found: %v", pid, err)
}

sb := c.GetSandbox(podID)
if sb == nil {
return nil, fmt.Errorf("specified pod not found: %s", podID)
}
return sb, nil
}

// LookupContainer returns the container with the given name or full or partial id
func (c *ContainerServer) LookupContainer(idOrName string) (*oci.Container, error) {
if idOrName == "" {
Expand All @@ -142,21 +47,3 @@ func (c *ContainerServer) LookupContainer(idOrName string) (*oci.Container, erro

return c.GetContainerFromShortID(ctrID)
}

// LookupSandbox returns the pod sandbox with the given name or full or partial id
func (c *ContainerServer) LookupSandbox(idOrName string) (*sandbox.Sandbox, error) {
if idOrName == "" {
return nil, fmt.Errorf("container ID or name should not be empty")
}

podID, err := c.podNameIndex.Get(idOrName)
if err != nil {
if err == registrar.ErrNameNotReserved {
podID = idOrName
} else {
return nil, err
}
}

return c.getSandboxFromRequest(podID)
}
13 changes: 2 additions & 11 deletions internal/lib/container_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/cri-o/cri-o/internal/storage"
crioann "github.com/cri-o/cri-o/pkg/annotations"
libconfig "github.com/cri-o/cri-o/pkg/config"
"github.com/cri-o/cri-o/server/cri/types"
json "github.com/json-iterator/go"
rspec "github.com/opencontainers/runtime-spec/specs-go"
"github.com/opencontainers/selinux/go-selinux/label"
Expand Down Expand Up @@ -63,21 +64,11 @@ func (c *ContainerServer) StorageImageServer() storage.ImageServer {
return c.storageImageServer
}

// CtrNameIndex returns the Registrar for the ContainerServer
func (c *ContainerServer) CtrNameIndex() *registrar.Registrar {
return c.ctrNameIndex
}

// CtrIDIndex returns the TruncIndex for the ContainerServer
func (c *ContainerServer) CtrIDIndex() *truncindex.TruncIndex {
return c.ctrIDIndex
}

// PodNameIndex returns the index of pod names
func (c *ContainerServer) PodNameIndex() *registrar.Registrar {
return c.podNameIndex
}

// PodIDIndex returns the index of pod IDs
func (c *ContainerServer) PodIDIndex() *truncindex.TruncIndex {
return c.podIDIndex
Expand Down Expand Up @@ -189,7 +180,7 @@ func (c *ContainerServer) LoadSandbox(ctx context.Context, id string) (retErr er

privileged := isTrue(m.Annotations[annotations.PrivilegedRuntime])
hostNetwork := isTrue(m.Annotations[annotations.HostNetwork])
nsOpts := sandbox.NamespaceOption{}
nsOpts := types.NamespaceOption{}
if err := json.Unmarshal([]byte(m.Annotations[annotations.NamespaceOptions]), &nsOpts); err != nil {
return errors.Wrapf(err, "error unmarshalling %s annotation", annotations.NamespaceOptions)
}
Expand Down
18 changes: 0 additions & 18 deletions internal/lib/container_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,6 @@ var _ = t.Describe("ContainerServer", func() {
Expect(res).NotTo(BeNil())
})

It("should succeed to get the CtrNameIndex", func() {
// Given
// When
res := sut.CtrNameIndex()

// Then
Expect(res).NotTo(BeNil())
})

It("should succeed to get the CtrIDIndex", func() {
// Given
// When
Expand All @@ -121,15 +112,6 @@ var _ = t.Describe("ContainerServer", func() {
Expect(res).NotTo(BeNil())
})

It("should succeed to get the PodNameIndex", func() {
// Given
// When
res := sut.PodNameIndex()

// Then
Expect(res).NotTo(BeNil())
})

It("should succeed to get the PodIDIndex", func() {
// Given
// When
Expand Down
Loading