Skip to content

Commit 5137c59

Browse files
authored
Mis cleanup (#428)
1 parent d2c6e7a commit 5137c59

File tree

5 files changed

+25
-27
lines changed

5 files changed

+25
-27
lines changed

pkg/epp/controller/inferencemodel_reconciler.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ func (c *InferenceModelReconciler) Reconcile(ctx context.Context, req ctrl.Reque
6868
logger = logger.WithValues("poolRef", infModel.Spec.PoolRef).WithValues("modelName", infModel.Spec.ModelName)
6969
if !c.Datastore.ModelSetIfOlder(infModel) {
7070
logger.Info("Skipping InferenceModel, existing instance has older creation timestamp")
71-
71+
} else {
72+
logger.Info("Added/Updated InferenceModel")
7273
}
73-
logger.Info("Added/Updated InferenceModel")
7474

7575
return ctrl.Result{}, nil
7676
}
@@ -82,8 +82,8 @@ func (c *InferenceModelReconciler) handleModelDeleted(ctx context.Context, req t
8282
// other instances referencing the same modelName if exist, and store the oldest in
8383
// its place. This ensures that the InferenceModel with the oldest creation
8484
// timestamp is active.
85-
existing, exists := c.Datastore.ModelDelete(req)
86-
if !exists {
85+
existing := c.Datastore.ModelDelete(req)
86+
if existing == nil {
8787
// No entry exists in the first place, nothing to do.
8888
return nil
8989
}

pkg/epp/datastore/datastore.go

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ type Datastore interface {
5151

5252
// InferenceModel operations
5353
ModelSetIfOlder(infModel *v1alpha2.InferenceModel) bool
54-
ModelGet(modelName string) (*v1alpha2.InferenceModel, bool)
55-
ModelDelete(namespacedName types.NamespacedName) (*v1alpha2.InferenceModel, bool)
54+
ModelGet(modelName string) *v1alpha2.InferenceModel
55+
ModelDelete(namespacedName types.NamespacedName) *v1alpha2.InferenceModel
5656
ModelResync(ctx context.Context, ctrlClient client.Client, modelName string) (bool, error)
5757
ModelGetAll() []*v1alpha2.InferenceModel
5858

5959
// PodMetrics operations
6060
PodUpdateOrAddIfNotExist(pod *corev1.Pod) bool
6161
PodUpdateMetricsIfExist(namespacedName types.NamespacedName, m *Metrics) bool
62-
PodGet(namespacedName types.NamespacedName) (*PodMetrics, bool)
62+
PodGet(namespacedName types.NamespacedName) *PodMetrics
6363
PodDelete(namespacedName types.NamespacedName)
6464
PodResyncAll(ctx context.Context, ctrlClient client.Client)
6565
PodGetAll() []*PodMetrics
@@ -147,7 +147,6 @@ func (ds *datastore) PoolLabelsMatch(podLabels map[string]string) bool {
147147
return poolSelector.Matches(podSet)
148148
}
149149

150-
// /// InferenceModel APIs ///
151150
func (ds *datastore) ModelSetIfOlder(infModel *v1alpha2.InferenceModel) bool {
152151
ds.poolAndModelsMu.Lock()
153152
defer ds.poolAndModelsMu.Unlock()
@@ -199,23 +198,22 @@ func (ds *datastore) ModelResync(ctx context.Context, c client.Client, modelName
199198
return true, nil
200199
}
201200

202-
func (ds *datastore) ModelGet(modelName string) (*v1alpha2.InferenceModel, bool) {
201+
func (ds *datastore) ModelGet(modelName string) *v1alpha2.InferenceModel {
203202
ds.poolAndModelsMu.RLock()
204203
defer ds.poolAndModelsMu.RUnlock()
205-
m, exists := ds.models[modelName]
206-
return m, exists
204+
return ds.models[modelName]
207205
}
208206

209-
func (ds *datastore) ModelDelete(namespacedName types.NamespacedName) (*v1alpha2.InferenceModel, bool) {
207+
func (ds *datastore) ModelDelete(namespacedName types.NamespacedName) *v1alpha2.InferenceModel {
210208
ds.poolAndModelsMu.Lock()
211209
defer ds.poolAndModelsMu.Unlock()
212210
for _, m := range ds.models {
213211
if m.Name == namespacedName.Name && m.Namespace == namespacedName.Namespace {
214212
delete(ds.models, m.Spec.ModelName)
215-
return m, true
213+
return m
216214
}
217215
}
218-
return nil, false
216+
return nil
219217
}
220218

221219
func (ds *datastore) ModelGetAll() []*v1alpha2.InferenceModel {
@@ -238,12 +236,12 @@ func (ds *datastore) PodUpdateMetricsIfExist(namespacedName types.NamespacedName
238236
return false
239237
}
240238

241-
func (ds *datastore) PodGet(namespacedName types.NamespacedName) (*PodMetrics, bool) {
239+
func (ds *datastore) PodGet(namespacedName types.NamespacedName) *PodMetrics {
242240
val, ok := ds.pods.Load(namespacedName)
243241
if ok {
244-
return val.(*PodMetrics), true
242+
return val.(*PodMetrics)
245243
}
246-
return nil, false
244+
return nil
247245
}
248246

249247
func (ds *datastore) PodGetAll() []*PodMetrics {
@@ -311,7 +309,7 @@ func (ds *datastore) PodResyncAll(ctx context.Context, ctrlClient client.Client)
311309
}
312310
}
313311

314-
// Remove pods that don't exist or not ready any more.
312+
// Remove pods that don't belong to the pool or not ready any more.
315313
deleteFn := func(k, v any) bool {
316314
pm := v.(*PodMetrics)
317315
if exist := activePods[pm.NamespacedName.Name]; !exist {

pkg/epp/datastore/datastore_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,8 @@ func TestModel(t *testing.T) {
176176
name: "Getting by model name, chat -> model2",
177177
existingModels: []*v1alpha2.InferenceModel{model2chat, model1ts},
178178
op: func(ds Datastore) bool {
179-
gotChat, exists := ds.ModelGet(chatModel)
180-
return exists && cmp.Diff(model2chat, gotChat) == ""
179+
gotChat := ds.ModelGet(chatModel)
180+
return gotChat != nil && cmp.Diff(model2chat, gotChat) == ""
181181
},
182182
wantOpResult: true,
183183
wantModels: []*v1alpha2.InferenceModel{model2chat, model1ts},
@@ -186,9 +186,9 @@ func TestModel(t *testing.T) {
186186
name: "Delete the model",
187187
existingModels: []*v1alpha2.InferenceModel{model2chat, model1ts},
188188
op: func(ds Datastore) bool {
189-
_, existed := ds.ModelDelete(types.NamespacedName{Name: model1ts.Name, Namespace: model1ts.Namespace})
190-
_, exists := ds.ModelGet(tsModel)
191-
return existed && !exists
189+
existing := ds.ModelDelete(types.NamespacedName{Name: model1ts.Name, Namespace: model1ts.Namespace})
190+
got := ds.ModelGet(tsModel)
191+
return existing != nil && got == nil
192192

193193
},
194194
wantOpResult: true,

pkg/epp/handlers/request.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ func (s *Server) HandleRequestBody(
6464
// NOTE: The nil checking for the modelObject means that we DO allow passthrough currently.
6565
// This might be a security risk in the future where adapters not registered in the InferenceModel
6666
// are able to be requested by using their distinct name.
67-
modelObj, exist := s.datastore.ModelGet(model)
68-
if !exist {
67+
modelObj := s.datastore.ModelGet(model)
68+
if modelObj == nil {
6969
return nil, errutil.Error{Code: errutil.BadConfiguration, Msg: fmt.Sprintf("error finding a model object in InferenceModel for input %v", model)}
7070
}
7171
if len(modelObj.Spec.TargetModels) > 0 {

test/integration/hermetic_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -520,8 +520,8 @@ func BeforeSuit(t *testing.T) func() {
520520
}
521521

522522
assert.EventuallyWithT(t, func(t *assert.CollectT) {
523-
_, modelExist := serverRunner.Datastore.ModelGet("my-model")
524-
synced := serverRunner.Datastore.PoolHasSynced() && modelExist
523+
modelExist := serverRunner.Datastore.ModelGet("my-model")
524+
synced := serverRunner.Datastore.PoolHasSynced() && modelExist != nil
525525
assert.True(t, synced, "Timeout waiting for the pool and models to sync")
526526
}, 10*time.Second, 10*time.Millisecond)
527527

0 commit comments

Comments
 (0)