mirror of https://github.com/k3s-io/k3s
commit
accd6a49be
|
@ -997,16 +997,31 @@ func (r *Runtime) GetPods(all bool) ([]*kubecontainer.Pod, error) {
|
||||||
return nil, fmt.Errorf("couldn't list pods: %v", err)
|
return nil, fmt.Errorf("couldn't list pods: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var pods []*kubecontainer.Pod
|
pods := make(map[types.UID]*kubecontainer.Pod)
|
||||||
for _, pod := range listResp.Pods {
|
for _, pod := range listResp.Pods {
|
||||||
pod, err := r.convertRktPod(pod)
|
pod, err := r.convertRktPod(pod)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Warningf("rkt: Cannot construct pod from unit file: %v.", err)
|
glog.Warningf("rkt: Cannot construct pod from unit file: %v.", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
pods = append(pods, pod)
|
|
||||||
|
// Group pods together.
|
||||||
|
oldPod, found := pods[pod.ID]
|
||||||
|
if !found {
|
||||||
|
pods[pod.ID] = pod
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
oldPod.Containers = append(oldPod.Containers, pod.Containers...)
|
||||||
}
|
}
|
||||||
return pods, nil
|
|
||||||
|
// Convert map to list.
|
||||||
|
var result []*kubecontainer.Pod
|
||||||
|
for _, p := range pods {
|
||||||
|
result = append(result, p)
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// KillPod invokes 'systemctl kill' to kill the unit that runs the pod.
|
// KillPod invokes 'systemctl kill' to kill the unit that runs the pod.
|
||||||
|
|
|
@ -409,7 +409,17 @@ func TestGetPods(t *testing.T) {
|
||||||
[]string{"img-id-11", "img-id-22"},
|
[]string{"img-id-11", "img-id-22"},
|
||||||
[]string{"img-name-11", "img-name-22"},
|
[]string{"img-name-11", "img-name-22"},
|
||||||
[]string{"10011", "10022"},
|
[]string{"10011", "10022"},
|
||||||
[]rktapi.AppState{rktapi.AppState_APP_STATE_RUNNING, rktapi.AppState_APP_STATE_EXITED},
|
[]rktapi.AppState{rktapi.AppState_APP_STATE_EXITED, rktapi.AppState_APP_STATE_EXITED},
|
||||||
|
[]int32{0, 0},
|
||||||
|
),
|
||||||
|
makeRktPod(rktapi.PodState_POD_STATE_EXITED,
|
||||||
|
"uuid-4004", "43", "guestbook", "default",
|
||||||
|
"10.10.10.44", "100000", "8",
|
||||||
|
[]string{"app-11", "app-22"},
|
||||||
|
[]string{"img-id-11", "img-id-22"},
|
||||||
|
[]string{"img-name-11", "img-name-22"},
|
||||||
|
[]string{"10011", "10022"},
|
||||||
|
[]rktapi.AppState{rktapi.AppState_APP_STATE_RUNNING, rktapi.AppState_APP_STATE_RUNNING},
|
||||||
[]int32{0, 0},
|
[]int32{0, 0},
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
@ -448,7 +458,7 @@ func TestGetPods(t *testing.T) {
|
||||||
Image: "img-name-11",
|
Image: "img-name-11",
|
||||||
Hash: 10011,
|
Hash: 10011,
|
||||||
Created: 90000,
|
Created: 90000,
|
||||||
State: "running",
|
State: "exited",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ID: kubecontainer.BuildContainerID("rkt", "uuid-4003:app-22"),
|
ID: kubecontainer.BuildContainerID("rkt", "uuid-4003:app-22"),
|
||||||
|
@ -458,6 +468,22 @@ func TestGetPods(t *testing.T) {
|
||||||
Created: 90000,
|
Created: 90000,
|
||||||
State: "exited",
|
State: "exited",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
ID: kubecontainer.BuildContainerID("rkt", "uuid-4004:app-11"),
|
||||||
|
Name: "app-11",
|
||||||
|
Image: "img-name-11",
|
||||||
|
Hash: 10011,
|
||||||
|
Created: 100000,
|
||||||
|
State: "running",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ID: kubecontainer.BuildContainerID("rkt", "uuid-4004:app-22"),
|
||||||
|
Name: "app-22",
|
||||||
|
Image: "img-name-22",
|
||||||
|
Hash: 10022,
|
||||||
|
Created: 100000,
|
||||||
|
State: "running",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue