use runtime sandbox status instead of calling cri
This commit is contained in:
parent
c24349e9f2
commit
70e2559aca
@ -251,7 +251,6 @@ go_test(
|
||||
"//staging/src/k8s.io/component-base/featuregate/testing:go_default_library",
|
||||
"//staging/src/k8s.io/component-base/version:go_default_library",
|
||||
"//staging/src/k8s.io/cri-api/pkg/apis/runtime/v1alpha2:go_default_library",
|
||||
"//staging/src/k8s.io/cri-api/pkg/apis/testing:go_default_library",
|
||||
"//vendor/github.com/google/cadvisor/info/v1:go_default_library",
|
||||
"//vendor/github.com/google/cadvisor/info/v2:go_default_library",
|
||||
"//vendor/github.com/stretchr/testify/assert:go_default_library",
|
||||
|
@ -281,7 +281,6 @@ type PodStatus struct {
|
||||
// Status of containers in the pod.
|
||||
ContainerStatuses []*ContainerStatus
|
||||
// Status of the pod sandbox.
|
||||
// Only for kuberuntime now, other runtime may keep it nil.
|
||||
SandboxStatuses []*runtimeapi.PodSandboxStatus
|
||||
}
|
||||
|
||||
|
@ -941,18 +941,10 @@ func (kl *Kubelet) PodResourcesAreReclaimed(pod *v1.Pod, status v1.PodStatus) bo
|
||||
return false
|
||||
}
|
||||
// pod's sandboxes should be deleted
|
||||
filter := &runtimeapi.PodSandboxFilter{
|
||||
LabelSelector: map[string]string{kubetypes.KubernetesPodUIDLabel: string(pod.UID)},
|
||||
}
|
||||
sandboxes, err := kl.runtimeService.ListPodSandbox(filter)
|
||||
if err != nil {
|
||||
klog.V(3).Infof("Pod %q is terminated, Error getting pod sandboxes from the runtime service: %s", format.Pod(pod), err)
|
||||
return false
|
||||
}
|
||||
if len(sandboxes) > 0 {
|
||||
if len(runtimeStatus.SandboxStatuses) > 0 {
|
||||
var sandboxStr string
|
||||
for _, sandbox := range sandboxes {
|
||||
sandboxStr += fmt.Sprintf("%+v ", sandbox)
|
||||
for _, sandbox := range runtimeStatus.SandboxStatuses {
|
||||
sandboxStr += fmt.Sprintf("%+v ", *sandbox)
|
||||
}
|
||||
klog.V(3).Infof("Pod %q is terminated, but some pod sandboxes have not been cleaned up: %s", format.Pod(pod), sandboxStr)
|
||||
return false
|
||||
|
@ -20,7 +20,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
kubetypes "k8s.io/kubernetes/pkg/kubelet/types"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
@ -44,7 +43,6 @@ import (
|
||||
// to "v1"?
|
||||
|
||||
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
|
||||
apitest "k8s.io/cri-api/pkg/apis/testing"
|
||||
_ "k8s.io/kubernetes/pkg/apis/core/install"
|
||||
"k8s.io/kubernetes/pkg/features"
|
||||
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
|
||||
@ -2389,7 +2387,7 @@ func TestTruncatePodHostname(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestKubelet_PodResourcesAreReclaimed(t *testing.T) {
|
||||
func TestPodResourcesAreReclaimed(t *testing.T) {
|
||||
|
||||
type args struct {
|
||||
pod *v1.Pod
|
||||
@ -2430,12 +2428,13 @@ func TestKubelet_PodResourcesAreReclaimed(t *testing.T) {
|
||||
{
|
||||
"pod with sandbox present",
|
||||
args{
|
||||
pod: &v1.Pod{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
UID: types.UID("fakesandbox"),
|
||||
pod: &v1.Pod{},
|
||||
status: v1.PodStatus{},
|
||||
runtimeStatus: kubecontainer.PodStatus{
|
||||
SandboxStatuses: []*runtimeapi.PodSandboxStatus{
|
||||
{},
|
||||
},
|
||||
},
|
||||
status: v1.PodStatus{},
|
||||
},
|
||||
false,
|
||||
},
|
||||
@ -2445,18 +2444,6 @@ func TestKubelet_PodResourcesAreReclaimed(t *testing.T) {
|
||||
defer testKubelet.Cleanup()
|
||||
kl := testKubelet.kubelet
|
||||
|
||||
runtimeService := apitest.NewFakeRuntimeService()
|
||||
runtimeService.SetFakeSandboxes([]*apitest.FakePodSandbox{
|
||||
{
|
||||
PodSandboxStatus: runtimeapi.PodSandboxStatus{
|
||||
Id: "fakesandbox",
|
||||
Labels: map[string]string{
|
||||
kubetypes.KubernetesPodUIDLabel: "fakesandbox",
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
kl.runtimeService = runtimeService
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
testKubelet.fakeRuntime.PodStatus = tt.args.runtimeStatus
|
||||
|
Loading…
Reference in New Issue
Block a user