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 e4433bd

Browse files
committedNov 20, 2024·
llmservice reconciler implementation
1 parent a55f870 commit e4433bd

File tree

7 files changed

+339
-72
lines changed

7 files changed

+339
-72
lines changed
 

Diff for: ‎examples/poc/README.md

-71
This file was deleted.

Diff for: ‎examples/poc/envoy-gateway-bootstrap.png

-911 KB
Binary file not shown.

Diff for: ‎examples/poc/manifests/llmservice.yaml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
apiVersion: inference.networking.x-k8s.io/v1alpha1
2+
kind: LLMService
3+
metadata:
4+
labels:
5+
app.kubernetes.io/name: api
6+
app.kubernetes.io/managed-by: kustomize
7+
name: llmservice-sample
8+
spec:
9+
models:
10+
- name: sql-code-assist
11+
- name: npc-bot
12+
objective:
13+
desiredAveragePerOutputTokenLatencyAtP95OverMultipleRequests: 50
14+
targetModels:
15+
- name: npc-bot-v1
16+
weight: 50
17+
- name: npc-bot-v2
18+
weight: 50
19+
poolRef:
20+
- kind: LLMServerPool
21+
name: test-pool
22+
- name: gemini-pool
23+
kind: LLMServerPool

Diff for: ‎pkg/ext-proc/backend/datastore.go

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
// The datastore is a local cache of relevant data for the given LLMServerPool (currently all pulled from k8s-api)
1111
type K8sDatastore struct {
1212
LLMServerPool *v1alpha1.LLMServerPool
13+
LLMServices *sync.Map
1314
Pods *sync.Map
1415
}
1516

Diff for: ‎pkg/ext-proc/backend/llmservice_reconciler.go

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

0 commit comments

Comments
 (0)
Please sign in to comment.