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

Skip to content
Closed
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
24 changes: 12 additions & 12 deletions internal/lib/container_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
26 changes: 16 additions & 10 deletions server/sandbox_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions test/drop_infra.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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" != "{}" ]]
}