Skip to content

Commit 40bb0d0

Browse files
committed
refine
1 parent 182d6da commit 40bb0d0

2 files changed

Lines changed: 73 additions & 50 deletions

File tree

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
Copyright 2025 The llm-d Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package launcherpopulator
18+
19+
import (
20+
"context"
21+
"fmt"
22+
23+
corev1 "k8s.io/api/core/v1"
24+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
25+
"k8s.io/utils/ptr"
26+
27+
fmav1alpha1 "github.com/llm-d-incubation/llm-d-fast-model-actuation/api/fma/v1alpha1"
28+
)
29+
30+
// makeLCOwnerRef builds a non-controlling OwnerReference for a LauncherConfig.
31+
func makeLCOwnerRef(lc *fmav1alpha1.LauncherConfig) metav1.OwnerReference {
32+
return metav1.OwnerReference{
33+
APIVersion: fmav1alpha1.SchemeGroupVersion.String(),
34+
Kind: "LauncherConfig",
35+
Name: lc.Name,
36+
UID: lc.UID,
37+
Controller: ptr.To(false),
38+
BlockOwnerDeletion: ptr.To(false),
39+
}
40+
}
41+
42+
// nonNilSlice returns a single-element slice if s is non-empty, or nil otherwise.
43+
func nonNilSlice(s string) []string {
44+
if s == "" {
45+
return nil
46+
}
47+
return []string{s}
48+
}
49+
50+
// getMatchingNodes returns nodes that match the EnhancedNodeSelector.
51+
// It returns three values: the matched nodes, user-facing selector errors (non-nil when the
52+
// LabelSelector itself is malformed — this is a user configuration error), and an internal
53+
// error (non-nil for unexpected infrastructure failures such as lister errors).
54+
// Callers should handle selectorErrs and err independently.
55+
func (ctl *controller) getMatchingNodes(ctx context.Context, selector fmav1alpha1.EnhancedNodeSelector) ([]corev1.Node, []string, error) {
56+
// Convert the label selector. A failure here is a user error (malformed LabelSelector).
57+
labelSelector, selectorErr := metav1.LabelSelectorAsSelector(&selector.LabelSelector)
58+
if selectorErr != nil {
59+
return nil, []string{fmt.Sprintf("invalid label selector: %v", selectorErr)}, nil
60+
}
61+
nodes, err := ctl.nodeLister.List(labelSelector)
62+
if err != nil {
63+
return nil, nil, fmt.Errorf("failed to list nodes using nodeLister: %w", err)
64+
}
65+
66+
var matchedNodes []corev1.Node
67+
for _, node := range nodes {
68+
if matchesResourceConditions(node.Status.Allocatable, selector.AllocatableResources) {
69+
matchedNodes = append(matchedNodes, *node)
70+
}
71+
}
72+
return matchedNodes, nil, nil
73+
}

pkg/controller/launcher-populator/populator.go

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929
"k8s.io/apimachinery/pkg/labels"
3030
"k8s.io/apimachinery/pkg/types"
3131
"k8s.io/apimachinery/pkg/util/sets"
32-
"k8s.io/utils/ptr"
3332

3433
corev1preinformers "k8s.io/client-go/informers/core/v1"
3534
coreclient "k8s.io/client-go/kubernetes/typed/core/v1"
@@ -487,55 +486,6 @@ func (ctl *controller) reconcileKey(ctx context.Context, key NodeLauncherKey, de
487486
return nil, false
488487
}
489488

490-
// ---------------------------------------------------------------------------
491-
// Helper functions
492-
// ---------------------------------------------------------------------------
493-
494-
// makeLCOwnerRef builds a non-controlling OwnerReference for a LauncherConfig.
495-
func makeLCOwnerRef(lc *fmav1alpha1.LauncherConfig) metav1.OwnerReference {
496-
return metav1.OwnerReference{
497-
APIVersion: fmav1alpha1.SchemeGroupVersion.String(),
498-
Kind: "LauncherConfig",
499-
Name: lc.Name,
500-
UID: lc.UID,
501-
Controller: ptr.To(false),
502-
BlockOwnerDeletion: ptr.To(false),
503-
}
504-
}
505-
506-
// nonNilSlice returns a single-element slice if s is non-empty, or nil otherwise.
507-
func nonNilSlice(s string) []string {
508-
if s == "" {
509-
return nil
510-
}
511-
return []string{s}
512-
}
513-
514-
// getMatchingNodes returns nodes that match the EnhancedNodeSelector.
515-
// It returns three values: the matched nodes, user-facing selector errors (non-nil when the
516-
// LabelSelector itself is malformed — this is a user configuration error), and an internal
517-
// error (non-nil for unexpected infrastructure failures such as lister errors).
518-
// Callers should handle selectorErrs and err independently.
519-
func (ctl *controller) getMatchingNodes(ctx context.Context, selector fmav1alpha1.EnhancedNodeSelector) ([]corev1.Node, []string, error) {
520-
// Convert the label selector. A failure here is a user error (malformed LabelSelector).
521-
labelSelector, selectorErr := metav1.LabelSelectorAsSelector(&selector.LabelSelector)
522-
if selectorErr != nil {
523-
return nil, []string{fmt.Sprintf("invalid label selector: %v", selectorErr)}, nil
524-
}
525-
nodes, err := ctl.nodeLister.List(labelSelector)
526-
if err != nil {
527-
return nil, nil, fmt.Errorf("failed to list nodes using nodeLister: %w", err)
528-
}
529-
530-
var matchedNodes []corev1.Node
531-
for _, node := range nodes {
532-
if matchesResourceConditions(node.Status.Allocatable, selector.AllocatableResources) {
533-
matchedNodes = append(matchedNodes, *node)
534-
}
535-
}
536-
return matchedNodes, nil, nil
537-
}
538-
539489
// getCurrentLaunchersOnNode returns launcher pods for a specific config on a specific node.
540490
// It reads the informer cache and uses the resulting UID set to reconcile any
541491
// pending expectations, then returns one of:

0 commit comments

Comments
 (0)