@@ -705,7 +705,7 @@ var _ = Describe("DRA Client operations", func() {
705705 })
706706
707707 Context ("when device does not have deviceID attribute" , func () {
708- It ("should return an error " , func () {
708+ It ("should warn and skip the claim without failing " , func () {
709709 claimName := "test-claim"
710710 deviceName := "device-1"
711711 driverName := "test-driver.example.com"
@@ -785,13 +785,13 @@ var _ = Describe("DRA Client operations", func() {
785785 // Execute
786786 resourceMap := make (map [string ]* types.ResourceInfo )
787787 err = draClient .GetPodResourceMap (pod , resourceMap )
788- Expect (err ).To (HaveOccurred ())
789- Expect (err . Error ()) .To (ContainSubstring ( "not found for claim resource" ))
788+ Expect (err ).NotTo (HaveOccurred ())
789+ Expect (resourceMap ) .To (BeEmpty ( ))
790790 })
791791 })
792792
793793 Context ("when device has deviceID but missing resourceName attribute" , func () {
794- It ("should return an error " , func () {
794+ It ("should warn and skip without failing when nothing maps to a resource name " , func () {
795795 claimName := "test-claim"
796796 deviceName := "device-1"
797797 driverName := "test-driver.example.com"
@@ -846,13 +846,13 @@ var _ = Describe("DRA Client operations", func() {
846846
847847 resourceMap := make (map [string ]* types.ResourceInfo )
848848 err = draClient .GetPodResourceMap (pod , resourceMap )
849- Expect (err ).To (HaveOccurred ())
850- Expect (err . Error ()) .To (ContainSubstring ( multusResourceNameAttr ))
849+ Expect (err ).NotTo (HaveOccurred ())
850+ Expect (resourceMap ) .To (BeEmpty ( ))
851851 })
852852 })
853853
854854 Context ("when device name in allocation does not match any device in slice" , func () {
855- It ("should return an error " , func () {
855+ It ("should warn and skip the claim without failing " , func () {
856856 claimName := "test-claim"
857857 deviceName := "device-1"
858858 wrongDeviceName := "wrong-device"
@@ -934,8 +934,145 @@ var _ = Describe("DRA Client operations", func() {
934934 // Execute
935935 resourceMap := make (map [string ]* types.ResourceInfo )
936936 err = draClient .GetPodResourceMap (pod , resourceMap )
937- Expect (err ).To (HaveOccurred ())
938- Expect (err .Error ()).To (ContainSubstring ("not found for claim resource" ))
937+ Expect (err ).NotTo (HaveOccurred ())
938+ Expect (resourceMap ).To (BeEmpty ())
939+ })
940+
941+ It ("should preserve existing kubelet map entries when the claim maps nothing" , func () {
942+ claimName := "test-claim"
943+ deviceName := "device-1"
944+ wrongDeviceName := "wrong-device"
945+ driverName := "test-driver.example.com"
946+ poolName := "test-pool"
947+ requestName := "gpu"
948+ deviceID := "pci:0000:00:01.0"
949+ legacyKey := "example.com/legacy-vf"
950+ legacyPCI := "0000:8d:00.4"
951+
952+ deviceIDValue := deviceID
953+ resourceSlice := & resourcev1api.ResourceSlice {
954+ ObjectMeta : metav1.ObjectMeta {Name : "test-resource-slice" },
955+ Spec : resourcev1api.ResourceSliceSpec {
956+ Driver : driverName ,
957+ Pool : resourcev1api.ResourcePool {Name : poolName , ResourceSliceCount : 1 },
958+ Devices : []resourcev1api.Device {
959+ {
960+ Name : deviceName ,
961+ Attributes : map [resourcev1api.QualifiedName ]resourcev1api.DeviceAttribute {
962+ multusDeviceIDAttr : {StringValue : & deviceIDValue },
963+ },
964+ },
965+ },
966+ },
967+ }
968+ resourceClaim := & resourcev1api.ResourceClaim {
969+ ObjectMeta : metav1.ObjectMeta {Name : claimName , Namespace : "default" },
970+ Status : resourcev1api.ResourceClaimStatus {
971+ Allocation : & resourcev1api.AllocationResult {
972+ Devices : resourcev1api.DeviceAllocationResult {
973+ Results : []resourcev1api.DeviceRequestAllocationResult {
974+ {Request : requestName , Driver : driverName , Pool : poolName , Device : wrongDeviceName },
975+ },
976+ },
977+ },
978+ },
979+ }
980+ claimNamePtr := claimName
981+ pod := & v1.Pod {
982+ ObjectMeta : metav1.ObjectMeta {Name : "hybrid-pod" , Namespace : "default" , UID : k8sTypes .UID ("uid-hybrid" )},
983+ Status : v1.PodStatus {
984+ ResourceClaimStatuses : []v1.PodResourceClaimStatus {
985+ {Name : claimName , ResourceClaimName : & claimNamePtr },
986+ },
987+ },
988+ }
989+ _ , err := fakeClient .ResourceV1 ().ResourceClaims ("default" ).Create (context .TODO (), resourceClaim , metav1.CreateOptions {})
990+ Expect (err ).NotTo (HaveOccurred ())
991+ _ , err = fakeClient .ResourceV1 ().ResourceSlices ().Create (context .TODO (), resourceSlice , metav1.CreateOptions {})
992+ Expect (err ).NotTo (HaveOccurred ())
993+
994+ resourceMap := map [string ]* types.ResourceInfo {
995+ legacyKey : {DeviceIDs : []string {legacyPCI }},
996+ }
997+ err = draClient .GetPodResourceMap (pod , resourceMap )
998+ Expect (err ).NotTo (HaveOccurred ())
999+ Expect (resourceMap [legacyKey ].DeviceIDs ).To (Equal ([]string {legacyPCI }))
1000+ })
1001+
1002+ It ("should succeed when one allocation result is missing from slices but another resolves" , func () {
1003+ claimName := "multi-claim"
1004+ driverSRIOV := "sriovnetwork.k8snetworkplumbingwg.io"
1005+ driverGPU := "gpu.nvidia.com"
1006+ poolName := "orch-dev-a100-002"
1007+ deviceVF := "0000-8d-00-4"
1008+ deviceGPU := "gpu-4"
1009+ deviceIDVF := "pci:0000:8d:00.4"
1010+ mapKey := "nvidia.com/port2"
1011+ deviceIDVFVal := deviceIDVF
1012+ mapKeyVal := mapKey
1013+
1014+ // SR-IOV slice has the VF; empty GPU slice exists so List() finds gpu.nvidia.com/pool (real clusters
1015+ // always publish a slice per driver/pool). Allocation still references gpu-4, which is not listed here.
1016+ resourceSlice := & resourcev1api.ResourceSlice {
1017+ ObjectMeta : metav1.ObjectMeta {Name : "sriov-slice" },
1018+ Spec : resourcev1api.ResourceSliceSpec {
1019+ Driver : driverSRIOV ,
1020+ Pool : resourcev1api.ResourcePool {Name : poolName , ResourceSliceCount : 1 },
1021+ Devices : []resourcev1api.Device {
1022+ {
1023+ Name : deviceVF ,
1024+ Attributes : map [resourcev1api.QualifiedName ]resourcev1api.DeviceAttribute {
1025+ multusDeviceIDAttr : {StringValue : & deviceIDVFVal },
1026+ multusResourceNameAttr : {StringValue : & mapKeyVal },
1027+ },
1028+ },
1029+ },
1030+ },
1031+ }
1032+ gpuSlice := & resourcev1api.ResourceSlice {
1033+ ObjectMeta : metav1.ObjectMeta {Name : "gpu-slice" },
1034+ Spec : resourcev1api.ResourceSliceSpec {
1035+ Driver : driverGPU ,
1036+ Pool : resourcev1api.ResourcePool {Name : poolName , ResourceSliceCount : 1 },
1037+ Devices : []resourcev1api.Device {},
1038+ },
1039+ }
1040+
1041+ resourceClaim := & resourcev1api.ResourceClaim {
1042+ ObjectMeta : metav1.ObjectMeta {Name : claimName , Namespace : "default" },
1043+ Status : resourcev1api.ResourceClaimStatus {
1044+ Allocation : & resourcev1api.AllocationResult {
1045+ Devices : resourcev1api.DeviceAllocationResult {
1046+ Results : []resourcev1api.DeviceRequestAllocationResult {
1047+ {Request : "vf" , Driver : driverSRIOV , Pool : poolName , Device : deviceVF },
1048+ {Request : "gpu" , Driver : driverGPU , Pool : poolName , Device : deviceGPU },
1049+ },
1050+ },
1051+ },
1052+ },
1053+ }
1054+
1055+ claimNamePtr := claimName
1056+ pod := & v1.Pod {
1057+ ObjectMeta : metav1.ObjectMeta {Name : "mixed-pod" , Namespace : "default" , UID : k8sTypes .UID ("uid-mixed" )},
1058+ Status : v1.PodStatus {
1059+ ResourceClaimStatuses : []v1.PodResourceClaimStatus {
1060+ {Name : claimName , ResourceClaimName : & claimNamePtr },
1061+ },
1062+ },
1063+ }
1064+
1065+ _ , err := fakeClient .ResourceV1 ().ResourceClaims ("default" ).Create (context .TODO (), resourceClaim , metav1.CreateOptions {})
1066+ Expect (err ).NotTo (HaveOccurred ())
1067+ _ , err = fakeClient .ResourceV1 ().ResourceSlices ().Create (context .TODO (), resourceSlice , metav1.CreateOptions {})
1068+ Expect (err ).NotTo (HaveOccurred ())
1069+ _ , err = fakeClient .ResourceV1 ().ResourceSlices ().Create (context .TODO (), gpuSlice , metav1.CreateOptions {})
1070+ Expect (err ).NotTo (HaveOccurred ())
1071+
1072+ resourceMap := make (map [string ]* types.ResourceInfo )
1073+ err = draClient .GetPodResourceMap (pod , resourceMap )
1074+ Expect (err ).NotTo (HaveOccurred ())
1075+ Expect (resourceMap [mapKey ].DeviceIDs ).To (Equal ([]string {deviceIDVF }))
9391076 })
9401077 })
9411078
0 commit comments