@@ -282,8 +282,10 @@ func (r *WorkloadReconciler) cleanupSlices(ctx context.Context, wl *kueue.Worklo
282282func (r * WorkloadReconciler ) findWorkloadSlices (ctx context.Context , wl * kueue.Workload ) ([]v1alpha1.Slice , error ) {
283283 slices := & v1alpha1.SliceList {}
284284 opts := []client.ListOption {
285- client .InNamespace (wl .Namespace ),
286- client.MatchingFields {OwnerReferenceUID : string (wl .UID )},
285+ client.MatchingFields {
286+ WorkloadNamespaceIndex : wl .Namespace ,
287+ WorkloadNameIndex : wl .Name ,
288+ },
287289 }
288290 if err := r .client .List (ctx , slices , opts ... ); err != nil {
289291 return nil , err
@@ -463,7 +465,7 @@ func (r *WorkloadReconciler) syncSlices(
463465 continue
464466 }
465467
466- sliceName := core .SliceName (wl .Name , psa .Name )
468+ sliceName := core .SliceName (wl .Namespace , wl . Name , psa .Name )
467469
468470 if _ , exist := slicesByName [sliceName ]; exist {
469471 // Slice already exists, nothing to do.
@@ -511,18 +513,17 @@ func (r *WorkloadReconciler) createSlice(ctx context.Context, wl *kueue.Workload
511513 slice := core .SliceWithMetadata (wl , psa .Name )
512514 log := ctrl .LoggerFrom (ctx ).WithValues ("slice" , klog .KObj (slice ))
513515 log .V (3 ).Info ("Creating Slice" )
514-
515- if err := controllerutil .SetControllerReference (wl , slice , r .client .Scheme ()); err != nil {
516- return nil , err
517- }
516+ // Since Slice is a cluster-scoped object and Workload is namespaced,
517+ // we cannot set a controller owner reference. The Workload's namespace and name
518+ // are stored as annotations on the Slice for lookup.
518519 parseTopologyAssignmentIntoPartitionIds (slice , psa .TopologyAssignment , nodes )
519520
520521 ps := podset .FindPodSetByName (wl .Spec .PodSets , psa .Name )
521522 slice .Spec .Type = v1alpha1 .Type (core .GetTPUAccelerator (ps .Template ))
522523 slice .Spec .Topology = core .GetTPUTopology (ps .Template )
523524
524525 if err := r .client .Create (ctx , slice ); err != nil {
525- msg := fmt .Sprintf ("Error creating Slice %q: %v" , client . ObjectKeyFromObject ( slice ) , err )
526+ msg := fmt .Sprintf ("Error creating Slice %q: %v" , slice . Name , err )
526527 log .Error (err , msg )
527528 r .record .Event (wl , corev1 .EventTypeWarning , FailedCreateSliceEventType , api .TruncateEventMessage (msg ))
528529 ac .State = kueue .CheckStatePending
@@ -547,7 +548,7 @@ func (r *WorkloadReconciler) updateWorkloadAdmissionCheckStatus(ctx context.Cont
547548func buildCreationEventMessage (slices []v1alpha1.Slice ) string {
548549 sliceNames := make ([]string , len (slices ))
549550 for index , slice := range slices {
550- sliceNames [index ] = fmt .Sprintf ("%q" , client . ObjectKeyFromObject ( & slice ) )
551+ sliceNames [index ] = fmt .Sprintf ("%q" , slice . Name )
551552 }
552553 sort .Strings (sliceNames )
553554 return fmt .Sprintf ("The Slices %s have been created" , strings .Join (sliceNames , ", " ))
@@ -672,18 +673,20 @@ func (h *sliceHandler) handleEvent(ctx context.Context, obj client.Object, q wor
672673
673674 log := ctrl .LoggerFrom (ctx )
674675
675- owner := metav1 .GetControllerOf (slice )
676- if owner == nil {
677- log .V (3 ).Info ("Owner not found" )
676+ workloadNamespace , nsFound := slice .Annotations [core .OwnerWorkloadNamespaceAnnotation ]
677+ workloadName , nameFound := slice .Annotations [core .OwnerWorkloadNameAnnotation ]
678+
679+ if ! nsFound || ! nameFound {
680+ log .V (3 ).Info ("Slice is missing workload owner annotations, skipping event handling" , "slice" , klog .KObj (slice ))
678681 return
679682 }
680683
681- log .V (3 ).Info ("Handle Slice event" , "workload" , klog .KRef (slice . Namespace , slice . Name ))
684+ log .V (3 ).Info ("Handle Slice event" , "workload" , klog .KRef (workloadNamespace , workloadName ))
682685
683686 req := reconcile.Request {
684687 NamespacedName : types.NamespacedName {
685- Name : owner . Name ,
686- Namespace : slice . Namespace ,
688+ Name : workloadName ,
689+ Namespace : workloadNamespace ,
687690 },
688691 }
689692
0 commit comments