Skip to content

Commit

Permalink
fix: Add preset nil checks (#347)
Browse files Browse the repository at this point in the history
**Reason for Change**:
Address some missing needed nil checks in workspace controller
  • Loading branch information
ishaansehgal99 authored Apr 10, 2024
1 parent fde6369 commit 64152d4
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions pkg/controllers/workspace_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (c *WorkspaceReconciler) Reconcile(ctx context.Context, req reconcile.Reque
}
}

if workspaceObj.Inference.Preset != nil {
if workspaceObj.Inference != nil && workspaceObj.Inference.Preset != nil {
if !plugin.KaitoModelRegister.Has(string(workspaceObj.Inference.Preset.Name)) {
return reconcile.Result{}, fmt.Errorf("The preset model name %s is not registered for workspace %s/%s", string(workspaceObj.Inference.Preset.Name), workspaceObj.Namespace, workspaceObj.Name)
}
Expand Down Expand Up @@ -316,7 +316,7 @@ func (c *WorkspaceReconciler) validateNodeInstanceType(ctx context.Context, wObj
// createAndValidateNode creates a new machine and validates status.
func (c *WorkspaceReconciler) createAndValidateNode(ctx context.Context, wObj *kaitov1alpha1.Workspace) (*corev1.Node, error) {
var machineOSDiskSize string
if wObj.Inference.Preset != nil && wObj.Inference.Preset.Name != "" {
if wObj.Inference != nil && wObj.Inference.Preset != nil && wObj.Inference.Preset.Name != "" {
presetName := string(wObj.Inference.Preset.Name)
machineOSDiskSize = plugin.KaitoModelRegister.MustGet(presetName).GetInferenceParameters().DiskStorageRequirement
}
Expand Down Expand Up @@ -412,7 +412,7 @@ func (c *WorkspaceReconciler) ensureService(ctx context.Context, wObj *kaitov1al
return nil
}

if wObj.Inference.Preset != nil {
if wObj.Inference != nil && wObj.Inference.Preset != nil {
presetName := string(wObj.Inference.Preset.Name)
model := plugin.KaitoModelRegister.MustGet(presetName)
serviceObj := resources.GenerateServiceManifest(ctx, wObj, serviceType, model.SupportDistributedInference())
Expand Down Expand Up @@ -480,7 +480,7 @@ func (c *WorkspaceReconciler) applyInference(ctx context.Context, wObj *kaitov1a
if err = resources.CheckResourceStatus(workloadObj, c.Client, time.Duration(10)*time.Minute); err != nil {
return
}
} else if wObj.Inference.Preset != nil {
} else if wObj.Inference != nil && wObj.Inference.Preset != nil {
presetName := string(wObj.Inference.Preset.Name)
model := plugin.KaitoModelRegister.MustGet(presetName)

Expand Down Expand Up @@ -575,4 +575,4 @@ func (c *WorkspaceReconciler) watchMachines() handler.EventHandler {
},
}
})
}
}

0 comments on commit 64152d4

Please sign in to comment.