|
1 | 1 | package backend
|
2 | 2 |
|
3 | 3 | 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" |
4 | 11 | "k8s.io/client-go/kubernetes"
|
5 | 12 | )
|
6 | 13 |
|
7 | 14 | 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. |
11 | 21 | }
|
12 | 22 |
|
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 | +} |
14 | 31 |
|
| 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 |
15 | 40 | }
|
16 | 41 |
|
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}) |
19 | 44 | if err != nil {
|
20 |
| - //Cry about it. |
| 45 | + // Handle err |
21 | 46 | }
|
22 | 47 |
|
23 |
| - for p in podList.Items { |
| 48 | + for _, p := range podList.Items { |
| 49 | + fmt.Print(p.Name) |
24 | 50 | // get IP and name
|
25 | 51 | }
|
26 | 52 | }
|
27 |
| - |
28 |
| -func (k *K8sClient) GetLLMServices() { |
29 |
| - |
30 |
| -} |
|
0 commit comments