forked from kubernetes-sigs/gateway-api-inference-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathllmservice_reconciler.go
57 lines (49 loc) · 1.64 KB
/
llmservice_reconciler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package backend
import (
"context"
"strings"
"inference.networking.x-k8s.io/llm-instance-gateway/api/v1alpha1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/tools/record"
"k8s.io/klog/v2"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
)
type LLMServiceReconciler struct {
client.Client
Scheme *runtime.Scheme
Record record.EventRecorder
Datastore *K8sDatastore
ServerPoolName string
Namespace string
}
func (c *LLMServiceReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
if req.Namespace != c.Namespace {
return ctrl.Result{}, nil
}
klog.V(1).Info("reconciling LLMService", req.NamespacedName)
service := &v1alpha1.LLMService{}
if err := c.Get(ctx, req.NamespacedName, service); err != nil {
klog.Error(err, "unable to get LLMServerPool")
return ctrl.Result{}, err
}
c.updateDatastore(service)
return ctrl.Result{}, nil
}
func (c *LLMServiceReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
For(&v1alpha1.LLMService{}).
Complete(c)
}
func (c *LLMServiceReconciler) updateDatastore(service *v1alpha1.LLMService) {
for _, ref := range service.Spec.PoolRef {
if strings.Contains(strings.ToLower(ref.Kind), strings.ToLower("LLMServerPool")) && ref.Name == c.ServerPoolName {
klog.V(2).Infof("Adding/Updating service: %v", service.Name)
c.Datastore.LLMServices.Store(service.Name, service)
return
}
}
klog.V(2).Infof("Removing/Not adding service: %v", service.Name)
// If we get here. The service is not relevant to this pool, remove.
c.Datastore.LLMServices.Delete(service.Name)
}