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