@@ -28,7 +28,7 @@ import (
28
28
"github.com/google/go-cmp/cmp"
29
29
30
30
v1 "k8s.io/api/core/v1"
31
- resourcev1alpha2 "k8s.io/api/resource/v1alpha2 "
31
+ resourceapi "k8s.io/api/resource/v1alpha3 "
32
32
k8serrors "k8s.io/apimachinery/pkg/api/errors"
33
33
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
34
34
"k8s.io/apimachinery/pkg/runtime"
@@ -37,7 +37,7 @@ import (
37
37
"k8s.io/client-go/kubernetes"
38
38
"k8s.io/client-go/kubernetes/scheme"
39
39
corev1types "k8s.io/client-go/kubernetes/typed/core/v1"
40
- resourcev1alpha2listers "k8s.io/client-go/listers/resource/v1alpha2 "
40
+ resourcelisters "k8s.io/client-go/listers/resource/v1alpha3 "
41
41
"k8s.io/client-go/tools/cache"
42
42
"k8s.io/client-go/tools/record"
43
43
"k8s.io/client-go/util/workqueue"
@@ -67,14 +67,14 @@ type Driver interface {
67
67
// possible. class.Parameters may be nil.
68
68
//
69
69
// The caller wraps the error to include the parameter reference.
70
- GetClassParameters (ctx context.Context , class * resourcev1alpha2 .ResourceClass ) (interface {}, error )
70
+ GetClassParameters (ctx context.Context , class * resourceapi .ResourceClass ) (interface {}, error )
71
71
72
72
// GetClaimParameters is called to retrieve the parameter object
73
73
// referenced by a claim. The content should be validated now if
74
74
// possible. claim.Spec.Parameters may be nil.
75
75
//
76
76
// The caller wraps the error to include the parameter reference.
77
- GetClaimParameters (ctx context.Context , claim * resourcev1alpha2 .ResourceClaim , class * resourcev1alpha2 .ResourceClass , classParameters interface {}) (interface {}, error )
77
+ GetClaimParameters (ctx context.Context , claim * resourceapi .ResourceClaim , class * resourceapi .ResourceClass , classParameters interface {}) (interface {}, error )
78
78
79
79
// Allocate is called when all same-driver ResourceClaims for Pod are ready
80
80
// to be allocated. The selectedNode is empty for ResourceClaims with immediate
@@ -111,7 +111,7 @@ type Driver interface {
111
111
// Deallocate may be called when a previous allocation got
112
112
// interrupted. Deallocate must then stop any on-going allocation
113
113
// activity and free resources before returning without an error.
114
- Deallocate (ctx context.Context , claim * resourcev1alpha2 .ResourceClaim ) error
114
+ Deallocate (ctx context.Context , claim * resourceapi .ResourceClaim ) error
115
115
116
116
// UnsuitableNodes checks all pending claims with delayed allocation
117
117
// for a pod. All claims are ready for allocation by the driver
@@ -137,8 +137,8 @@ type Driver interface {
137
137
// pod.Spec.ResourceClaim entry.
138
138
type ClaimAllocation struct {
139
139
PodClaimName string
140
- Claim * resourcev1alpha2 .ResourceClaim
141
- Class * resourcev1alpha2 .ResourceClass
140
+ Claim * resourceapi .ResourceClaim
141
+ Class * resourceapi .ResourceClass
142
142
ClaimParameters interface {}
143
143
ClassParameters interface {}
144
144
@@ -148,7 +148,7 @@ type ClaimAllocation struct {
148
148
149
149
// Driver must populate this field with resources that were
150
150
// allocated for the claim in case of successful allocation.
151
- Allocation * resourcev1alpha2 .AllocationResult
151
+ Allocation * resourceapi .AllocationResult
152
152
// In case of error allocating particular claim, driver must
153
153
// populate this field.
154
154
Error error
@@ -165,10 +165,10 @@ type controller struct {
165
165
claimNameLookup * resourceclaim.Lookup
166
166
queue workqueue.TypedRateLimitingInterface [string ]
167
167
eventRecorder record.EventRecorder
168
- rcLister resourcev1alpha2listers .ResourceClassLister
168
+ rcLister resourcelisters .ResourceClassLister
169
169
rcSynced cache.InformerSynced
170
170
claimCache cache.MutationCache
171
- schedulingCtxLister resourcev1alpha2listers .PodSchedulingContextLister
171
+ schedulingCtxLister resourcelisters .PodSchedulingContextLister
172
172
claimSynced cache.InformerSynced
173
173
schedulingCtxSynced cache.InformerSynced
174
174
}
@@ -184,9 +184,9 @@ func New(
184
184
kubeClient kubernetes.Interface ,
185
185
informerFactory informers.SharedInformerFactory ) Controller {
186
186
logger := klog .LoggerWithName (klog .FromContext (ctx ), "resource controller" )
187
- rcInformer := informerFactory .Resource ().V1alpha2 ().ResourceClasses ()
188
- claimInformer := informerFactory .Resource ().V1alpha2 ().ResourceClaims ()
189
- schedulingCtxInformer := informerFactory .Resource ().V1alpha2 ().PodSchedulingContexts ()
187
+ rcInformer := informerFactory .Resource ().V1alpha3 ().ResourceClasses ()
188
+ claimInformer := informerFactory .Resource ().V1alpha3 ().ResourceClaims ()
189
+ schedulingCtxInformer := informerFactory .Resource ().V1alpha3 ().PodSchedulingContexts ()
190
190
claimNameLookup := resourceclaim .NewNameLookup (kubeClient )
191
191
192
192
eventBroadcaster := record .NewBroadcaster (record .WithContext (ctx ))
@@ -321,9 +321,9 @@ func getKey(obj interface{}) (string, error) {
321
321
}
322
322
prefix := ""
323
323
switch obj .(type ) {
324
- case * resourcev1alpha2 .ResourceClaim :
324
+ case * resourceapi .ResourceClaim :
325
325
prefix = claimKeyPrefix
326
- case * resourcev1alpha2 .PodSchedulingContext :
326
+ case * resourceapi .PodSchedulingContext :
327
327
prefix = schedulingCtxKeyPrefix
328
328
default :
329
329
return "" , fmt .Errorf ("unexpected object: %T" , obj )
@@ -427,7 +427,7 @@ func (ctrl *controller) syncKey(ctx context.Context, key string) (obj runtime.Ob
427
427
return
428
428
}
429
429
430
- func (ctrl * controller ) getCachedClaim (ctx context.Context , key string ) (* resourcev1alpha2 .ResourceClaim , error ) {
430
+ func (ctrl * controller ) getCachedClaim (ctx context.Context , key string ) (* resourceapi .ResourceClaim , error ) {
431
431
claimObj , exists , err := ctrl .claimCache .GetByKey (key )
432
432
if ! exists || k8serrors .IsNotFound (err ) {
433
433
klog .FromContext (ctx ).V (5 ).Info ("ResourceClaim not found, no need to process it" )
@@ -436,16 +436,16 @@ func (ctrl *controller) getCachedClaim(ctx context.Context, key string) (*resour
436
436
if err != nil {
437
437
return nil , err
438
438
}
439
- claim , ok := claimObj .(* resourcev1alpha2 .ResourceClaim )
439
+ claim , ok := claimObj .(* resourceapi .ResourceClaim )
440
440
if ! ok {
441
- return nil , fmt .Errorf ("internal error: got %T instead of *resourcev1alpha2 .ResourceClaim from claim cache" , claimObj )
441
+ return nil , fmt .Errorf ("internal error: got %T instead of *resourceapi .ResourceClaim from claim cache" , claimObj )
442
442
}
443
443
return claim , nil
444
444
}
445
445
446
446
// syncClaim determines which next action may be needed for a ResourceClaim
447
447
// and does it.
448
- func (ctrl * controller ) syncClaim (ctx context.Context , claim * resourcev1alpha2 .ResourceClaim ) error {
448
+ func (ctrl * controller ) syncClaim (ctx context.Context , claim * resourceapi .ResourceClaim ) error {
449
449
var err error
450
450
logger := klog .FromContext (ctx )
451
451
@@ -476,7 +476,7 @@ func (ctrl *controller) syncClaim(ctx context.Context, claim *resourcev1alpha2.R
476
476
claim .Status .Allocation = nil
477
477
claim .Status .DriverName = ""
478
478
claim .Status .DeallocationRequested = false
479
- claim , err = ctrl .kubeClient .ResourceV1alpha2 ().ResourceClaims (claim .Namespace ).UpdateStatus (ctx , claim , metav1.UpdateOptions {})
479
+ claim , err = ctrl .kubeClient .ResourceV1alpha3 ().ResourceClaims (claim .Namespace ).UpdateStatus (ctx , claim , metav1.UpdateOptions {})
480
480
if err != nil {
481
481
return fmt .Errorf ("remove allocation: %v" , err )
482
482
}
@@ -491,15 +491,15 @@ func (ctrl *controller) syncClaim(ctx context.Context, claim *resourcev1alpha2.R
491
491
if claim .Status .DeallocationRequested {
492
492
// Still need to remove it.
493
493
claim .Status .DeallocationRequested = false
494
- claim , err = ctrl .kubeClient .ResourceV1alpha2 ().ResourceClaims (claim .Namespace ).UpdateStatus (ctx , claim , metav1.UpdateOptions {})
494
+ claim , err = ctrl .kubeClient .ResourceV1alpha3 ().ResourceClaims (claim .Namespace ).UpdateStatus (ctx , claim , metav1.UpdateOptions {})
495
495
if err != nil {
496
496
return fmt .Errorf ("remove deallocation: %v" , err )
497
497
}
498
498
ctrl .claimCache .Mutation (claim )
499
499
}
500
500
501
501
claim .Finalizers = ctrl .removeFinalizer (claim .Finalizers )
502
- claim , err = ctrl .kubeClient .ResourceV1alpha2 ().ResourceClaims (claim .Namespace ).Update (ctx , claim , metav1.UpdateOptions {})
502
+ claim , err = ctrl .kubeClient .ResourceV1alpha3 ().ResourceClaims (claim .Namespace ).Update (ctx , claim , metav1.UpdateOptions {})
503
503
if err != nil {
504
504
return fmt .Errorf ("remove finalizer: %v" , err )
505
505
}
@@ -515,7 +515,7 @@ func (ctrl *controller) syncClaim(ctx context.Context, claim *resourcev1alpha2.R
515
515
logger .V (5 ).Info ("ResourceClaim is allocated" )
516
516
return nil
517
517
}
518
- if claim .Spec .AllocationMode != resourcev1alpha2 .AllocationModeImmediate {
518
+ if claim .Spec .AllocationMode != resourceapi .AllocationModeImmediate {
519
519
logger .V (5 ).Info ("ResourceClaim waiting for first consumer" )
520
520
return nil
521
521
}
@@ -560,7 +560,7 @@ func (ctrl *controller) syncClaim(ctx context.Context, claim *resourcev1alpha2.R
560
560
return nil
561
561
}
562
562
563
- func (ctrl * controller ) getParameters (ctx context.Context , claim * resourcev1alpha2 .ResourceClaim , class * resourcev1alpha2 .ResourceClass , notifyClaim bool ) (claimParameters , classParameters interface {}, err error ) {
563
+ func (ctrl * controller ) getParameters (ctx context.Context , claim * resourceapi .ResourceClaim , class * resourceapi .ResourceClass , notifyClaim bool ) (claimParameters , classParameters interface {}, err error ) {
564
564
classParameters , err = ctrl .driver .GetClassParameters (ctx , class )
565
565
if err != nil {
566
566
ctrl .eventRecorder .Event (class , v1 .EventTypeWarning , "Failed" , err .Error ())
@@ -580,7 +580,7 @@ func (ctrl *controller) getParameters(ctx context.Context, claim *resourcev1alph
580
580
581
581
// allocateClaims filters list of claims, keeps those needing allocation and asks driver to do the allocations.
582
582
// Driver is supposed to write the AllocationResult and Error field into argument claims slice.
583
- func (ctrl * controller ) allocateClaims (ctx context.Context , claims []* ClaimAllocation , selectedNode string , selectedUser * resourcev1alpha2 .ResourceClaimConsumerReference ) {
583
+ func (ctrl * controller ) allocateClaims (ctx context.Context , claims []* ClaimAllocation , selectedNode string , selectedUser * resourceapi .ResourceClaimConsumerReference ) {
584
584
logger := klog .FromContext (ctx )
585
585
586
586
needAllocation := make ([]* ClaimAllocation , 0 , len (claims ))
@@ -610,7 +610,7 @@ func (ctrl *controller) allocateClaims(ctx context.Context, claims []*ClaimAlloc
610
610
logger .V (5 ).Info ("Adding finalizer" , "claim" , claim .Name )
611
611
claim .Finalizers = append (claim .Finalizers , ctrl .finalizer )
612
612
var err error
613
- claim , err = ctrl .kubeClient .ResourceV1alpha2 ().ResourceClaims (claim .Namespace ).Update (ctx , claim , metav1.UpdateOptions {})
613
+ claim , err = ctrl .kubeClient .ResourceV1alpha3 ().ResourceClaims (claim .Namespace ).Update (ctx , claim , metav1.UpdateOptions {})
614
614
if err != nil {
615
615
logger .Error (err , "add finalizer" , "claim" , claim .Name )
616
616
claimAllocation .Error = fmt .Errorf ("add finalizer: %v" , err )
@@ -648,7 +648,7 @@ func (ctrl *controller) allocateClaims(ctx context.Context, claims []*ClaimAlloc
648
648
claim .Status .ReservedFor = append (claim .Status .ReservedFor , * selectedUser )
649
649
}
650
650
logger .V (6 ).Info ("Updating claim after allocation" , "claim" , claim )
651
- claim , err := ctrl .kubeClient .ResourceV1alpha2 ().ResourceClaims (claim .Namespace ).UpdateStatus (ctx , claim , metav1.UpdateOptions {})
651
+ claim , err := ctrl .kubeClient .ResourceV1alpha3 ().ResourceClaims (claim .Namespace ).UpdateStatus (ctx , claim , metav1.UpdateOptions {})
652
652
if err != nil {
653
653
claimAllocation .Error = fmt .Errorf ("add allocation: %v" , err )
654
654
continue
@@ -678,7 +678,7 @@ func (ctrl *controller) checkPodClaim(ctx context.Context, pod *v1.Pod, podClaim
678
678
return nil , err
679
679
}
680
680
}
681
- if claim .Spec .AllocationMode != resourcev1alpha2 .AllocationModeWaitForFirstConsumer {
681
+ if claim .Spec .AllocationMode != resourceapi .AllocationModeWaitForFirstConsumer {
682
682
// Nothing to do for it as part of pod scheduling.
683
683
return nil , nil
684
684
}
@@ -711,7 +711,7 @@ func (ctrl *controller) checkPodClaim(ctx context.Context, pod *v1.Pod, podClaim
711
711
712
712
// syncPodSchedulingContext determines which next action may be needed for a PodSchedulingContext object
713
713
// and does it.
714
- func (ctrl * controller ) syncPodSchedulingContexts (ctx context.Context , schedulingCtx * resourcev1alpha2 .PodSchedulingContext ) error {
714
+ func (ctrl * controller ) syncPodSchedulingContexts (ctx context.Context , schedulingCtx * resourceapi .PodSchedulingContext ) error {
715
715
logger := klog .FromContext (ctx )
716
716
717
717
// Ignore deleted objects.
@@ -801,7 +801,7 @@ func (ctrl *controller) syncPodSchedulingContexts(ctx context.Context, schedulin
801
801
logger .V (2 ).Info ("skipping allocation for unsuitable selected node" , "node" , selectedNode )
802
802
} else {
803
803
logger .V (2 ).Info ("allocation for selected node" , "node" , selectedNode )
804
- selectedUser := & resourcev1alpha2 .ResourceClaimConsumerReference {
804
+ selectedUser := & resourceapi .ResourceClaimConsumerReference {
805
805
Resource : "pods" ,
806
806
Name : pod .Name ,
807
807
UID : pod .UID ,
@@ -838,7 +838,7 @@ func (ctrl *controller) syncPodSchedulingContexts(ctx context.Context, schedulin
838
838
if i < 0 {
839
839
// Add new entry.
840
840
schedulingCtx .Status .ResourceClaims = append (schedulingCtx .Status .ResourceClaims ,
841
- resourcev1alpha2 .ResourceClaimSchedulingStatus {
841
+ resourceapi .ResourceClaimSchedulingStatus {
842
842
Name : delayed .PodClaimName ,
843
843
UnsuitableNodes : truncateNodes (delayed .UnsuitableNodes , selectedNode ),
844
844
})
@@ -851,7 +851,7 @@ func (ctrl *controller) syncPodSchedulingContexts(ctx context.Context, schedulin
851
851
}
852
852
if modified {
853
853
logger .V (6 ).Info ("Updating pod scheduling with modified unsuitable nodes" , "podSchedulingCtx" , schedulingCtx )
854
- if _ , err := ctrl .kubeClient .ResourceV1alpha2 ().PodSchedulingContexts (schedulingCtx .Namespace ).UpdateStatus (ctx , schedulingCtx , metav1.UpdateOptions {}); err != nil {
854
+ if _ , err := ctrl .kubeClient .ResourceV1alpha3 ().PodSchedulingContexts (schedulingCtx .Namespace ).UpdateStatus (ctx , schedulingCtx , metav1.UpdateOptions {}); err != nil {
855
855
return fmt .Errorf ("update unsuitable node status: %v" , err )
856
856
}
857
857
}
@@ -866,7 +866,7 @@ func truncateNodes(nodes []string, selectedNode string) []string {
866
866
// this list might be too long by one element. When truncating it, make
867
867
// sure that the selected node is listed.
868
868
lenUnsuitable := len (nodes )
869
- if lenUnsuitable > resourcev1alpha2 .PodSchedulingNodeListMaxSize {
869
+ if lenUnsuitable > resourceapi .PodSchedulingNodeListMaxSize {
870
870
if nodes [0 ] == selectedNode {
871
871
// Truncate at the end and keep selected node in the first element.
872
872
nodes = nodes [0 : lenUnsuitable - 1 ]
@@ -893,7 +893,7 @@ func (claims claimAllocations) MarshalLog() interface{} {
893
893
var _ logr.Marshaler = claimAllocations {}
894
894
895
895
// findClaim returns the index of the specified pod claim, -1 if not found.
896
- func findClaim (claims []resourcev1alpha2 .ResourceClaimSchedulingStatus , podClaimName string ) int {
896
+ func findClaim (claims []resourceapi .ResourceClaimSchedulingStatus , podClaimName string ) int {
897
897
for i := range claims {
898
898
if claims [i ].Name == podClaimName {
899
899
return i
@@ -926,7 +926,7 @@ func stringsDiffer(a, b []string) bool {
926
926
}
927
927
928
928
// hasFinalizer checks if the claim has the finalizer of the driver.
929
- func (ctrl * controller ) hasFinalizer (claim * resourcev1alpha2 .ResourceClaim ) bool {
929
+ func (ctrl * controller ) hasFinalizer (claim * resourceapi .ResourceClaim ) bool {
930
930
for _ , finalizer := range claim .Finalizers {
931
931
if finalizer == ctrl .finalizer {
932
932
return true
0 commit comments