Skip to content

Commit

Permalink
Merge pull request kubernetes#116742 from moshe010/fix-pod-resource-a…
Browse files Browse the repository at this point in the history
…pi-ut

kubelet PodResources API: follow-up review comments
  • Loading branch information
k8s-ci-robot committed Jun 6, 2023
2 parents 299b72c + 1031977 commit 3d4a243
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
11 changes: 7 additions & 4 deletions pkg/kubelet/apis/podresources/server_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,10 @@ func (p *v1PodResourcesServer) List(ctx context.Context, req *v1.ListPodResource
podResources[i] = &pRes
}

return &v1.ListPodResourcesResponse{
response := &v1.ListPodResourcesResponse{
PodResources: podResources,
}, nil
}
return response, nil
}

// GetAllocatableResources returns information about all the resources known by the server - this more like the capacity, not like the current amount of free resources.
Expand All @@ -94,11 +95,13 @@ func (p *v1PodResourcesServer) GetAllocatableResources(ctx context.Context, req
return nil, fmt.Errorf("PodResources API GetAllocatableResources disabled")
}

return &v1.AllocatableResourcesResponse{
response := &v1.AllocatableResourcesResponse{
Devices: p.devicesProvider.GetAllocatableDevices(),
CpuIds: p.cpusProvider.GetAllocatableCPUs(),
Memory: p.memoryProvider.GetAllocatableMemory(),
}, nil
}

return response, nil
}

// Get returns information about the resources assigned to a specific pod
Expand Down
15 changes: 9 additions & 6 deletions pkg/kubelet/apis/podresources/server_v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import (
)

func TestListPodResourcesV1(t *testing.T) {
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, pkgfeatures.KubeletPodResourcesDynamicResources, true)()

podName := "pod-name"
podNamespace := "pod-namespace"
podUID := types.UID("pod-uid")
Expand Down Expand Up @@ -213,7 +215,6 @@ func TestListPodResourcesV1(t *testing.T) {
},
} {
t.Run(tc.desc, func(t *testing.T) {
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, pkgfeatures.KubeletPodResourcesDynamicResources, true)()
mockDevicesProvider := podresourcetest.NewMockDevicesProvider(mockCtrl)
mockPodsProvider := podresourcetest.NewMockPodsProvider(mockCtrl)
mockCPUsProvider := podresourcetest.NewMockCPUsProvider(mockCtrl)
Expand Down Expand Up @@ -545,6 +546,9 @@ func TestAllocatableResources(t *testing.T) {
}

func TestGetPodResourcesV1(t *testing.T) {
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, pkgfeatures.KubeletPodResourcesGet, true)()
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, pkgfeatures.KubeletPodResourcesDynamicResources, true)()

podName := "pod-name"
podNamespace := "pod-namespace"
podUID := types.UID("pod-uid")
Expand Down Expand Up @@ -677,8 +681,6 @@ func TestGetPodResourcesV1(t *testing.T) {
},
} {
t.Run(tc.desc, func(t *testing.T) {
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, pkgfeatures.KubeletPodResourcesGet, true)()
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, pkgfeatures.KubeletPodResourcesDynamicResources, true)()
mockDevicesProvider := podresourcetest.NewMockDevicesProvider(mockCtrl)
mockPodsProvider := podresourcetest.NewMockPodsProvider(mockCtrl)
mockCPUsProvider := podresourcetest.NewMockCPUsProvider(mockCtrl)
Expand Down Expand Up @@ -754,15 +756,15 @@ func equalListResponse(respA, respB *podresourcesapi.ListPodResourcesResponse) b
return false
}

if !euqalDynamicResources(cntA.DynamicResources, cntB.DynamicResources) {
if !equalDynamicResources(cntA.DynamicResources, cntB.DynamicResources) {
return false
}
}
}
return true
}

func euqalDynamicResources(draResA, draResB []*podresourcesapi.DynamicResource) bool {
func equalDynamicResources(draResA, draResB []*podresourcesapi.DynamicResource) bool {
if len(draResA) != len(draResB) {
return false
}
Expand Down Expand Up @@ -801,6 +803,7 @@ func euqalDynamicResources(draResA, draResB []*podresourcesapi.DynamicResource)

return true
}

func equalContainerDevices(devA, devB []*podresourcesapi.ContainerDevices) bool {
if len(devA) != len(devB) {
return false
Expand Down Expand Up @@ -890,7 +893,7 @@ func equalGetResponse(ResA, ResB *podresourcesapi.GetPodResourcesResponse) bool
return false
}

if !euqalDynamicResources(cntA.DynamicResources, cntB.DynamicResources) {
if !equalDynamicResources(cntA.DynamicResources, cntB.DynamicResources) {
return false
}

Expand Down

0 comments on commit 3d4a243

Please sign in to comment.