commit
737efe70a7
@ -46,8 +46,6 @@ func (c *criContainerdService) PodSandboxStatus(ctx context.Context, r *runtime.
|
||||
|
||||
var pid uint32
|
||||
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 task != nil {
|
||||
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)
|
||||
}
|
||||
|
||||
if taskStatus.Status == containerd.Running {
|
||||
state = runtime.PodSandboxState_SANDBOX_READY
|
||||
}
|
||||
pid = task.Pid()
|
||||
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)
|
||||
}
|
||||
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())
|
||||
if err != nil {
|
||||
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.
|
||||
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()
|
||||
return &runtime.PodSandboxStatus{
|
||||
Id: meta.ID,
|
||||
|
@ -20,6 +20,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/containerd/containerd"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
|
||||
|
||||
@ -58,12 +59,10 @@ func TestPodSandboxStatus(t *testing.T) {
|
||||
Config: config,
|
||||
},
|
||||
}
|
||||
state := runtime.PodSandboxState_SANDBOX_NOTREADY
|
||||
|
||||
expected := &runtime.PodSandboxStatus{
|
||||
Id: id,
|
||||
Metadata: config.GetMetadata(),
|
||||
State: state,
|
||||
CreatedAt: createdAt.UnixNano(),
|
||||
Network: &runtime.PodSandboxNetworkStatus{Ip: ip},
|
||||
Linux: &runtime.LinuxPodSandboxStatus{
|
||||
@ -78,7 +77,21 @@ func TestPodSandboxStatus(t *testing.T) {
|
||||
Labels: config.GetLabels(),
|
||||
Annotations: config.GetAnnotations(),
|
||||
}
|
||||
|
||||
got := toCRISandboxStatus(sandbox.Metadata, state, createdAt, ip)
|
||||
assert.Equal(t, expected, got)
|
||||
for _, status := range []containerd.ProcessStatus{
|
||||
"",
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
@ -42,7 +42,6 @@ type Image struct {
|
||||
Size int64
|
||||
// ImageSpec is the oci image structure which describes basic information about the image.
|
||||
ImageSpec imagespec.Image
|
||||
|
||||
// Containerd image reference
|
||||
Image containerd.Image
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
imagespec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
assertlib "github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/kubernetes-incubator/cri-containerd/pkg/store"
|
||||
@ -33,6 +34,7 @@ func TestImageStore(t *testing.T) {
|
||||
RepoTags: []string{"tag-1"},
|
||||
RepoDigests: []string{"digest-1"},
|
||||
Size: 10,
|
||||
ImageSpec: imagespec.Image{},
|
||||
},
|
||||
{
|
||||
ID: "sha256:2123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
|
||||
@ -40,6 +42,7 @@ func TestImageStore(t *testing.T) {
|
||||
RepoTags: []string{"tag-2abcd"},
|
||||
RepoDigests: []string{"digest-2abcd"},
|
||||
Size: 20,
|
||||
ImageSpec: imagespec.Image{},
|
||||
},
|
||||
{
|
||||
ID: "sha256:3123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
|
||||
@ -47,6 +50,7 @@ func TestImageStore(t *testing.T) {
|
||||
RepoDigests: []string{"digest-4a333"},
|
||||
ChainID: "test-chain-id-4a333",
|
||||
Size: 30,
|
||||
ImageSpec: imagespec.Image{},
|
||||
},
|
||||
{
|
||||
ID: "sha256:4123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
|
||||
@ -54,6 +58,7 @@ func TestImageStore(t *testing.T) {
|
||||
RepoDigests: []string{"digest-4abcd"},
|
||||
ChainID: "test-chain-id-4abcd",
|
||||
Size: 40,
|
||||
ImageSpec: imagespec.Image{},
|
||||
},
|
||||
}
|
||||
assert := assertlib.New(t)
|
||||
|
Loading…
Reference in New Issue
Block a user