Skip to content

Commit

Permalink
fix: rename create to useHeadlessService
Browse files Browse the repository at this point in the history
  • Loading branch information
ishaansehgal99 committed Nov 2, 2023
1 parent ac0e880 commit fd3f9db
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
14 changes: 7 additions & 7 deletions pkg/controllers/workspace_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ func (c *WorkspaceReconciler) addOrUpdateWorkspace(ctx context.Context, wObj *ka
return reconcile.Result{}, err
}

createHeadlessService := *(wObj.Resource.Count) > 1 && strings.Contains(string(wObj.Inference.Preset.Name), "llama")
if err := c.ensureService(ctx, wObj, createHeadlessService); err != nil {
useHeadlessService := *(wObj.Resource.Count) > 1 && strings.Contains(string(wObj.Inference.Preset.Name), "llama")
if err := c.ensureService(ctx, wObj, useHeadlessService); err != nil {
if updateErr := c.updateStatusConditionIfNotMatch(ctx, wObj, kaitov1alpha1.WorkspaceConditionTypeReady, metav1.ConditionFalse,
"workspaceFailed", err.Error()); updateErr != nil {
klog.ErrorS(updateErr, "failed to update workspace status", "workspace", klog.KObj(wObj))
Expand All @@ -103,7 +103,7 @@ func (c *WorkspaceReconciler) addOrUpdateWorkspace(ctx context.Context, wObj *ka
return reconcile.Result{}, err
}

if err = c.applyInference(ctx, wObj, createHeadlessService); err != nil {
if err = c.applyInference(ctx, wObj, useHeadlessService); err != nil {
if updateErr := c.updateStatusConditionIfNotMatch(ctx, wObj, kaitov1alpha1.WorkspaceConditionTypeReady, metav1.ConditionFalse,
"workspaceFailed", err.Error()); updateErr != nil {
klog.ErrorS(updateErr, "failed to update workspace status", "workspace", klog.KObj(wObj))
Expand Down Expand Up @@ -379,7 +379,7 @@ func (c *WorkspaceReconciler) ensureNodePlugins(ctx context.Context, wObj *kaito
}
}

func (c *WorkspaceReconciler) ensureService(ctx context.Context, wObj *kaitov1alpha1.Workspace, createHeadlessService bool) error {
func (c *WorkspaceReconciler) ensureService(ctx context.Context, wObj *kaitov1alpha1.Workspace, useHeadlessService bool) error {
serviceType := corev1.ServiceTypeClusterIP
wAnnotation := wObj.GetAnnotations()

Expand Down Expand Up @@ -408,7 +408,7 @@ func (c *WorkspaceReconciler) ensureService(ctx context.Context, wObj *kaitov1al
if err != nil {
return err
}
if createHeadlessService {
if useHeadlessService {
headlessService := resources.GenerateHeadlessServiceManifest(ctx, wObj)
err = resources.CreateResource(ctx, headlessService, c.Client)
if err != nil {
Expand Down Expand Up @@ -455,7 +455,7 @@ func (c *WorkspaceReconciler) getInferenceObjFromPreset(ctx context.Context, wOb
}

// applyInference applies inference spec.
func (c *WorkspaceReconciler) applyInference(ctx context.Context, wObj *kaitov1alpha1.Workspace, createHeadlessService bool) error {
func (c *WorkspaceReconciler) applyInference(ctx context.Context, wObj *kaitov1alpha1.Workspace, useHeadlessService bool) error {

inferErr := func() error {
if wObj.Inference.Template != nil {
Expand Down Expand Up @@ -490,7 +490,7 @@ func (c *WorkspaceReconciler) applyInference(ctx context.Context, wObj *kaitov1a
}
} else if apierrors.IsNotFound(err) {
// Need to create a new workload
workloadObj, err := inference.CreatePresetInference(ctx, wObj, inferenceObj, createHeadlessService, c.Client)
workloadObj, err := inference.CreatePresetInference(ctx, wObj, inferenceObj, useHeadlessService, c.Client)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/inference/preset-inferences.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func setTorchParams(ctx context.Context, kubeClient client.Client, wObj *kaitov1
}

func CreatePresetInference(ctx context.Context, workspaceObj *kaitov1alpha1.Workspace,
inferenceObj PresetInferenceParam, createHeadlessService bool, kubeClient client.Client) (client.Object, error) {
inferenceObj PresetInferenceParam, useHeadlessService bool, kubeClient client.Client) (client.Object, error) {
if inferenceObj.TorchRunParams != nil {
if err := setTorchParams(ctx, kubeClient, workspaceObj, inferenceObj); err != nil {
klog.ErrorS(err, "failed to update torch params", "workspace", workspaceObj)
Expand All @@ -112,7 +112,7 @@ func CreatePresetInference(ctx context.Context, workspaceObj *kaitov1alpha1.Work
switch inferenceObj.ModelName {
case "LLaMa2":
depObj = resources.GenerateStatefulSetManifest(ctx, workspaceObj, inferenceObj.Image, inferenceObj.ImagePullSecrets, *workspaceObj.Resource.Count, commands,
containerPorts, livenessProbe, readinessProbe, resourceReq, tolerations, volume, volumeMount, createHeadlessService)
containerPorts, livenessProbe, readinessProbe, resourceReq, tolerations, volume, volumeMount, useHeadlessService)
case "Falcon":
depObj = resources.GenerateDeploymentManifest(ctx, workspaceObj, inferenceObj.Image, inferenceObj.ImagePullSecrets, *workspaceObj.Resource.Count, commands,
containerPorts, livenessProbe, readinessProbe, resourceReq, tolerations, volume, volumeMount)
Expand Down
4 changes: 2 additions & 2 deletions pkg/resources/manifests.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func GenerateServiceManifest(ctx context.Context, workspaceObj *kaitov1alpha1.Wo
func GenerateStatefulSetManifest(ctx context.Context, workspaceObj *kaitov1alpha1.Workspace, imageName string,
imagePullSecretRefs []corev1.LocalObjectReference, replicas int, commands []string, containerPorts []corev1.ContainerPort,
livenessProbe, readinessProbe *corev1.Probe, resourceRequirements corev1.ResourceRequirements,
tolerations []corev1.Toleration, volumes []corev1.Volume, volumeMount []corev1.VolumeMount, createHeadlessService bool) *appsv1.StatefulSet {
tolerations []corev1.Toleration, volumes []corev1.Volume, volumeMount []corev1.VolumeMount, useHeadlessService bool) *appsv1.StatefulSet {

// Gather label requirements from workspaceObj's label selector
labelRequirements := make([]v1.LabelSelectorRequirement, 0, len(workspaceObj.Resource.LabelSelector.MatchLabels))
Expand Down Expand Up @@ -172,7 +172,7 @@ func GenerateStatefulSetManifest(ctx context.Context, workspaceObj *kaitov1alpha
},
},
}
if createHeadlessService {
if useHeadlessService {
ss.Spec.ServiceName = fmt.Sprintf("%s-headless", workspaceObj.Name)
}
return ss
Expand Down

0 comments on commit fd3f9db

Please sign in to comment.