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
4 changes: 2 additions & 2 deletions internal/lib/container_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func (c *ContainerServer) LoadSandbox(ctx context.Context, id string) (sb *sandb
c.ReleasePodName(name)
}
}()
var metadata sandbox.Metadata
var metadata types.PodSandboxMetadata
if err := json.Unmarshal([]byte(m.Annotations[annotations.Metadata]), &metadata); err != nil {
return nil, errors.Wrapf(err, "error unmarshalling %s annotation", annotations.Metadata)
}
Expand Down Expand Up @@ -380,7 +380,7 @@ func (c *ContainerServer) LoadContainer(ctx context.Context, id string) (retErr
}
}()

var metadata oci.Metadata
var metadata types.ContainerMetadata
if err := json.Unmarshal([]byte(m.Annotations[annotations.Metadata]), &metadata); err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion internal/lib/container_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/cri-o/cri-o/internal/lib"
"github.com/cri-o/cri-o/internal/oci"
libconfig "github.com/cri-o/cri-o/pkg/config"
"github.com/cri-o/cri-o/server/cri/types"
"github.com/golang/mock/gomock"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -586,7 +587,7 @@ var _ = t.Describe("ContainerServer", func() {
container, err := oci.NewContainer(containerID, "", "", "",
make(map[string]string), make(map[string]string),
make(map[string]string), "", "", "",
&oci.Metadata{}, sandboxID, false,
&types.ContainerMetadata{}, sandboxID, false,
false, false, "", "/invalid", time.Now(), "")
Expect(err).To(BeNil())

Expand Down
2 changes: 1 addition & 1 deletion internal/lib/sandbox/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func (history *History) Len() int {
func (history *History) Less(i, j int) bool {
sandboxes := *history
// FIXME: state access should be serialized
return sandboxes[j].createdAt.Before(sandboxes[i].createdAt)
return sandboxes[j].CreatedAt() < sandboxes[i].CreatedAt()
}

// Swap switches sandboxes i and j positions in the history.
Expand Down
3 changes: 2 additions & 1 deletion internal/lib/sandbox/history_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/cri-o/cri-o/internal/hostport"
"github.com/cri-o/cri-o/internal/lib/sandbox"
"github.com/cri-o/cri-o/server/cri/types"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
Expand All @@ -18,7 +19,7 @@ var _ = t.Describe("History", func() {
beforeEach()
otherTestSandbox, err := sandbox.New("sandboxID", "", "", "", "",
make(map[string]string), make(map[string]string), "", "",
&sandbox.Metadata{}, "", "", false, "", "", "",
&types.PodSandboxMetadata{}, "", "", false, "", "", "",
[]*hostport.PortMapping{}, false, time.Now(), "")
Expect(err).To(BeNil())
Expect(testSandbox).NotTo(BeNil())
Expand Down
3 changes: 2 additions & 1 deletion internal/lib/sandbox/namespaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/cri-o/cri-o/internal/config/nsmgr"
"github.com/cri-o/cri-o/internal/oci"
"github.com/cri-o/cri-o/server/cri/types"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
specs "github.com/opencontainers/runtime-spec/specs-go"
Expand Down Expand Up @@ -322,7 +323,7 @@ var _ = t.Describe("SandboxManagedNamespaces", func() {
testContainer, err := oci.NewContainer("testid", "testname", "",
"/container/logs", map[string]string{},
map[string]string{}, map[string]string{}, "image",
"imageName", "imageRef", &oci.Metadata{},
"imageName", "imageRef", &types.ContainerMetadata{},
"testsandboxid", false, false, false, "",
"/root/for/container", time.Now(), "SIGKILL")
Expect(err).To(BeNil())
Expand Down
53 changes: 21 additions & 32 deletions internal/lib/sandbox/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ var (

// Sandbox contains data surrounding kubernetes sandboxes on the server
type Sandbox struct {
criSandbox *types.PodSandbox
portMappings []*hostport.PortMapping
createdAt time.Time
id string
namespace string
// OCI pod name (eg "<namespace>-<name>-<attempt>")
name string
Expand All @@ -52,10 +51,7 @@ type Sandbox struct {
// ipv4 or ipv6 cache
ips []string
seccompProfilePath string
labels fields.Set
annotations map[string]string
infraContainer *oci.Container
metadata *Metadata
nsOpts *types.NamespaceOption
stopMutex sync.RWMutex
created bool
Expand All @@ -66,20 +62,6 @@ type Sandbox struct {
usernsMode string
}

type Metadata struct {
// Pod name of the sandbox.
Name string `json:"name,omitempty"`

// Pod UID of the sandbox.
UID string `json:"uid,omitempty"`

// Pod namespace of the sandbox.
Namespace string `json:"namespace,omitempty"`

// Attempt number of creating the sandbox.
Attempt uint32 `json:"attempt,omitempty"`
}

// DefaultShmSize is the default shm size
const DefaultShmSize = 64 * 1024 * 1024

Expand All @@ -89,35 +71,42 @@ var ErrIDEmpty = errors.New("PodSandboxId should not be empty")
// New creates and populates a new pod sandbox
// New sandboxes have no containers, no infra container, and no network namespaces associated with them
// An infra container must be attached before the sandbox is added to the state
func New(id, namespace, name, kubeName, logDir string, labels, annotations map[string]string, processLabel, mountLabel string, metadata *Metadata, shmPath, cgroupParent string, privileged bool, runtimeHandler, resolvPath, hostname string, portMappings []*hostport.PortMapping, hostNetwork bool, createdAt time.Time, usernsMode string) (*Sandbox, error) {
func New(id, namespace, name, kubeName, logDir string, labels, annotations map[string]string, processLabel, mountLabel string, metadata *types.PodSandboxMetadata, shmPath, cgroupParent string, privileged bool, runtimeHandler, resolvPath, hostname string, portMappings []*hostport.PortMapping, hostNetwork bool, createdAt time.Time, usernsMode string) (*Sandbox, error) {
sb := new(Sandbox)
sb.id = id

sb.criSandbox = &types.PodSandbox{
ID: id,
CreatedAt: createdAt.UnixNano(),
Labels: labels,
Annotations: annotations,
Metadata: metadata,
}
sb.namespace = namespace
sb.name = name
sb.kubeName = kubeName
sb.logDir = logDir
sb.labels = labels
sb.annotations = annotations
sb.containers = oci.NewMemoryStore()
sb.processLabel = processLabel
sb.mountLabel = mountLabel
sb.metadata = metadata
sb.shmPath = shmPath
sb.cgroupParent = cgroupParent
sb.privileged = privileged
sb.runtimeHandler = runtimeHandler
sb.resolvPath = resolvPath
sb.hostname = hostname
sb.portMappings = portMappings
sb.createdAt = createdAt
sb.hostNetwork = hostNetwork
sb.usernsMode = usernsMode

return sb, nil
}

func (s *Sandbox) CreatedAt() time.Time {
return s.createdAt
func (s *Sandbox) CRISandbox() *types.PodSandbox {
return s.criSandbox
}

func (s *Sandbox) CreatedAt() int64 {
return s.criSandbox.CreatedAt
}

// SetSeccompProfilePath sets the seccomp profile path
Expand Down Expand Up @@ -157,7 +146,7 @@ func (s *Sandbox) IPs() []string {

// ID returns the id of the sandbox
func (s *Sandbox) ID() string {
return s.id
return s.criSandbox.ID
}

// UsernsMode returns the mode for setting the user namespace, if any.
Expand Down Expand Up @@ -187,12 +176,12 @@ func (s *Sandbox) LogDir() string {

// Labels returns the labels associated with the sandbox
func (s *Sandbox) Labels() fields.Set {
return s.labels
return s.criSandbox.Labels
}

// Annotations returns a list of annotations for the sandbox
func (s *Sandbox) Annotations() map[string]string {
return s.annotations
return s.criSandbox.Annotations
}

// Containers returns the ContainerStorer that contains information on all
Expand All @@ -212,8 +201,8 @@ func (s *Sandbox) MountLabel() string {
}

// Metadata returns a set of metadata about the sandbox
func (s *Sandbox) Metadata() *Metadata {
return s.metadata
func (s *Sandbox) Metadata() *types.PodSandboxMetadata {
return s.criSandbox.Metadata
}

// ShmPath returns the shm path of the sandbox
Expand Down
6 changes: 3 additions & 3 deletions internal/lib/sandbox/sandbox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var _ = t.Describe("Sandbox", func() {
annotations := map[string]string{"a": "annotA", "b": "annotB"}
processLabel := "processLabel"
mountLabel := "mountLabel"
metadata := sandbox.Metadata{Name: name}
metadata := types.PodSandboxMetadata{Name: name}
shmPath := "shmPath"
cgroupParent := "cgroupParent"
privileged := true
Expand Down Expand Up @@ -68,7 +68,7 @@ var _ = t.Describe("Sandbox", func() {
Expect(sandbox.HostNetwork()).To(Equal(hostNetwork))
Expect(sandbox.StopMutex()).NotTo(BeNil())
Expect(sandbox.Containers()).NotTo(BeNil())
Expect(sandbox.CreatedAt()).To(Equal(createdAt))
Expect(sandbox.CreatedAt()).To(Equal(createdAt.UnixNano()))
})
})

Expand Down Expand Up @@ -184,7 +184,7 @@ var _ = t.Describe("Sandbox", func() {
testContainer, err = oci.NewContainer("testid", "testname", "",
"/container/logs", map[string]string{},
map[string]string{}, map[string]string{}, "image",
"imageName", "imageRef", &oci.Metadata{},
"imageName", "imageRef", &types.ContainerMetadata{},
"testsandboxid", false, false, false, "",
"/root/for/container", time.Now(), "SIGKILL")
Expect(err).To(BeNil())
Expand Down
3 changes: 2 additions & 1 deletion internal/lib/sandbox/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/cri-o/cri-o/internal/hostport"
"github.com/cri-o/cri-o/internal/lib/sandbox"
"github.com/cri-o/cri-o/server/cri/types"
. "github.com/cri-o/cri-o/test/framework"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -39,7 +40,7 @@ func beforeEach() {
var err error
testSandbox, err = sandbox.New("sandboxID", "", "", "", "",
make(map[string]string), make(map[string]string), "", "",
&sandbox.Metadata{}, "", "", false, "", "", "",
&types.PodSandboxMetadata{}, "", "", false, "", "", "",
[]*hostport.PortMapping{}, false, time.Now(), "")
Expect(err).To(BeNil())
Expect(testSandbox).NotTo(BeNil())
Expand Down
5 changes: 3 additions & 2 deletions internal/lib/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/cri-o/cri-o/internal/lib/sandbox"
"github.com/cri-o/cri-o/internal/oci"
libconfig "github.com/cri-o/cri-o/pkg/config"
"github.com/cri-o/cri-o/server/cri/types"
. "github.com/cri-o/cri-o/test/framework"
containerstoragemock "github.com/cri-o/cri-o/test/mocks/containerstorage"
libmock "github.com/cri-o/cri-o/test/mocks/lib"
Expand Down Expand Up @@ -142,14 +143,14 @@ func beforeEach() {
// Setup test vars
mySandbox, err = sandbox.New(sandboxID, "", "", "", "",
make(map[string]string), make(map[string]string), "", "",
&sandbox.Metadata{}, "", "", false, "", "", "",
&types.PodSandboxMetadata{}, "", "", false, "", "", "",
[]*hostport.PortMapping{}, false, time.Now(), "")
Expect(err).To(BeNil())

myContainer, err = oci.NewContainer(containerID, "", "", "",
make(map[string]string), make(map[string]string),
make(map[string]string), "", "", "",
&oci.Metadata{}, sandboxID, false,
&types.ContainerMetadata{}, sandboxID, false,
false, false, "", "", time.Now(), "")
Expect(err).To(BeNil())
}
Expand Down
Loading