Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9a7ac49

Browse files
committedOct 28, 2024
WIP
1 parent 5f4d2fa commit 9a7ac49

File tree

2 files changed

+80
-12
lines changed

2 files changed

+80
-12
lines changed
 

‎pkg/ext-proc/backend/k8s_client.go

+34-12
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,52 @@
11
package backend
22

33
import (
4+
"context"
5+
"fmt"
6+
7+
v1alpha1 "inference.networking.x-k8s.io/llm-instance-gateway/api/v1alpha1"
8+
clientset "inference.networking.x-k8s.io/llm-instance-gateway/client-go/clientset/versioned"
9+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
10+
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
411
"k8s.io/client-go/kubernetes"
512
)
613

714
type K8sClient struct {
8-
serverPoolName string
9-
clientSet *kubernetes.Clientset
10-
labelSelector string // Remove this when LLMServerPool is wired up.
15+
serverPoolName string
16+
namespace string
17+
kubeClientSet *kubernetes.Clientset
18+
instanceGWClientSet clientset.Interface
19+
20+
labelSelector string // Remove this when LLMServerPool is wired up.
1121
}
1222

13-
func (k *K8sClient) GetLLMServerPool() {
23+
func NewK8sClient(name, namespace string, k8sClient *kubernetes.Clientset, iGWClient clientset.Interface) K8sClient {
24+
return K8sClient{
25+
serverPoolName: name,
26+
namespace: namespace,
27+
kubeClientSet: k8sClient,
28+
instanceGWClientSet: iGWClient,
29+
}
30+
}
1431

32+
func (k *K8sClient) GetLLMServerPool() (*v1alpha1.LLMServerPool, error) {
33+
llmServerPool, err := k.instanceGWClientSet.ApiV1alpha1().LLMServerPools(k.namespace).Get(context.TODO(), k.serverPoolName, v1.GetOptions{})
34+
fmt.Print(llmServerPool.Name)
35+
if err != nil {
36+
fmt.Print("oh no.")
37+
return nil, err
38+
}
39+
return llmServerPool, nil
1540
}
1641

17-
func (k *K8sClient) GetPods(namespace string) {
18-
podList, err := k.clentSet.CoreV1().Pods(namespace).List(context.TODO(), metav1.ListOptions{LabelSelector: k.labelSelector})
42+
func (k *K8sClient) GetPods() {
43+
podList, err := k.kubeClientSet.CoreV1().Pods(k.namespace).List(context.TODO(), metav1.ListOptions{LabelSelector: k.labelSelector})
1944
if err != nil {
20-
//Cry about it.
45+
// Handle err
2146
}
2247

23-
for p in podList.Items {
48+
for _, p := range podList.Items {
49+
fmt.Print(p.Name)
2450
// get IP and name
2551
}
2652
}
27-
28-
func (k *K8sClient) GetLLMServices() {
29-
30-
}

‎pkg/ext-proc/main.go

+46
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,52 @@ func main() {
115115
}
116116
}()
117117

118+
kubeInformerFactory := kubeinformers.NewSharedInformerFactory(kubeClientset, time.Second*30)
119+
llmServerPoolInformerFactory := informers.NewSharedInformerFactory(iGWClientSet, time.Second*30)
120+
121+
llmServerPoolController := backend.NewLLMServerPoolController(
122+
ctx,
123+
*serverPoolName,
124+
datastore,
125+
kubeClientset,
126+
llmServerPoolInformerFactory.Api().V1alpha1().LLMServerPools(),
127+
)
128+
129+
podController := backend.NewPodController(
130+
ctx,
131+
*serverPoolName,
132+
datastore,
133+
kubeClientset,
134+
kubeInformerFactory.Core().V1().Pods(),
135+
)
136+
137+
kubeInformerFactory.Start(ctx.Done())
138+
llmServerPoolInformerFactory.Start(ctx.Done())
139+
140+
errChan := make(chan error)
141+
go func() {
142+
if err = llmServerPoolController.Run(ctx, 1); err != nil {
143+
klog.Error(err, "Error running LLMServerPoolController")
144+
errChan <- err
145+
}
146+
}()
147+
148+
go func() {
149+
if err = podController.Run(ctx, 2); err != nil {
150+
klog.Error(err, "Error running PodController")
151+
errChan <- err
152+
}
153+
}()
154+
155+
k8sClient := backend.NewK8sClient("test-pool", "default", kubeClientset, iGWClientSet)
156+
serverPool, err := k8sClient.GetLLMServerPool()
157+
if err != nil {
158+
klog.Error(err.Error())
159+
} else if serverPool != nil {
160+
klog.Info(fmt.Printf("KELLEN TEST: %v", serverPool.Spec.ModelServerSelector.MatchLabels))
161+
} else {
162+
klog.Info("No err but serverPool is nil")
163+
}
118164
s := grpc.NewServer()
119165

120166
pp := backend.NewProvider(&backend.PodMetricsClientImpl{}, datastore)

0 commit comments

Comments
 (0)
Please sign in to comment.