Skip to content

Commit

Permalink
Add check to verify presence of an isvc before creating it
Browse files Browse the repository at this point in the history
  • Loading branch information
deadlycoconuts committed Jan 15, 2024
1 parent 367a4ec commit 649eebb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
12 changes: 9 additions & 3 deletions api/cluster/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,16 @@ func (c *controller) Deploy(ctx context.Context, modelService *models.Service) (
return nil, errors.Wrapf(err, fmt.Sprintf("%v (%s)", ErrUnableToCreateInferenceService, isvcName))
}

s, err := c.kserveClient.InferenceServices(modelService.Namespace).Create(spec)
s, err := c.kserveClient.InferenceServices(modelService.Namespace).Get(modelService.Name, metav1.GetOptions{})
if err != nil {
log.Errorf("unable to create inference service %s: %v", isvcName, err)
return nil, errors.Wrapf(err, fmt.Sprintf("%v (%s)", ErrUnableToCreateInferenceService, isvcName))
if !kerrors.IsNotFound(err) {
return nil, errors.Wrapf(err, "unable to check status of inference service: %s", s.Name)
}
s, err = c.kserveClient.InferenceServices(modelService.Namespace).Create(spec)
if err != nil {
log.Errorf("unable to create inference service %s: %v", isvcName, err)
return nil, errors.Wrapf(err, fmt.Sprintf("%v (%s)", ErrUnableToCreateInferenceService, isvcName))
}
}

if c.deploymentConfig.PodDisruptionBudget.Enabled {
Expand Down
8 changes: 5 additions & 3 deletions api/cluster/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,10 @@ func TestController_DeployInferenceService(t *testing.T) {
nil,
errors.New("error creating inference service"),
},
checkResult: nil,
checkResult: &inferenceServiceReactor{
nil,
kerrors.NewNotFound(schema.GroupResource{}, ""),
},
deployTimeout: deployTimeout,
createPdbResult: &pdbReactor{pdb, nil},
createVsResult: &vsReactor{vs, nil},
Expand All @@ -468,7 +471,7 @@ func TestController_DeployInferenceService(t *testing.T) {
},
checkResult: &inferenceServiceReactor{
nil,
errors.New("error check"),
kerrors.NewNotFound(schema.GroupResource{}, ""),
},
deployTimeout: deployTimeout,
createPdbResult: &pdbReactor{pdb, nil},
Expand Down Expand Up @@ -639,7 +642,6 @@ func TestController_DeployInferenceService(t *testing.T) {
kfClient.PrependReactor(createMethod, inferenceServiceResource, func(action ktesting.Action) (handled bool, ret runtime.Object, err error) {
return true, tt.createResult.isvc, tt.createResult.err
})

kfClient.PrependReactor(deleteMethod, inferenceServiceResource, func(action ktesting.Action) (handled bool, ret runtime.Object, err error) {
return true, nil, nil
})
Expand Down

0 comments on commit 649eebb

Please sign in to comment.