commit
737efe70a7
@ -46,8 +46,6 @@ func (c *criContainerdService) PodSandboxStatus(ctx context.Context, r *runtime.
|
|||||||
|
|
||||||
var pid uint32
|
var pid uint32
|
||||||
var processStatus containerd.ProcessStatus
|
var processStatus containerd.ProcessStatus
|
||||||
// Set sandbox state to NOTREADY by default.
|
|
||||||
state := runtime.PodSandboxState_SANDBOX_NOTREADY
|
|
||||||
// If the sandbox container is running, treat it as READY.
|
// If the sandbox container is running, treat it as READY.
|
||||||
if task != nil {
|
if task != nil {
|
||||||
taskStatus, err := task.Status(ctx)
|
taskStatus, err := task.Status(ctx)
|
||||||
@ -55,9 +53,6 @@ func (c *criContainerdService) PodSandboxStatus(ctx context.Context, r *runtime.
|
|||||||
return nil, fmt.Errorf("failed to get task status: %v", err)
|
return nil, fmt.Errorf("failed to get task status: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if taskStatus.Status == containerd.Running {
|
|
||||||
state = runtime.PodSandboxState_SANDBOX_READY
|
|
||||||
}
|
|
||||||
pid = task.Pid()
|
pid = task.Pid()
|
||||||
processStatus = taskStatus.Status
|
processStatus = taskStatus.Status
|
||||||
}
|
}
|
||||||
@ -72,7 +67,7 @@ func (c *criContainerdService) PodSandboxStatus(ctx context.Context, r *runtime.
|
|||||||
return nil, fmt.Errorf("failed to get sandbox container info: %v", err)
|
return nil, fmt.Errorf("failed to get sandbox container info: %v", err)
|
||||||
}
|
}
|
||||||
createdAt := ctrInfo.CreatedAt
|
createdAt := ctrInfo.CreatedAt
|
||||||
status := toCRISandboxStatus(sandbox.Metadata, state, createdAt, ip)
|
status := toCRISandboxStatus(sandbox.Metadata, processStatus, createdAt, ip)
|
||||||
info, err := toCRISandboxInfo(ctx, sandbox, pid, processStatus, r.GetVerbose())
|
info, err := toCRISandboxInfo(ctx, sandbox, pid, processStatus, r.GetVerbose())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to get verbose sandbox container info: %v", err)
|
return nil, fmt.Errorf("failed to get verbose sandbox container info: %v", err)
|
||||||
@ -123,7 +118,12 @@ func (c *criContainerdService) getIP(sandbox sandboxstore.Sandbox) (string, erro
|
|||||||
}
|
}
|
||||||
|
|
||||||
// toCRISandboxStatus converts sandbox metadata into CRI pod sandbox status.
|
// toCRISandboxStatus converts sandbox metadata into CRI pod sandbox status.
|
||||||
func toCRISandboxStatus(meta sandboxstore.Metadata, state runtime.PodSandboxState, createdAt time.Time, ip string) *runtime.PodSandboxStatus {
|
func toCRISandboxStatus(meta sandboxstore.Metadata, status containerd.ProcessStatus, createdAt time.Time, ip string) *runtime.PodSandboxStatus {
|
||||||
|
// Set sandbox state to NOTREADY by default.
|
||||||
|
state := runtime.PodSandboxState_SANDBOX_NOTREADY
|
||||||
|
if status == containerd.Running {
|
||||||
|
state = runtime.PodSandboxState_SANDBOX_READY
|
||||||
|
}
|
||||||
nsOpts := meta.Config.GetLinux().GetSecurityContext().GetNamespaceOptions()
|
nsOpts := meta.Config.GetLinux().GetSecurityContext().GetNamespaceOptions()
|
||||||
return &runtime.PodSandboxStatus{
|
return &runtime.PodSandboxStatus{
|
||||||
Id: meta.ID,
|
Id: meta.ID,
|
||||||
|
@ -20,6 +20,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/containerd/containerd"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
|
"k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
|
||||||
|
|
||||||
@ -58,12 +59,10 @@ func TestPodSandboxStatus(t *testing.T) {
|
|||||||
Config: config,
|
Config: config,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
state := runtime.PodSandboxState_SANDBOX_NOTREADY
|
|
||||||
|
|
||||||
expected := &runtime.PodSandboxStatus{
|
expected := &runtime.PodSandboxStatus{
|
||||||
Id: id,
|
Id: id,
|
||||||
Metadata: config.GetMetadata(),
|
Metadata: config.GetMetadata(),
|
||||||
State: state,
|
|
||||||
CreatedAt: createdAt.UnixNano(),
|
CreatedAt: createdAt.UnixNano(),
|
||||||
Network: &runtime.PodSandboxNetworkStatus{Ip: ip},
|
Network: &runtime.PodSandboxNetworkStatus{Ip: ip},
|
||||||
Linux: &runtime.LinuxPodSandboxStatus{
|
Linux: &runtime.LinuxPodSandboxStatus{
|
||||||
@ -78,7 +77,21 @@ func TestPodSandboxStatus(t *testing.T) {
|
|||||||
Labels: config.GetLabels(),
|
Labels: config.GetLabels(),
|
||||||
Annotations: config.GetAnnotations(),
|
Annotations: config.GetAnnotations(),
|
||||||
}
|
}
|
||||||
|
for _, status := range []containerd.ProcessStatus{
|
||||||
got := toCRISandboxStatus(sandbox.Metadata, state, createdAt, ip)
|
"",
|
||||||
|
containerd.Running,
|
||||||
|
containerd.Created,
|
||||||
|
containerd.Stopped,
|
||||||
|
containerd.Paused,
|
||||||
|
containerd.Pausing,
|
||||||
|
containerd.Unknown,
|
||||||
|
} {
|
||||||
|
state := runtime.PodSandboxState_SANDBOX_NOTREADY
|
||||||
|
if status == containerd.Running {
|
||||||
|
state = runtime.PodSandboxState_SANDBOX_READY
|
||||||
|
}
|
||||||
|
expected.State = state
|
||||||
|
got := toCRISandboxStatus(sandbox.Metadata, status, createdAt, ip)
|
||||||
assert.Equal(t, expected, got)
|
assert.Equal(t, expected, got)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,6 @@ type Image struct {
|
|||||||
Size int64
|
Size int64
|
||||||
// ImageSpec is the oci image structure which describes basic information about the image.
|
// ImageSpec is the oci image structure which describes basic information about the image.
|
||||||
ImageSpec imagespec.Image
|
ImageSpec imagespec.Image
|
||||||
|
|
||||||
// Containerd image reference
|
// Containerd image reference
|
||||||
Image containerd.Image
|
Image containerd.Image
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
imagespec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||||
assertlib "github.com/stretchr/testify/assert"
|
assertlib "github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
"github.com/kubernetes-incubator/cri-containerd/pkg/store"
|
"github.com/kubernetes-incubator/cri-containerd/pkg/store"
|
||||||
@ -33,6 +34,7 @@ func TestImageStore(t *testing.T) {
|
|||||||
RepoTags: []string{"tag-1"},
|
RepoTags: []string{"tag-1"},
|
||||||
RepoDigests: []string{"digest-1"},
|
RepoDigests: []string{"digest-1"},
|
||||||
Size: 10,
|
Size: 10,
|
||||||
|
ImageSpec: imagespec.Image{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ID: "sha256:2123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
|
ID: "sha256:2123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
|
||||||
@ -40,6 +42,7 @@ func TestImageStore(t *testing.T) {
|
|||||||
RepoTags: []string{"tag-2abcd"},
|
RepoTags: []string{"tag-2abcd"},
|
||||||
RepoDigests: []string{"digest-2abcd"},
|
RepoDigests: []string{"digest-2abcd"},
|
||||||
Size: 20,
|
Size: 20,
|
||||||
|
ImageSpec: imagespec.Image{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ID: "sha256:3123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
|
ID: "sha256:3123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
|
||||||
@ -47,6 +50,7 @@ func TestImageStore(t *testing.T) {
|
|||||||
RepoDigests: []string{"digest-4a333"},
|
RepoDigests: []string{"digest-4a333"},
|
||||||
ChainID: "test-chain-id-4a333",
|
ChainID: "test-chain-id-4a333",
|
||||||
Size: 30,
|
Size: 30,
|
||||||
|
ImageSpec: imagespec.Image{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ID: "sha256:4123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
|
ID: "sha256:4123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
|
||||||
@ -54,6 +58,7 @@ func TestImageStore(t *testing.T) {
|
|||||||
RepoDigests: []string{"digest-4abcd"},
|
RepoDigests: []string{"digest-4abcd"},
|
||||||
ChainID: "test-chain-id-4abcd",
|
ChainID: "test-chain-id-4abcd",
|
||||||
Size: 40,
|
Size: 40,
|
||||||
|
ImageSpec: imagespec.Image{},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert := assertlib.New(t)
|
assert := assertlib.New(t)
|
||||||
|
Loading…
Reference in New Issue
Block a user