@@ -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 )
@@ -734,7 +735,7 @@ func (ec *Controller) ensurePodSchedulingContext(ctx context.Context, pod *v1.Po
734
735
},
735
736
}
736
737
if _ , err := ec .kubeClient .ResourceV1alpha2 ().PodSchedulingContexts (pod .Namespace ).Create (ctx , scheduling , metav1.CreateOptions {}); err != nil {
737
- return fmt .Errorf ("create PodSchedulingContext: %v" , err )
738
+ return fmt .Errorf ("create PodSchedulingContext %s : %w" , klog . KObj ( scheduling ) , err )
738
739
}
739
740
return nil
740
741
}
@@ -743,7 +744,7 @@ func (ec *Controller) ensurePodSchedulingContext(ctx context.Context, pod *v1.Po
743
744
scheduling := scheduling .DeepCopy ()
744
745
scheduling .Spec .SelectedNode = pod .Spec .NodeName
745
746
if _ , err := ec .kubeClient .ResourceV1alpha2 ().PodSchedulingContexts (pod .Namespace ).Update (ctx , scheduling , metav1.UpdateOptions {}); err != nil {
746
- return fmt .Errorf ("update spec.selectedNode in PodSchedulingContext: %v" , err )
747
+ return fmt .Errorf ("update spec.selectedNode in PodSchedulingContext %s : %w" , klog . KObj ( scheduling ) , err )
747
748
}
748
749
}
749
750
@@ -759,7 +760,7 @@ func (ec *Controller) reserveForPod(ctx context.Context, pod *v1.Pod, claim *res
759
760
UID : pod .UID ,
760
761
})
761
762
if _ , err := ec .kubeClient .ResourceV1alpha2 ().ResourceClaims (claim .Namespace ).UpdateStatus (ctx , claim , metav1.UpdateOptions {}); err != nil {
762
- return fmt .Errorf ("reserve claim for pod: %v" , err )
763
+ return fmt .Errorf ("reserve claim %s for pod: %w" , klog . KObj ( claim ) , err )
763
764
}
764
765
return nil
765
766
}
@@ -929,7 +930,7 @@ func (ec *Controller) syncClaim(ctx context.Context, namespace, name string) err
929
930
logger .V (5 ).Info ("deleting unused generated claim" , "claim" , klog .KObj (claim ), "pod" , klog .KObj (pod ))
930
931
err := ec .kubeClient .ResourceV1alpha2 ().ResourceClaims (claim .Namespace ).Delete (ctx , claim .Name , metav1.DeleteOptions {})
931
932
if err != nil {
932
- return fmt .Errorf ("delete claim: %v" , err )
933
+ return fmt .Errorf ("delete claim %s : %w" , klog . KObj ( claim ) , err )
933
934
}
934
935
} else {
935
936
logger .V (6 ).Info ("wrong pod content, not deleting claim" , "claim" , klog .KObj (claim ), "podUID" , podUID , "podContent" , pod )
0 commit comments