mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-19 08:40:42 +00:00
Merge pull request #116742 from moshe010/fix-pod-resource-api-ut
kubelet PodResources API: follow-up review comments
This commit is contained in:
commit
3d4a243742
@ -79,9 +79,10 @@ func (p *v1PodResourcesServer) List(ctx context.Context, req *v1.ListPodResource
|
|||||||
podResources[i] = &pRes
|
podResources[i] = &pRes
|
||||||
}
|
}
|
||||||
|
|
||||||
return &v1.ListPodResourcesResponse{
|
response := &v1.ListPodResourcesResponse{
|
||||||
PodResources: podResources,
|
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.
|
// GetAllocatableResources returns information about all the resources known by the server - this more like the capacity, not like the current amount of free resources.
|
||||||
@ -94,11 +95,13 @@ func (p *v1PodResourcesServer) GetAllocatableResources(ctx context.Context, req
|
|||||||
return nil, fmt.Errorf("PodResources API GetAllocatableResources disabled")
|
return nil, fmt.Errorf("PodResources API GetAllocatableResources disabled")
|
||||||
}
|
}
|
||||||
|
|
||||||
return &v1.AllocatableResourcesResponse{
|
response := &v1.AllocatableResourcesResponse{
|
||||||
Devices: p.devicesProvider.GetAllocatableDevices(),
|
Devices: p.devicesProvider.GetAllocatableDevices(),
|
||||||
CpuIds: p.cpusProvider.GetAllocatableCPUs(),
|
CpuIds: p.cpusProvider.GetAllocatableCPUs(),
|
||||||
Memory: p.memoryProvider.GetAllocatableMemory(),
|
Memory: p.memoryProvider.GetAllocatableMemory(),
|
||||||
}, nil
|
}
|
||||||
|
|
||||||
|
return response, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get returns information about the resources assigned to a specific pod
|
// Get returns information about the resources assigned to a specific pod
|
||||||
|
@ -35,6 +35,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestListPodResourcesV1(t *testing.T) {
|
func TestListPodResourcesV1(t *testing.T) {
|
||||||
|
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, pkgfeatures.KubeletPodResourcesDynamicResources, true)()
|
||||||
|
|
||||||
podName := "pod-name"
|
podName := "pod-name"
|
||||||
podNamespace := "pod-namespace"
|
podNamespace := "pod-namespace"
|
||||||
podUID := types.UID("pod-uid")
|
podUID := types.UID("pod-uid")
|
||||||
@ -213,7 +215,6 @@ func TestListPodResourcesV1(t *testing.T) {
|
|||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
t.Run(tc.desc, func(t *testing.T) {
|
t.Run(tc.desc, func(t *testing.T) {
|
||||||
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, pkgfeatures.KubeletPodResourcesDynamicResources, true)()
|
|
||||||
mockDevicesProvider := podresourcetest.NewMockDevicesProvider(mockCtrl)
|
mockDevicesProvider := podresourcetest.NewMockDevicesProvider(mockCtrl)
|
||||||
mockPodsProvider := podresourcetest.NewMockPodsProvider(mockCtrl)
|
mockPodsProvider := podresourcetest.NewMockPodsProvider(mockCtrl)
|
||||||
mockCPUsProvider := podresourcetest.NewMockCPUsProvider(mockCtrl)
|
mockCPUsProvider := podresourcetest.NewMockCPUsProvider(mockCtrl)
|
||||||
@ -545,6 +546,9 @@ func TestAllocatableResources(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestGetPodResourcesV1(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"
|
podName := "pod-name"
|
||||||
podNamespace := "pod-namespace"
|
podNamespace := "pod-namespace"
|
||||||
podUID := types.UID("pod-uid")
|
podUID := types.UID("pod-uid")
|
||||||
@ -677,8 +681,6 @@ func TestGetPodResourcesV1(t *testing.T) {
|
|||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
t.Run(tc.desc, func(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)
|
mockDevicesProvider := podresourcetest.NewMockDevicesProvider(mockCtrl)
|
||||||
mockPodsProvider := podresourcetest.NewMockPodsProvider(mockCtrl)
|
mockPodsProvider := podresourcetest.NewMockPodsProvider(mockCtrl)
|
||||||
mockCPUsProvider := podresourcetest.NewMockCPUsProvider(mockCtrl)
|
mockCPUsProvider := podresourcetest.NewMockCPUsProvider(mockCtrl)
|
||||||
@ -754,7 +756,7 @@ func equalListResponse(respA, respB *podresourcesapi.ListPodResourcesResponse) b
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if !euqalDynamicResources(cntA.DynamicResources, cntB.DynamicResources) {
|
if !equalDynamicResources(cntA.DynamicResources, cntB.DynamicResources) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -762,7 +764,7 @@ func equalListResponse(respA, respB *podresourcesapi.ListPodResourcesResponse) b
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func euqalDynamicResources(draResA, draResB []*podresourcesapi.DynamicResource) bool {
|
func equalDynamicResources(draResA, draResB []*podresourcesapi.DynamicResource) bool {
|
||||||
if len(draResA) != len(draResB) {
|
if len(draResA) != len(draResB) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@ -801,6 +803,7 @@ func euqalDynamicResources(draResA, draResB []*podresourcesapi.DynamicResource)
|
|||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func equalContainerDevices(devA, devB []*podresourcesapi.ContainerDevices) bool {
|
func equalContainerDevices(devA, devB []*podresourcesapi.ContainerDevices) bool {
|
||||||
if len(devA) != len(devB) {
|
if len(devA) != len(devB) {
|
||||||
return false
|
return false
|
||||||
@ -890,7 +893,7 @@ func equalGetResponse(ResA, ResB *podresourcesapi.GetPodResourcesResponse) bool
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if !euqalDynamicResources(cntA.DynamicResources, cntB.DynamicResources) {
|
if !equalDynamicResources(cntA.DynamicResources, cntB.DynamicResources) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user