Skip to content

Commit 759129f

Browse files
committed
Refine based on comments
1 parent 276a8da commit 759129f

2 files changed

Lines changed: 34 additions & 23 deletions

File tree

pkg/controller/launcher-populator/node-launcher-key.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,16 @@ func (k NodeLauncherKey) String() string {
3737
// DesiredStateEntry holds the desired count and the LauncherConfig spec
3838
// for a (Node, LauncherConfig) pair.
3939
type DesiredStateEntry struct {
40-
Count int32
41-
LauncherConfigSpec fmav1alpha1.LauncherConfigSpec
40+
Count int32
41+
LauncherConfigSpec *fmav1alpha1.LauncherConfigSpec
4242
LauncherConfigOwnerRef metav1.OwnerReference
4343
}
4444

4545
func (e DesiredStateEntry) String() string {
46-
return fmt.Sprintf("count=%d,config=%s", e.Count, e.LauncherConfigOwnerRef.Name)
46+
if e.LauncherConfigSpec == nil {
47+
return fmt.Sprintf("count=%d,config=%s,spec=<nil>", e.Count, e.LauncherConfigOwnerRef.Name)
48+
}
49+
return fmt.Sprintf("count=%d,config=%s,spec=%+v", e.Count, e.LauncherConfigOwnerRef.Name, *e.LauncherConfigSpec)
4750
}
4851

4952
// MapToLoggable converts a map of NodeLauncherKey to Val values into a string representation.

pkg/controller/launcher-populator/populator.go

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func (ctl *controller) OnUpdate(prev, obj any) {
152152
item := lcItem{cache.MetaObjectToName(typed)}
153153
ctl.Queue.Add(item)
154154
default:
155-
ctl.enqueueLogger.V(5).Info("Notified of update of type of ignored object", "type", fmt.Sprintf("%T", obj))
155+
ctl.enqueueLogger.V(5).Info("Notified of update of object of ignored type", "type", fmt.Sprintf("%T", obj))
156156
return
157157
}
158158
}
@@ -167,7 +167,7 @@ func (ctl *controller) OnDelete(obj any) {
167167
item := lppItem{cache.MetaObjectToName(typed)}
168168
ctl.Queue.Add(item)
169169
default:
170-
ctl.enqueueLogger.V(5).Info("Notified of delete of type of ignored object", "type", fmt.Sprintf("%T", obj))
170+
ctl.enqueueLogger.V(5).Info("Notified of delete of object of ignored type", "type", fmt.Sprintf("%T", obj))
171171
return
172172
}
173173
}
@@ -261,12 +261,18 @@ func (ctl *controller) buildDesiredStateFromPolicies(ctx context.Context) (map[N
261261
NodeName: node.Name,
262262
LauncherConfigName: countRule.LauncherConfigName,
263263
}
264-
ownerRef := *metav1.NewControllerRef(lc, fmav1alpha1.SchemeGroupVersion.WithKind("LauncherConfig"))
265-
ownerRef.BlockOwnerDeletion = ptr.To(false)
264+
ownerRef := metav1.OwnerReference{
265+
APIVersion: fmav1alpha1.SchemeGroupVersion.String(),
266+
Kind: "LauncherConfig",
267+
Name: lc.Name,
268+
UID: lc.UID,
269+
Controller: ptr.To(false),
270+
BlockOwnerDeletion: ptr.To(false),
271+
}
266272
if entry, exists := desired[key]; !exists || countRule.LauncherCount > entry.Count {
267273
desired[key] = DesiredStateEntry{
268274
Count: countRule.LauncherCount,
269-
LauncherConfigSpec: lc.Spec,
275+
LauncherConfigSpec: &lc.Spec,
270276
LauncherConfigOwnerRef: ownerRef,
271277
}
272278
}
@@ -347,10 +353,10 @@ func (ctl *controller) reconcileLaunchersOnSingleNode(ctx context.Context, nodeN
347353
deletionInProgress := false // tracks pods already being deleted (DeletionTimestamp set)
348354

349355
type creationInfo struct {
350-
key NodeLauncherKey
351-
count int
352-
spec fmav1alpha1.LauncherConfigSpec
353-
owner metav1.OwnerReference
356+
key NodeLauncherKey
357+
count int
358+
spec *fmav1alpha1.LauncherConfigSpec
359+
owner metav1.OwnerReference
354360
}
355361
var creations []creationInfo
356362

@@ -371,15 +377,17 @@ func (ctl *controller) reconcileLaunchersOnSingleNode(ctx context.Context, nodeN
371377
// BuildLauncherPodFromTemplate computes a hash of the fully built pod spec
372378
// and stores it as the LauncherConfigHashAnnotationKey annotation.
373379
nominalHash := ""
374-
nominalPod, err := utils.BuildLauncherPodFromTemplate(
375-
entry.LauncherConfigSpec.PodTemplate, ctl.namespace, key.NodeName, key.LauncherConfigName)
376-
if err != nil {
377-
// The only error possible here is that the PodTemplate lacks an inference server container.
378-
// In that case we proceed without a nominal hash, so no stale-pod detection occurs for this config.
379-
logger.Error(err, "Failed to build nominal pod for hash comparison",
380-
"node", nodeName, "config", key.LauncherConfigName)
381-
} else if nominalPod.Annotations != nil {
382-
nominalHash = nominalPod.Annotations[string(common.LauncherConfigHashAnnotationKey)]
380+
if entry.LauncherConfigSpec != nil {
381+
nominalPod, err := utils.BuildLauncherPodFromTemplate(
382+
entry.LauncherConfigSpec.PodTemplate, ctl.namespace, key.NodeName, key.LauncherConfigName)
383+
if err != nil {
384+
// The only error possible here is that the PodTemplate lacks an inference server container.
385+
// In that case we proceed without a nominal hash, so no stale-pod detection occurs for this config.
386+
logger.Error(err, "Failed to build nominal pod for hash comparison",
387+
"node", nodeName, "config", key.LauncherConfigName)
388+
} else {
389+
nominalHash = nominalPod.Annotations[string(common.LauncherConfigHashAnnotationKey)]
390+
}
383391
}
384392

385393
// Categorize current pods: separate live unbound current-spec pods from stale/unbound ones
@@ -432,7 +440,7 @@ func (ctl *controller) reconcileLaunchersOnSingleNode(ctx context.Context, nodeN
432440
effectiveRemaining := liveBoundCount + len(liveUnboundCurrentPods)
433441
diff := entry.Count - int32(effectiveRemaining)
434442

435-
logger.Info("Analyzing config on node",
443+
logger.Info("Analyzed config on node",
436444
"node", nodeName,
437445
"config", key.LauncherConfigName,
438446
"current", effectiveRemaining,
@@ -525,7 +533,7 @@ func (ctl *controller) getCurrentLaunchersOnNode(ctx context.Context, key NodeLa
525533

526534
// createLaunchers creates the specified number of launcher pods on a node
527535
// using the given LauncherConfig spec and owner reference directly (no additional lookup needed).
528-
func (ctl *controller) createLaunchers(ctx context.Context, node corev1.Node, key NodeLauncherKey, count int, lcSpec fmav1alpha1.LauncherConfigSpec, lcOwnerRef metav1.OwnerReference) error {
536+
func (ctl *controller) createLaunchers(ctx context.Context, node corev1.Node, key NodeLauncherKey, count int, lcSpec *fmav1alpha1.LauncherConfigSpec, lcOwnerRef metav1.OwnerReference) error {
529537
logger := klog.FromContext(ctx)
530538

531539
// Create the specified number of launcher pods

0 commit comments

Comments
 (0)