Skip to content

Commit 30a058a

Browse files
committed
register controller.
1 parent c3c32f6 commit 30a058a

File tree

7 files changed

+51
-14
lines changed

7 files changed

+51
-14
lines changed

config/charts/inferencepool/templates/rbac.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ metadata:
4646
{{- include "gateway-api-inference-extension.labels" . | nindent 4 }}
4747
rules:
4848
- apiGroups: ["inference.networking.x-k8s.io"]
49-
resources: ["inferenceobjectives"]
49+
resources: ["inferenceobjectives", "inferencemodelrewrites"]
5050
verbs: ["get", "watch", "list"]
5151
- apiGroups: ["{{ (split "/" .Values.inferencePool.apiVersion)._0 }}"]
5252
resources: ["inferencepools"]

pkg/epp/controller/inferencemodelrewrite_reconciler.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ func (c *InferenceModelRewriteReconciler) Reconcile(ctx context.Context, req ctr
5454
notFound = true
5555
}
5656

57-
if notFound || !infModelRewrite.DeletionTimestamp.IsZero() || infModelRewrite.Spec.PoolRef.Name != v1alpha2.ObjectName(c.PoolGKNN.Name) {
57+
if notFound || !infModelRewrite.DeletionTimestamp.IsZero() || infModelRewrite.Spec.PoolRef == nil ||
58+
infModelRewrite.Spec.PoolRef.Name != v1alpha2.ObjectName(c.PoolGKNN.Name) ||
59+
(infModelRewrite.Spec.PoolRef.Group != v1alpha2.Group(c.PoolGKNN.Group) && infModelRewrite.Spec.PoolRef.Group != "inference.networking.x-k8s.io") {
5860
// InferenceModelRewrite object got deleted or changed the referenced pool.
5961
c.Datastore.RewriteDelete(req.NamespacedName)
6062
return ctrl.Result{}, nil

pkg/epp/controller/inferencemodelrewrite_reconciler_test.go

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import (
3636
"sigs.k8s.io/gateway-api-inference-extension/pkg/common"
3737
backendmetrics "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/backend/metrics"
3838
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/datastore"
39+
poolutil "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/util/pool"
3940
utiltest "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/util/testing"
4041
)
4142

@@ -48,7 +49,10 @@ var (
4849
CreationTimestamp: metav1.Unix(1000, 0),
4950
},
5051
Spec: v1alpha2.InferenceModelRewriteSpec{
51-
PoolRef: &v1alpha2.PoolObjectReference{Name: v1alpha2.ObjectName(poolForRewrite.Name)},
52+
PoolRef: &v1alpha2.PoolObjectReference{
53+
Name: v1alpha2.ObjectName(poolForRewrite.Name),
54+
Group: v1alpha2.Group(poolForRewrite.GroupVersionKind().Group),
55+
},
5256
},
5357
}
5458
rewrite1Pool2 = &v1alpha2.InferenceModelRewrite{
@@ -58,7 +62,10 @@ var (
5862
CreationTimestamp: metav1.Unix(1001, 0),
5963
},
6064
Spec: v1alpha2.InferenceModelRewriteSpec{
61-
PoolRef: &v1alpha2.PoolObjectReference{Name: "test-pool2"},
65+
PoolRef: &v1alpha2.PoolObjectReference{
66+
Name: "test-pool2",
67+
Group: v1alpha2.Group(poolForRewrite.GroupVersionKind().Group),
68+
},
6269
},
6370
}
6471
rewrite1Updated = &v1alpha2.InferenceModelRewrite{
@@ -68,8 +75,11 @@ var (
6875
CreationTimestamp: metav1.Unix(1003, 0),
6976
},
7077
Spec: v1alpha2.InferenceModelRewriteSpec{
71-
PoolRef: &v1alpha2.PoolObjectReference{Name: v1alpha2.ObjectName(poolForRewrite.Name)},
72-
Rules: []v1alpha2.InferenceModelRewriteRule{{}},
78+
PoolRef: &v1alpha2.PoolObjectReference{
79+
Name: v1alpha2.ObjectName(poolForRewrite.Name),
80+
Group: v1alpha2.Group(poolForRewrite.GroupVersionKind().Group),
81+
},
82+
Rules: []v1alpha2.InferenceModelRewriteRule{{}},
7383
},
7484
}
7585
rewrite1Deleted = &v1alpha2.InferenceModelRewrite{
@@ -78,9 +88,13 @@ var (
7888
Namespace: rewrite1.Namespace,
7989
CreationTimestamp: metav1.Unix(1004, 0),
8090
DeletionTimestamp: &metav1.Time{Time: time.Now()},
91+
Finalizers: []string{"deleted"},
8192
},
8293
Spec: v1alpha2.InferenceModelRewriteSpec{
83-
PoolRef: &v1alpha2.PoolObjectReference{Name: v1alpha2.ObjectName(poolForRewrite.Name)},
94+
PoolRef: &v1alpha2.PoolObjectReference{
95+
Name: v1alpha2.ObjectName(poolForRewrite.Name),
96+
Group: v1alpha2.Group(poolForRewrite.GroupVersionKind().Group),
97+
},
8498
},
8599
}
86100
rewrite2 = &v1alpha2.InferenceModelRewrite{
@@ -90,7 +104,10 @@ var (
90104
CreationTimestamp: metav1.Unix(1001, 0),
91105
},
92106
Spec: v1alpha2.InferenceModelRewriteSpec{
93-
PoolRef: &v1alpha2.PoolObjectReference{Name: v1alpha2.ObjectName(poolForRewrite.Name)},
107+
PoolRef: &v1alpha2.PoolObjectReference{
108+
Name: v1alpha2.ObjectName(poolForRewrite.Name),
109+
Group: v1alpha2.Group(poolForRewrite.GroupVersionKind().Group),
110+
},
94111
},
95112
}
96113
)
@@ -155,7 +172,7 @@ func TestInferenceModelRewriteReconciler(t *testing.T) {
155172
_ = v1alpha2.Install(scheme)
156173
_ = v1.Install(scheme)
157174
initObjs := []client.Object{}
158-
if test.rewrite != nil && test.rewrite.DeletionTimestamp.IsZero() {
175+
if test.rewrite != nil {
159176
initObjs = append(initObjs, test.rewrite)
160177
}
161178
for _, r := range test.rewritesInAPIServer {
@@ -170,7 +187,8 @@ func TestInferenceModelRewriteReconciler(t *testing.T) {
170187
for _, r := range test.rewritesInStore {
171188
ds.RewriteSet(r)
172189
}
173-
_ = ds.PoolSet(context.Background(), fakeClient, poolForRewrite)
190+
endpointPool := poolutil.InferencePoolToEndpointPool(poolForRewrite)
191+
_ = ds.PoolSet(context.Background(), fakeClient, endpointPool)
174192
reconciler := &InferenceModelRewriteReconciler{
175193
Reader: fakeClient,
176194
Datastore: ds,

pkg/epp/datastore/datastore.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import (
3131

3232
"sigs.k8s.io/controller-runtime/pkg/client"
3333
"sigs.k8s.io/controller-runtime/pkg/log"
34-
v1 "sigs.k8s.io/gateway-api-inference-extension/api/v1"
3534
"sigs.k8s.io/gateway-api-inference-extension/apix/v1alpha2"
3635
backendmetrics "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/backend/metrics"
3736
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/datalayer"
@@ -101,7 +100,7 @@ type datastore struct {
101100
parentCtx context.Context
102101
// mu is used to synchronize access to pool, objectives, and rewrites.
103102
mu sync.RWMutex
104-
pool *v1.InferencePool
103+
pool *datalayer.EndpointPool
105104
// key: InferenceObjective name, value: *InferenceObjective
106105
objectives map[string]*v1alpha2.InferenceObjective
107106
// rewrites store for InferenceModelRewrite objects.
@@ -156,7 +155,7 @@ func (ds *datastore) PoolSet(ctx context.Context, reader client.Reader, endpoint
156155
return nil
157156
}
158157

159-
func (ds *datastore) PoolGet() (*v1.InferencePool, error) {
158+
func (ds *datastore) PoolGet() (*datalayer.EndpointPool, error) {
160159
ds.mu.RLock()
161160
defer ds.mu.RUnlock()
162161
if !ds.PoolHasSynced() {

pkg/epp/server/controller_manager.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ func defaultManagerOptions(disableK8sCrdReconcile bool, gknn common.GKNN, metric
5555
gknn.Namespace: {},
5656
},
5757
},
58+
&v1alpha2.InferenceObjective{}: {
59+
Namespaces: map[string]cache.Config{
60+
gknn.Namespace: {},
61+
},
62+
},
63+
&v1alpha2.InferenceModelRewrite{}: {
64+
Namespaces: map[string]cache.Config{
65+
gknn.Namespace: {},
66+
},
67+
},
5868
},
5969
},
6070
Metrics: metricsServerOptions,

pkg/epp/server/runserver.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,14 @@ func (r *ExtProcServerRunner) SetupWithManager(ctx context.Context, mgr ctrl.Man
131131
}
132132
}
133133

134+
if err := (&controller.InferenceModelRewriteReconciler{
135+
Datastore: r.Datastore,
136+
Reader: mgr.GetClient(),
137+
PoolGKNN: r.GKNN,
138+
}).SetupWithManager(ctx, mgr); err != nil {
139+
return fmt.Errorf("failed setting up InferenceModelRewriteReconciler: %w", err)
140+
}
141+
134142
if err := (&controller.PodReconciler{
135143
Datastore: r.Datastore,
136144
Reader: mgr.GetClient(),

test/testdata/inferencepool-e2e.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ metadata:
4444
namespace: $E2E_NS
4545
rules:
4646
- apiGroups: [ "inference.networking.x-k8s.io" ]
47-
resources: [ "inferenceobjectives", "inferencepools" ]
47+
resources: [ "inferenceobjectives", "inferencepools", "inferencemodelrewrites" ]
4848
verbs: [ "get", "watch", "list" ]
4949
- apiGroups: [ "inference.networking.k8s.io" ]
5050
resources: [ "inferencepools" ]

0 commit comments

Comments
 (0)