@@ -17,26 +17,22 @@ limitations under the License.
17
17
package dra
18
18
19
19
import (
20
+ "errors"
20
21
"fmt"
21
22
"sync"
22
23
23
24
resourceapi "k8s.io/api/resource/v1alpha3"
24
25
"k8s.io/apimachinery/pkg/types"
25
26
"k8s.io/apimachinery/pkg/util/sets"
26
27
"k8s.io/kubernetes/pkg/kubelet/cm/dra/state"
27
- "k8s.io/kubernetes/pkg/kubelet/cm/util/cdi"
28
- kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
29
28
)
30
29
31
30
// ClaimInfo holds information required
32
31
// to prepare and unprepare a resource claim.
33
32
// +k8s:deepcopy-gen=true
34
33
type ClaimInfo struct {
35
34
state.ClaimInfoState
36
- // annotations is a mapping of container annotations per DRA plugin associated with
37
- // a prepared resource
38
- annotations map [string ][]kubecontainer.Annotation
39
- prepared bool
35
+ prepared bool
40
36
}
41
37
42
38
// claimInfoCache is a cache of processed resource claims keyed by namespace/claimname.
@@ -47,89 +43,50 @@ type claimInfoCache struct {
47
43
}
48
44
49
45
// newClaimInfoFromClaim creates a new claim info from a resource claim.
50
- func newClaimInfoFromClaim (claim * resourceapi.ResourceClaim ) * ClaimInfo {
51
- // Grab the allocation.resourceHandles. If there are no
52
- // allocation.resourceHandles, create a single resourceHandle with no
53
- // content. This will trigger processing of this claim by a single
54
- // kubelet plugin whose name matches resourceClaim.Status.DriverName.
55
- resourceHandles := claim .Status .Allocation .ResourceHandles
56
- if len (resourceHandles ) == 0 {
57
- resourceHandles = make ([]resourceapi.ResourceHandle , 1 )
58
- }
46
+ // It verifies that the kubelet can handle the claim.
47
+ func newClaimInfoFromClaim (claim * resourceapi.ResourceClaim ) (* ClaimInfo , error ) {
59
48
claimInfoState := state.ClaimInfoState {
60
- DriverName : claim .Status .DriverName ,
61
- ClassName : claim .Spec .ResourceClassName ,
62
- ClaimUID : claim .UID ,
63
- ClaimName : claim .Name ,
64
- Namespace : claim .Namespace ,
65
- PodUIDs : sets .New [string ](),
66
- ResourceHandles : resourceHandles ,
67
- CDIDevices : make (map [string ][]string ),
49
+ ClaimUID : claim .UID ,
50
+ ClaimName : claim .Name ,
51
+ Namespace : claim .Namespace ,
52
+ PodUIDs : sets .New [string ](),
53
+ Drivers : make (map [string ]state.DriverState ),
54
+ }
55
+ if claim .Status .Allocation == nil {
56
+ return nil , errors .New ("not allocated" )
57
+ }
58
+ for _ , result := range claim .Status .Allocation .Devices .Results {
59
+ claimInfoState .Drivers [result .Driver ] = state.DriverState {
60
+ CDIDevices : make (map [string ][]string ),
61
+ }
68
62
}
69
63
info := & ClaimInfo {
70
64
ClaimInfoState : claimInfoState ,
71
- annotations : make (map [string ][]kubecontainer.Annotation ),
72
65
prepared : false ,
73
66
}
74
- return info
67
+ return info , nil
75
68
}
76
69
77
70
// newClaimInfoFromClaim creates a new claim info from a checkpointed claim info state object.
78
71
func newClaimInfoFromState (state * state.ClaimInfoState ) * ClaimInfo {
79
72
info := & ClaimInfo {
80
73
ClaimInfoState : * state .DeepCopy (),
81
- annotations : make (map [string ][]kubecontainer.Annotation ),
82
74
prepared : false ,
83
75
}
84
- for pluginName , devices := range info .CDIDevices {
85
- annotations , _ := cdi .GenerateAnnotations (info .ClaimUID , info .DriverName , devices )
86
- info .annotations [pluginName ] = append (info .annotations [pluginName ], annotations ... )
87
- }
88
76
return info
89
77
}
90
78
91
79
// setCDIDevices adds a set of CDI devices to the claim info.
92
- func (info * ClaimInfo ) setCDIDevices (pluginName string , cdiDevices []string ) error {
93
- // NOTE: Passing CDI device names as annotations is a temporary solution
94
- // It will be removed after all runtimes are updated
95
- // to get CDI device names from the ContainerConfig.CDIDevices field
96
- annotations , err := cdi .GenerateAnnotations (info .ClaimUID , info .DriverName , cdiDevices )
97
- if err != nil {
98
- return fmt .Errorf ("failed to generate container annotations, err: %+v" , err )
99
- }
100
-
101
- if info .CDIDevices == nil {
102
- info .CDIDevices = make (map [string ][]string )
103
- }
104
-
105
- if info .annotations == nil {
106
- info .annotations = make (map [string ][]kubecontainer.Annotation )
80
+ func (info * ClaimInfo ) setCDIDevices (driverName string , requestName string , cdiDevices []string ) {
81
+ if info .Drivers == nil {
82
+ info .Drivers = make (map [string ]state.DriverState )
107
83
}
108
-
109
- info .CDIDevices [pluginName ] = cdiDevices
110
- info .annotations [pluginName ] = annotations
111
-
112
- return nil
113
- }
114
-
115
- // annotationsAsList returns container annotations as a single list.
116
- func (info * ClaimInfo ) annotationsAsList () []kubecontainer.Annotation {
117
- var lst []kubecontainer.Annotation
118
- for _ , v := range info .annotations {
119
- lst = append (lst , v ... )
120
- }
121
- return lst
122
- }
123
-
124
- // cdiDevicesAsList returns a list of CDIDevices from the provided claim info.
125
- func (info * ClaimInfo ) cdiDevicesAsList () []kubecontainer.CDIDevice {
126
- var cdiDevices []kubecontainer.CDIDevice
127
- for _ , devices := range info .CDIDevices {
128
- for _ , device := range devices {
129
- cdiDevices = append (cdiDevices , kubecontainer.CDIDevice {Name : device })
130
- }
84
+ driverState := info .Drivers [driverName ]
85
+ if driverState .CDIDevices == nil {
86
+ driverState .CDIDevices = make (map [string ][]string )
131
87
}
132
- return cdiDevices
88
+ driverState .CDIDevices [requestName ] = cdiDevices
89
+ info .Drivers [driverName ] = driverState
133
90
}
134
91
135
92
// addPodReference adds a pod reference to the claim info.
0 commit comments