Skip to content

Commit 1b273b3

Browse files
authored
Merge pull request kubernetes#130653 from yliaog/master
kubelet and scheduler for extended resource backed by DRA
2 parents 74f7a44 + 23d6f73 commit 1b273b3

File tree

106 files changed

+6770
-2039
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+6770
-2039
lines changed

api/openapi-spec/swagger.json

Lines changed: 61 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/openapi-spec/v3/api__v1_openapi.json

Lines changed: 62 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/openapi-spec/v3/apis__resource.k8s.io__v1_openapi.json

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/openapi-spec/v3/apis__resource.k8s.io__v1beta1_openapi.json

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/openapi-spec/v3/apis__resource.k8s.io__v1beta2_openapi.json

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/api/pod/util.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,6 +1009,10 @@ func dropDisabledPodStatusFields(podStatus, oldPodStatus *api.PodStatus, podSpec
10091009
podStatus.ResourceClaimStatuses = nil
10101010
}
10111011

1012+
if !utilfeature.DefaultFeatureGate.Enabled(features.DRAExtendedResource) && !draExendedResourceInUse(oldPodStatus) {
1013+
podStatus.ExtendedResourceClaimStatus = nil
1014+
}
1015+
10121016
if !utilfeature.DefaultFeatureGate.Enabled(features.RecursiveReadOnlyMounts) && !rroInUse(oldPodSpec) {
10131017
for i := range podStatus.ContainerStatuses {
10141018
podStatus.ContainerStatuses[i].VolumeMounts = nil
@@ -1064,15 +1068,21 @@ func dropDisabledDynamicResourceAllocationFields(podSpec, oldPodSpec *api.PodSpe
10641068
}
10651069
}
10661070

1067-
func dynamicResourceAllocationInUse(podSpec *api.PodSpec) bool {
1068-
if podSpec == nil {
1069-
return false
1071+
func draExendedResourceInUse(podStatus *api.PodStatus) bool {
1072+
if podStatus != nil && podStatus.ExtendedResourceClaimStatus != nil {
1073+
return true
10701074
}
1075+
return false
1076+
}
10711077

1078+
func dynamicResourceAllocationInUse(podSpec *api.PodSpec) bool {
10721079
// We only need to check this field because the containers cannot have
10731080
// resource requirements entries for claims without a corresponding
10741081
// entry at the pod spec level.
1075-
return len(podSpec.ResourceClaims) > 0
1082+
if podSpec != nil && len(podSpec.ResourceClaims) > 0 {
1083+
return true
1084+
}
1085+
return false
10761086
}
10771087

10781088
func dropResourceClaimRequests(containers []api.Container) {

pkg/api/pod/util_test.go

Lines changed: 74 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -895,15 +895,35 @@ func TestDropDynamicResourceAllocation(t *testing.T) {
895895
EphemeralContainers: []api.EphemeralContainer{{}},
896896
},
897897
}
898+
podWithExtendedResource := &api.Pod{
899+
Spec: api.PodSpec{
900+
Containers: []api.Container{{}},
901+
InitContainers: []api.Container{{}},
902+
EphemeralContainers: []api.EphemeralContainer{{}},
903+
},
904+
Status: api.PodStatus{
905+
ExtendedResourceClaimStatus: &api.PodExtendedResourceClaimStatus{
906+
ResourceClaimName: "resource-claim-name",
907+
RequestMappings: []api.ContainerExtendedResourceRequest{
908+
{
909+
ContainerName: "c",
910+
ResourceName: "e",
911+
RequestName: "c-0-r-0",
912+
},
913+
},
914+
},
915+
},
916+
}
898917

899918
var noPod *api.Pod
900919

901920
testcases := []struct {
902-
description string
903-
enabled bool
904-
oldPod *api.Pod
905-
newPod *api.Pod
906-
wantPod *api.Pod
921+
description string
922+
enabled bool
923+
extendedEnabled bool
924+
oldPod *api.Pod
925+
newPod *api.Pod
926+
wantPod *api.Pod
907927
}{
908928
{
909929
description: "old with claims / new with claims / disabled",
@@ -986,11 +1006,60 @@ func TestDropDynamicResourceAllocation(t *testing.T) {
9861006
newPod: podWithoutClaims,
9871007
wantPod: podWithoutClaims,
9881008
},
1009+
{
1010+
description: "extended resource / no old pod/ new with extended resource / disabled",
1011+
enabled: false,
1012+
extendedEnabled: false,
1013+
oldPod: noPod,
1014+
newPod: podWithExtendedResource,
1015+
wantPod: podWithoutClaims,
1016+
},
1017+
{
1018+
description: "extended resource / old without claim / new with extended resource / disabled",
1019+
enabled: false,
1020+
extendedEnabled: false,
1021+
oldPod: podWithoutClaims,
1022+
newPod: podWithExtendedResource,
1023+
wantPod: podWithoutClaims,
1024+
},
1025+
{
1026+
description: "extended resource / no old pod/ new with extended resource / extended disabled only",
1027+
enabled: true,
1028+
extendedEnabled: false,
1029+
oldPod: noPod,
1030+
newPod: podWithExtendedResource,
1031+
wantPod: podWithoutClaims,
1032+
},
1033+
{
1034+
description: "extended resource / old without claim / new with extended resource / extended disabled only",
1035+
enabled: true,
1036+
extendedEnabled: false,
1037+
oldPod: podWithoutClaims,
1038+
newPod: podWithExtendedResource,
1039+
wantPod: podWithoutClaims,
1040+
},
1041+
{
1042+
description: "extended resource / no old pod/ new with extended resource / enabled",
1043+
enabled: true,
1044+
extendedEnabled: true,
1045+
oldPod: noPod,
1046+
newPod: podWithExtendedResource,
1047+
wantPod: podWithExtendedResource,
1048+
},
1049+
{
1050+
description: "extended resource / old without claim / new with extended resource / enabled",
1051+
enabled: true,
1052+
extendedEnabled: true,
1053+
oldPod: podWithoutClaims,
1054+
newPod: podWithExtendedResource,
1055+
wantPod: podWithExtendedResource,
1056+
},
9891057
}
9901058

9911059
for _, tc := range testcases {
9921060
t.Run(tc.description, func(t *testing.T) {
9931061
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.DynamicResourceAllocation, tc.enabled)
1062+
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.DRAExtendedResource, tc.extendedEnabled)
9941063

9951064
oldPod := tc.oldPod.DeepCopy()
9961065
newPod := tc.newPod.DeepCopy()

pkg/apis/core/types.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3934,6 +3934,28 @@ type PodResourceClaimStatus struct {
39343934
ResourceClaimName *string
39353935
}
39363936

3937+
// PodExtendedResourceClaimStatus is stored in the PodStatus for the extended
3938+
// resource requests backed by DRA. It stores the generated name for
3939+
// the corresponding special ResourceClaim created by the scheduler.
3940+
type PodExtendedResourceClaimStatus struct {
3941+
// RequestMapping identifies the mapping of <container, extended resource backed by DRA> to device request
3942+
// in the generated ResourceClaim.
3943+
RequestMappings []ContainerExtendedResourceRequest
3944+
3945+
// ResourceClaimName is the name of the ResourceClaim that was
3946+
// generated for the Pod in the namespace of the Pod.
3947+
ResourceClaimName string
3948+
}
3949+
3950+
type ContainerExtendedResourceRequest struct {
3951+
// The name of the container requesting resources.
3952+
ContainerName string
3953+
// The name of the extended resource in that container which gets backed by DRA.
3954+
ResourceName string
3955+
// The name of the request in the special ResourceClaim which corresponds to the extended resource.
3956+
RequestName string
3957+
}
3958+
39373959
// OSName is the set of OS'es that can be used in OS.
39383960
type OSName string
39393961

@@ -4535,6 +4557,11 @@ type PodStatus struct {
45354557
// +featureGate=DynamicResourceAllocation
45364558
// +optional
45374559
ResourceClaimStatuses []PodResourceClaimStatus
4560+
4561+
// Status of claim of extended resource backed by DRA.
4562+
// +featureGate=DRAExtendedResource
4563+
// +optional
4564+
ExtendedResourceClaimStatus *PodExtendedResourceClaimStatus
45384565
}
45394566

45404567
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

0 commit comments

Comments
 (0)