Skip to content

Commit 70e2559

Browse files
committed
use runtime sandbox status instead of calling cri
1 parent c24349e commit 70e2559

File tree

4 files changed

+9
-32
lines changed

4 files changed

+9
-32
lines changed

pkg/kubelet/BUILD

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,6 @@ go_test(
251251
"//staging/src/k8s.io/component-base/featuregate/testing:go_default_library",
252252
"//staging/src/k8s.io/component-base/version:go_default_library",
253253
"//staging/src/k8s.io/cri-api/pkg/apis/runtime/v1alpha2:go_default_library",
254-
"//staging/src/k8s.io/cri-api/pkg/apis/testing:go_default_library",
255254
"//vendor/github.com/google/cadvisor/info/v1:go_default_library",
256255
"//vendor/github.com/google/cadvisor/info/v2:go_default_library",
257256
"//vendor/github.com/stretchr/testify/assert:go_default_library",

pkg/kubelet/container/runtime.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,6 @@ type PodStatus struct {
281281
// Status of containers in the pod.
282282
ContainerStatuses []*ContainerStatus
283283
// Status of the pod sandbox.
284-
// Only for kuberuntime now, other runtime may keep it nil.
285284
SandboxStatuses []*runtimeapi.PodSandboxStatus
286285
}
287286

pkg/kubelet/kubelet_pods.go

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -941,18 +941,10 @@ func (kl *Kubelet) PodResourcesAreReclaimed(pod *v1.Pod, status v1.PodStatus) bo
941941
return false
942942
}
943943
// pod's sandboxes should be deleted
944-
filter := &runtimeapi.PodSandboxFilter{
945-
LabelSelector: map[string]string{kubetypes.KubernetesPodUIDLabel: string(pod.UID)},
946-
}
947-
sandboxes, err := kl.runtimeService.ListPodSandbox(filter)
948-
if err != nil {
949-
klog.V(3).Infof("Pod %q is terminated, Error getting pod sandboxes from the runtime service: %s", format.Pod(pod), err)
950-
return false
951-
}
952-
if len(sandboxes) > 0 {
944+
if len(runtimeStatus.SandboxStatuses) > 0 {
953945
var sandboxStr string
954-
for _, sandbox := range sandboxes {
955-
sandboxStr += fmt.Sprintf("%+v ", sandbox)
946+
for _, sandbox := range runtimeStatus.SandboxStatuses {
947+
sandboxStr += fmt.Sprintf("%+v ", *sandbox)
956948
}
957949
klog.V(3).Infof("Pod %q is terminated, but some pod sandboxes have not been cleaned up: %s", format.Pod(pod), sandboxStr)
958950
return false

pkg/kubelet/kubelet_pods_test.go

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"errors"
2121
"fmt"
2222
"io/ioutil"
23-
kubetypes "k8s.io/kubernetes/pkg/kubelet/types"
2423
"os"
2524
"path/filepath"
2625
"sort"
@@ -44,7 +43,6 @@ import (
4443
// to "v1"?
4544

4645
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
47-
apitest "k8s.io/cri-api/pkg/apis/testing"
4846
_ "k8s.io/kubernetes/pkg/apis/core/install"
4947
"k8s.io/kubernetes/pkg/features"
5048
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
@@ -2389,7 +2387,7 @@ func TestTruncatePodHostname(t *testing.T) {
23892387
}
23902388
}
23912389

2392-
func TestKubelet_PodResourcesAreReclaimed(t *testing.T) {
2390+
func TestPodResourcesAreReclaimed(t *testing.T) {
23932391

23942392
type args struct {
23952393
pod *v1.Pod
@@ -2430,12 +2428,13 @@ func TestKubelet_PodResourcesAreReclaimed(t *testing.T) {
24302428
{
24312429
"pod with sandbox present",
24322430
args{
2433-
pod: &v1.Pod{
2434-
ObjectMeta: metav1.ObjectMeta{
2435-
UID: types.UID("fakesandbox"),
2431+
pod: &v1.Pod{},
2432+
status: v1.PodStatus{},
2433+
runtimeStatus: kubecontainer.PodStatus{
2434+
SandboxStatuses: []*runtimeapi.PodSandboxStatus{
2435+
{},
24362436
},
24372437
},
2438-
status: v1.PodStatus{},
24392438
},
24402439
false,
24412440
},
@@ -2445,18 +2444,6 @@ func TestKubelet_PodResourcesAreReclaimed(t *testing.T) {
24452444
defer testKubelet.Cleanup()
24462445
kl := testKubelet.kubelet
24472446

2448-
runtimeService := apitest.NewFakeRuntimeService()
2449-
runtimeService.SetFakeSandboxes([]*apitest.FakePodSandbox{
2450-
{
2451-
PodSandboxStatus: runtimeapi.PodSandboxStatus{
2452-
Id: "fakesandbox",
2453-
Labels: map[string]string{
2454-
kubetypes.KubernetesPodUIDLabel: "fakesandbox",
2455-
},
2456-
},
2457-
},
2458-
})
2459-
kl.runtimeService = runtimeService
24602447
for _, tt := range tests {
24612448
t.Run(tt.name, func(t *testing.T) {
24622449
testKubelet.fakeRuntime.PodStatus = tt.args.runtimeStatus

0 commit comments

Comments
 (0)