@@ -71,8 +71,8 @@ const (
71
71
72
72
// Controller creates ResourceClaims for ResourceClaimTemplates in a pod spec.
73
73
type Controller struct {
74
- // adminAccessEnabled matches the DRAAdminAccess feature gate state .
75
- adminAccessEnabled bool
74
+ // features defines the feature gates that are enabled .
75
+ features Features
76
76
77
77
// kubeClient is the kube API client used to communicate with the API
78
78
// server.
@@ -118,25 +118,31 @@ const (
118
118
podKeyPrefix = "pod:"
119
119
)
120
120
121
+ // Features defines which features should be enabled in the controller.
122
+ type Features struct {
123
+ AdminAccess bool
124
+ PrioritizedList bool
125
+ }
126
+
121
127
// NewController creates a ResourceClaim controller.
122
128
func NewController (
123
129
logger klog.Logger ,
124
- adminAccessEnabled bool ,
130
+ features Features ,
125
131
kubeClient clientset.Interface ,
126
132
podInformer v1informers.PodInformer ,
127
133
claimInformer resourceinformers.ResourceClaimInformer ,
128
134
templateInformer resourceinformers.ResourceClaimTemplateInformer ) (* Controller , error ) {
129
135
130
136
ec := & Controller {
131
- adminAccessEnabled : adminAccessEnabled ,
132
- kubeClient : kubeClient ,
133
- podLister : podInformer .Lister (),
134
- podIndexer : podInformer .Informer ().GetIndexer (),
135
- podSynced : podInformer .Informer ().HasSynced ,
136
- claimLister : claimInformer .Lister (),
137
- claimsSynced : claimInformer .Informer ().HasSynced ,
138
- templateLister : templateInformer .Lister (),
139
- templatesSynced : templateInformer .Informer ().HasSynced ,
137
+ features : features ,
138
+ kubeClient : kubeClient ,
139
+ podLister : podInformer .Lister (),
140
+ podIndexer : podInformer .Informer ().GetIndexer (),
141
+ podSynced : podInformer .Informer ().HasSynced ,
142
+ claimLister : claimInformer .Lister (),
143
+ claimsSynced : claimInformer .Informer ().HasSynced ,
144
+ templateLister : templateInformer .Lister (),
145
+ templatesSynced : templateInformer .Informer ().HasSynced ,
140
146
queue : workqueue .NewTypedRateLimitingQueueWithConfig (
141
147
workqueue .DefaultTypedControllerRateLimiter [string ](),
142
148
workqueue.TypedRateLimitingQueueConfig [string ]{Name : "resource_claim" },
@@ -617,10 +623,14 @@ func (ec *Controller) handleClaim(ctx context.Context, pod *v1.Pod, podClaim v1.
617
623
return fmt .Errorf ("resource claim template %q: %v" , * templateName , err )
618
624
}
619
625
620
- if ! ec .adminAccessEnabled && needsAdminAccess (template ) {
626
+ if ! ec .features . AdminAccess && needsAdminAccess (template ) {
621
627
return errors .New ("admin access is requested, but the feature is disabled" )
622
628
}
623
629
630
+ if ! ec .features .PrioritizedList && hasPrioritizedList (template ) {
631
+ return errors .New ("template includes a prioritized list of subrequests, but the feature is disabled" )
632
+ }
633
+
624
634
// Create the ResourceClaim with pod as owner, with a generated name that uses
625
635
// <pod>-<claim name> as base.
626
636
isTrue := true
@@ -688,6 +698,15 @@ func needsAdminAccess(claimTemplate *resourceapi.ResourceClaimTemplate) bool {
688
698
return false
689
699
}
690
700
701
+ func hasPrioritizedList (claimTemplate * resourceapi.ResourceClaimTemplate ) bool {
702
+ for _ , request := range claimTemplate .Spec .Spec .Devices .Requests {
703
+ if len (request .FirstAvailable ) > 0 {
704
+ return true
705
+ }
706
+ }
707
+ return false
708
+ }
709
+
691
710
// findPodResourceClaim looks for an existing ResourceClaim with the right
692
711
// annotation (ties it to the pod claim) and the right ownership (ties it to
693
712
// the pod).
0 commit comments