Skip to content

Commit 92e0db2

Browse files
authored
Merge pull request kubernetes#125640 from googs1025/resourceclaim_controller_log_fix1
added resourceclaim_controller log info
2 parents e31d2ce + 5f8fb17 commit 92e0db2

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

pkg/controller/resourceclaim/controller.go

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ type Controller struct {
102102
templateLister resourcev1alpha2listers.ResourceClaimTemplateLister
103103
templatesSynced cache.InformerSynced
104104

105-
// podIndexer has the common PodResourceClaim indexer indexer installed To
105+
// podIndexer has the common PodResourceClaim indexer installed To
106106
// limit iteration over pods to those of interest.
107107
podIndexer cache.Indexer
108108

@@ -308,10 +308,11 @@ func (ec *Controller) podNeedsWork(pod *v1.Pod) (bool, string) {
308308
return true, fmt.Sprintf("internal error while checking for claim: %v", err)
309309
}
310310

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+
}
315316
}
316317

317318
// This check skips over the reasons below that only apply
@@ -340,14 +341,14 @@ func (ec *Controller) podNeedsWork(pod *v1.Pod) (bool, string) {
340341
}
341342
if scheduling.Spec.SelectedNode != pod.Spec.NodeName {
342343
// 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))
344345
}
345346
}
346347
if claim.Status.Allocation != nil &&
347348
!resourceclaim.IsReservedForPod(pod, claim) &&
348349
resourceclaim.CanBeReserved(claim) {
349350
// 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))
351352
}
352353
}
353354

@@ -521,10 +522,10 @@ func (ec *Controller) syncPod(ctx context.Context, namespace, name string) error
521522
continue
522523
}
523524
claim, err := ec.claimLister.ResourceClaims(pod.Namespace).Get(*claimName)
524-
if apierrors.IsNotFound(err) {
525-
return nil
526-
}
527525
if err != nil {
526+
if apierrors.IsNotFound(err) {
527+
return nil
528+
}
528529
return fmt.Errorf("retrieve claim: %v", err)
529530
}
530531
if checkOwner {
@@ -550,7 +551,7 @@ func (ec *Controller) syncPod(ctx context.Context, namespace, name string) error
550551
return nil
551552
}
552553

553-
// handleResourceClaim is invoked for each resource claim of a pod.
554+
// handleClaim is invoked for each resource claim of a pod.
554555
func (ec *Controller) handleClaim(ctx context.Context, pod *v1.Pod, podClaim v1.PodResourceClaim, newPodClaims *map[string]string) error {
555556
logger := klog.LoggerWithValues(klog.FromContext(ctx), "podClaim", podClaim.Name)
556557
ctx = klog.NewContext(ctx, logger)
@@ -735,7 +736,7 @@ func (ec *Controller) ensurePodSchedulingContext(ctx context.Context, pod *v1.Po
735736
},
736737
}
737738
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)
739740
}
740741
return nil
741742
}
@@ -744,7 +745,7 @@ func (ec *Controller) ensurePodSchedulingContext(ctx context.Context, pod *v1.Po
744745
scheduling := scheduling.DeepCopy()
745746
scheduling.Spec.SelectedNode = pod.Spec.NodeName
746747
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)
748749
}
749750
}
750751

@@ -760,7 +761,7 @@ func (ec *Controller) reserveForPod(ctx context.Context, pod *v1.Pod, claim *res
760761
UID: pod.UID,
761762
})
762763
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)
764765
}
765766
return nil
766767
}
@@ -930,7 +931,7 @@ func (ec *Controller) syncClaim(ctx context.Context, namespace, name string) err
930931
logger.V(5).Info("deleting unused generated claim", "claim", klog.KObj(claim), "pod", klog.KObj(pod))
931932
err := ec.kubeClient.ResourceV1alpha2().ResourceClaims(claim.Namespace).Delete(ctx, claim.Name, metav1.DeleteOptions{})
932933
if err != nil {
933-
return fmt.Errorf("delete claim: %v", err)
934+
return fmt.Errorf("delete claim %s: %w", klog.KObj(claim), err)
934935
}
935936
} else {
936937
logger.V(6).Info("wrong pod content, not deleting claim", "claim", klog.KObj(claim), "podUID", podUID, "podContent", pod)

pkg/controller/resourceclaim/controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ func TestSyncHandler(t *testing.T) {
541541
}
542542
}
543543

544-
err = ec.syncHandler(context.TODO(), tc.key)
544+
err = ec.syncHandler(ctx, tc.key)
545545
if err != nil && !tc.expectedError {
546546
t.Fatalf("unexpected error while running handler: %v", err)
547547
}

0 commit comments

Comments
 (0)