diff --git a/internal/lib/container_server.go b/internal/lib/container_server.go index 2f5f6ef27ef..9e303001a82 100644 --- a/internal/lib/container_server.go +++ b/internal/lib/container_server.go @@ -277,21 +277,21 @@ func (c *ContainerServer) LoadSandbox(ctx context.Context, id string) (sb *sandb if err != nil { return sb, err } - scontainer.SetSpec(&m) - scontainer.SetMountPoint(m.Annotations[annotations.MountPoint]) - - if m.Annotations[annotations.Volumes] != "" { - containerVolumes := []oci.ContainerVolume{} - if err = json.Unmarshal([]byte(m.Annotations[annotations.Volumes]), &containerVolumes); err != nil { - return sb, fmt.Errorf("failed to unmarshal container volumes: %v", err) - } - for _, cv := range containerVolumes { - scontainer.AddVolume(cv) - } - } } else { scontainer = oci.NewSpoofedContainer(cID, cname, labels, id, created, sandboxPath) } + scontainer.SetSpec(&m) + scontainer.SetMountPoint(m.Annotations[annotations.MountPoint]) + + if m.Annotations[annotations.Volumes] != "" { + containerVolumes := []oci.ContainerVolume{} + if err = json.Unmarshal([]byte(m.Annotations[annotations.Volumes]), &containerVolumes); err != nil { + return sb, fmt.Errorf("failed to unmarshal container volumes: %v", err) + } + for _, cv := range containerVolumes { + scontainer.AddVolume(cv) + } + } if err := c.ContainerStateFromDisk(ctx, scontainer); err != nil { return sb, fmt.Errorf("error reading sandbox state from disk %q: %v", scontainer.ID(), err) diff --git a/server/sandbox_status.go b/server/sandbox_status.go index 5be37282151..0f54192b475 100644 --- a/server/sandbox_status.go +++ b/server/sandbox_status.go @@ -81,17 +81,23 @@ func toPodIPs(ips []string) (result []*types.PodIP) { } func createSandboxInfo(c *oci.Container) (map[string]string, error) { + var info interface{} if c.Spoofed() { - return map[string]string{"info": "{}"}, nil - } - info := struct { - Image string `json:"image"` - Pid int `json:"pid"` - RuntimeSpec spec.Spec `json:"runtimeSpec,omitempty"` - }{ - c.Image(), - c.State().Pid, - c.Spec(), + info = struct { + RuntimeSpec spec.Spec `json:"runtimeSpec,omitempty"` + }{ + c.Spec(), + } + } else { + info = struct { + Image string `json:"image"` + Pid int `json:"pid"` + RuntimeSpec spec.Spec `json:"runtimeSpec,omitempty"` + }{ + c.Image(), + c.State().Pid, + c.Spec(), + } } bytes, err := json.Marshal(info) if err != nil { diff --git a/test/drop_infra.bats b/test/drop_infra.bats index db01c950ed9..e86ea7b76b5 100644 --- a/test/drop_infra.bats +++ b/test/drop_infra.bats @@ -33,3 +33,11 @@ function teardown() { output=$(runtime list) [[ "$output" = *"$pod_id"* ]] } + +@test "test infra ctr dropped status" { + jq '.linux.security_context.namespace_options.pid = 1' \ + "$TESTDATA"/sandbox_config.json > "$TESTDIR"/sandbox_no_infra.json + pod_id=$(crictl runp "$TESTDIR"/sandbox_no_infra.json) + output=$(crictl inspectp "$pod_id" | jq .info ) + [[ "$output" != "{}" ]] +}