@@ -102,7 +102,7 @@ type Controller struct {
102
102
templateLister resourcev1alpha2listers.ResourceClaimTemplateLister
103
103
templatesSynced cache.InformerSynced
104
104
105
- // podIndexer has the common PodResourceClaim indexer indexer installed To
105
+ // podIndexer has the common PodResourceClaim indexer installed To
106
106
// limit iteration over pods to those of interest.
107
107
podIndexer cache.Indexer
108
108
@@ -308,10 +308,11 @@ func (ec *Controller) podNeedsWork(pod *v1.Pod) (bool, string) {
308
308
return true , fmt .Sprintf ("internal error while checking for claim: %v" , err )
309
309
}
310
310
311
- if checkOwner &&
312
- resourceclaim .IsForPod (pod , claim ) != nil {
313
- // Cannot proceed with the pod unless that other claim gets deleted.
314
- return false , "conflicting claim needs to be removed by user"
311
+ if checkOwner {
312
+ if err := resourceclaim .IsForPod (pod , claim ); err != nil {
313
+ // Cannot proceed with the pod unless that other claim gets deleted.
314
+ return false , err .Error ()
315
+ }
315
316
}
316
317
317
318
// This check skips over the reasons below that only apply
@@ -340,14 +341,14 @@ func (ec *Controller) podNeedsWork(pod *v1.Pod) (bool, string) {
340
341
}
341
342
if scheduling .Spec .SelectedNode != pod .Spec .NodeName {
342
343
// Need to update PodSchedulingContext.
343
- return true , "need to updated PodSchedulingContext for scheduled pod"
344
+ return true , fmt . Sprintf ( "need to update PodSchedulingContext %s for scheduled pod" , klog . KObj ( scheduling ))
344
345
}
345
346
}
346
347
if claim .Status .Allocation != nil &&
347
348
! resourceclaim .IsReservedForPod (pod , claim ) &&
348
349
resourceclaim .CanBeReserved (claim ) {
349
350
// Need to reserve it.
350
- return true , "need to reserve claim for pod"
351
+ return true , fmt . Sprintf ( "need to reserve claim %s for pod" , klog . KObj ( claim ))
351
352
}
352
353
}
353
354
@@ -521,10 +522,10 @@ func (ec *Controller) syncPod(ctx context.Context, namespace, name string) error
521
522
continue
522
523
}
523
524
claim , err := ec .claimLister .ResourceClaims (pod .Namespace ).Get (* claimName )
524
- if apierrors .IsNotFound (err ) {
525
- return nil
526
- }
527
525
if err != nil {
526
+ if apierrors .IsNotFound (err ) {
527
+ return nil
528
+ }
528
529
return fmt .Errorf ("retrieve claim: %v" , err )
529
530
}
530
531
if checkOwner {
@@ -550,7 +551,7 @@ func (ec *Controller) syncPod(ctx context.Context, namespace, name string) error
550
551
return nil
551
552
}
552
553
553
- // handleResourceClaim is invoked for each resource claim of a pod.
554
+ // handleClaim is invoked for each resource claim of a pod.
554
555
func (ec * Controller ) handleClaim (ctx context.Context , pod * v1.Pod , podClaim v1.PodResourceClaim , newPodClaims * map [string ]string ) error {
555
556
logger := klog .LoggerWithValues (klog .FromContext (ctx ), "podClaim" , podClaim .Name )
556
557
ctx = klog .NewContext (ctx , logger )
@@ -735,7 +736,7 @@ func (ec *Controller) ensurePodSchedulingContext(ctx context.Context, pod *v1.Po
735
736
},
736
737
}
737
738
if _ , err := ec .kubeClient .ResourceV1alpha2 ().PodSchedulingContexts (pod .Namespace ).Create (ctx , scheduling , metav1.CreateOptions {}); err != nil {
738
- return fmt .Errorf ("create PodSchedulingContext: %v" , err )
739
+ return fmt .Errorf ("create PodSchedulingContext %s : %w" , klog . KObj ( scheduling ) , err )
739
740
}
740
741
return nil
741
742
}
@@ -744,7 +745,7 @@ func (ec *Controller) ensurePodSchedulingContext(ctx context.Context, pod *v1.Po
744
745
scheduling := scheduling .DeepCopy ()
745
746
scheduling .Spec .SelectedNode = pod .Spec .NodeName
746
747
if _ , err := ec .kubeClient .ResourceV1alpha2 ().PodSchedulingContexts (pod .Namespace ).Update (ctx , scheduling , metav1.UpdateOptions {}); err != nil {
747
- return fmt .Errorf ("update spec.selectedNode in PodSchedulingContext: %v" , err )
748
+ return fmt .Errorf ("update spec.selectedNode in PodSchedulingContext %s : %w" , klog . KObj ( scheduling ) , err )
748
749
}
749
750
}
750
751
@@ -760,7 +761,7 @@ func (ec *Controller) reserveForPod(ctx context.Context, pod *v1.Pod, claim *res
760
761
UID : pod .UID ,
761
762
})
762
763
if _ , err := ec .kubeClient .ResourceV1alpha2 ().ResourceClaims (claim .Namespace ).UpdateStatus (ctx , claim , metav1.UpdateOptions {}); err != nil {
763
- return fmt .Errorf ("reserve claim for pod: %v" , err )
764
+ return fmt .Errorf ("reserve claim %s for pod: %w" , klog . KObj ( claim ) , err )
764
765
}
765
766
return nil
766
767
}
@@ -930,7 +931,7 @@ func (ec *Controller) syncClaim(ctx context.Context, namespace, name string) err
930
931
logger .V (5 ).Info ("deleting unused generated claim" , "claim" , klog .KObj (claim ), "pod" , klog .KObj (pod ))
931
932
err := ec .kubeClient .ResourceV1alpha2 ().ResourceClaims (claim .Namespace ).Delete (ctx , claim .Name , metav1.DeleteOptions {})
932
933
if err != nil {
933
- return fmt .Errorf ("delete claim: %v" , err )
934
+ return fmt .Errorf ("delete claim %s : %w" , klog . KObj ( claim ) , err )
934
935
}
935
936
} else {
936
937
logger .V (6 ).Info ("wrong pod content, not deleting claim" , "claim" , klog .KObj (claim ), "podUID" , podUID , "podContent" , pod )
0 commit comments