Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: restruct workspace controller code - part 2 #683

Merged
merged 2 commits into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/workspace/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (
awsv1beta1 "github.com/aws/karpenter-provider-aws/pkg/apis/v1beta1"
"github.com/kaito-project/kaito/pkg/featuregates"
"github.com/kaito-project/kaito/pkg/k8sclient"
"github.com/kaito-project/kaito/pkg/nodeclaim"
"github.com/kaito-project/kaito/pkg/utils/consts"
"github.com/kaito-project/kaito/pkg/utils/nodeclaim"
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
"sigs.k8s.io/karpenter/pkg/apis/v1beta1"

Expand Down
6 changes: 3 additions & 3 deletions pkg/ragengine/controllers/ragengine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ import (
"github.com/go-logr/logr"
kaitov1alpha1 "github.com/kaito-project/kaito/api/v1alpha1"
"github.com/kaito-project/kaito/pkg/featuregates"
"github.com/kaito-project/kaito/pkg/machine"
"github.com/kaito-project/kaito/pkg/nodeclaim"
"github.com/kaito-project/kaito/pkg/resources"
"github.com/kaito-project/kaito/pkg/utils"
"github.com/kaito-project/kaito/pkg/utils/consts"
"github.com/kaito-project/kaito/pkg/utils/machine"
"github.com/kaito-project/kaito/pkg/utils/nodeclaim"
"github.com/kaito-project/kaito/pkg/utils/resources"
"github.com/samber/lo"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
Expand Down
4 changes: 2 additions & 2 deletions pkg/ragengine/controllers/ragengine_gc_finalizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (

kaitov1alpha1 "github.com/kaito-project/kaito/api/v1alpha1"
"github.com/kaito-project/kaito/pkg/featuregates"
"github.com/kaito-project/kaito/pkg/machine"
"github.com/kaito-project/kaito/pkg/nodeclaim"
"github.com/kaito-project/kaito/pkg/utils/consts"
"github.com/kaito-project/kaito/pkg/utils/machine"
"github.com/kaito-project/kaito/pkg/utils/nodeclaim"
"k8s.io/klog/v2"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down
2 changes: 1 addition & 1 deletion pkg/machine/machine.go → pkg/utils/machine/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (

"github.com/aws/karpenter-core/pkg/apis/v1alpha5"
kaitov1alpha1 "github.com/kaito-project/kaito/api/v1alpha1"
"github.com/kaito-project/kaito/pkg/resources"
"github.com/kaito-project/kaito/pkg/utils/consts"
"github.com/kaito-project/kaito/pkg/utils/resources"
"github.com/samber/lo"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (
azurev1alpha2 "github.com/Azure/karpenter-provider-azure/pkg/apis/v1alpha2"
awsv1beta1 "github.com/aws/karpenter-provider-aws/pkg/apis/v1beta1"
kaitov1alpha1 "github.com/kaito-project/kaito/api/v1alpha1"
"github.com/kaito-project/kaito/pkg/resources"
"github.com/kaito-project/kaito/pkg/utils/consts"
"github.com/kaito-project/kaito/pkg/utils/resources"
"github.com/samber/lo"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
15 changes: 8 additions & 7 deletions pkg/workspace/controllers/workspace_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,20 @@ import (
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"

"github.com/kaito-project/kaito/pkg/featuregates"
"github.com/kaito-project/kaito/pkg/nodeclaim"
"github.com/kaito-project/kaito/pkg/tuning"
"github.com/kaito-project/kaito/pkg/utils/consts"
"github.com/kaito-project/kaito/pkg/utils/nodeclaim"
"github.com/kaito-project/kaito/pkg/workspace/tuning"
batchv1 "k8s.io/api/batch/v1"
"sigs.k8s.io/karpenter/pkg/apis/v1beta1"

"github.com/aws/karpenter-core/pkg/apis/v1alpha5"
"github.com/go-logr/logr"
kaitov1alpha1 "github.com/kaito-project/kaito/api/v1alpha1"
"github.com/kaito-project/kaito/pkg/machine"
"github.com/kaito-project/kaito/pkg/resources"
manifests "github.com/kaito-project/kaito/pkg/resources"
"github.com/kaito-project/kaito/pkg/utils"
"github.com/kaito-project/kaito/pkg/utils/machine"
"github.com/kaito-project/kaito/pkg/utils/plugin"
"github.com/kaito-project/kaito/pkg/utils/resources"
"github.com/kaito-project/kaito/pkg/workspace/inference"
"github.com/samber/lo"
appsv1 "k8s.io/api/apps/v1"
Expand Down Expand Up @@ -633,12 +634,12 @@ func (c *WorkspaceReconciler) ensureService(ctx context.Context, wObj *kaitov1al

if presetName := getPresetName(wObj); presetName != "" {
model := plugin.KaitoModelRegister.MustGet(presetName)
serviceObj := resources.GenerateServiceManifest(ctx, wObj, serviceType, model.SupportDistributedInference())
serviceObj := manifests.GenerateServiceManifest(ctx, wObj, serviceType, model.SupportDistributedInference())
if err := resources.CreateResource(ctx, serviceObj, c.Client); err != nil {
return err
}
if model.SupportDistributedInference() {
headlessService := resources.GenerateHeadlessServiceManifest(ctx, wObj)
headlessService := manifests.GenerateHeadlessServiceManifest(ctx, wObj)
if err := resources.CreateResource(ctx, headlessService, c.Client); err != nil {
return err
}
Expand Down Expand Up @@ -759,7 +760,7 @@ func (c *WorkspaceReconciler) applyInference(ctx context.Context, wObj *kaitov1a
volumes = append(volumes, adapterVolume)
volumeMounts = append(volumeMounts, adapterVolumeMount)
}
initContainers, envs := resources.GenerateInitContainers(wObj, volumeMounts)
initContainers, envs := manifests.GenerateInitContainers(wObj, volumeMounts)
spec := &deployment.Spec

spec.Template.Spec.InitContainers = initContainers
Expand Down
4 changes: 2 additions & 2 deletions pkg/workspace/controllers/workspace_gc_finalizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (

kaitov1alpha1 "github.com/kaito-project/kaito/api/v1alpha1"
"github.com/kaito-project/kaito/pkg/featuregates"
"github.com/kaito-project/kaito/pkg/machine"
"github.com/kaito-project/kaito/pkg/nodeclaim"
"github.com/kaito-project/kaito/pkg/utils/consts"
"github.com/kaito-project/kaito/pkg/utils/machine"
"github.com/kaito-project/kaito/pkg/utils/nodeclaim"
"k8s.io/klog/v2"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down
7 changes: 4 additions & 3 deletions pkg/workspace/inference/preset-inferences.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import (

kaitov1alpha1 "github.com/kaito-project/kaito/api/v1alpha1"
"github.com/kaito-project/kaito/pkg/model"
"github.com/kaito-project/kaito/pkg/resources"
manifests "github.com/kaito-project/kaito/pkg/resources"
"github.com/kaito-project/kaito/pkg/utils/resources"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/util/intstr"
Expand Down Expand Up @@ -156,10 +157,10 @@ func CreatePresetInference(ctx context.Context, workspaceObj *kaitov1alpha1.Work

var depObj client.Object
if supportDistributedInference {
depObj = resources.GenerateStatefulSetManifest(ctx, workspaceObj, image, imagePullSecrets, *workspaceObj.Resource.Count, commands,
depObj = manifests.GenerateStatefulSetManifest(ctx, workspaceObj, image, imagePullSecrets, *workspaceObj.Resource.Count, commands,
containerPorts, livenessProbe, readinessProbe, resourceReq, tolerations, volumes, volumeMounts)
} else {
depObj = resources.GenerateDeploymentManifest(ctx, workspaceObj, revisionNum, image, imagePullSecrets, *workspaceObj.Resource.Count, commands,
depObj = manifests.GenerateDeploymentManifest(ctx, workspaceObj, revisionNum, image, imagePullSecrets, *workspaceObj.Resource.Count, commands,
containerPorts, livenessProbe, readinessProbe, resourceReq, tolerations, volumes, volumeMounts)
}
err = resources.CreateResource(ctx, depObj, kubeClient)
Expand Down
5 changes: 3 additions & 2 deletions pkg/workspace/inference/template_inference.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import (
"context"

kaitov1alpha1 "github.com/kaito-project/kaito/api/v1alpha1"
"github.com/kaito-project/kaito/pkg/resources"
manifests "github.com/kaito-project/kaito/pkg/resources"
"github.com/kaito-project/kaito/pkg/utils/resources"
"sigs.k8s.io/controller-runtime/pkg/client"
)

func CreateTemplateInference(ctx context.Context, workspaceObj *kaitov1alpha1.Workspace, kubeClient client.Client) (client.Object, error) {
depObj := resources.GenerateDeploymentManifestWithPodTemplate(ctx, workspaceObj, tolerations)
depObj := manifests.GenerateDeploymentManifestWithPodTemplate(ctx, workspaceObj, tolerations)
err := resources.CreateResource(ctx, client.Object(depObj), kubeClient)
if client.IgnoreAlreadyExists(err) != nil {
return nil, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ import (

kaitov1alpha1 "github.com/kaito-project/kaito/api/v1alpha1"
"github.com/kaito-project/kaito/pkg/model"
"github.com/kaito-project/kaito/pkg/resources"
manifests "github.com/kaito-project/kaito/pkg/resources"
"github.com/kaito-project/kaito/pkg/utils"
"github.com/kaito-project/kaito/pkg/utils/resources"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/klog/v2"
Expand Down Expand Up @@ -356,7 +357,7 @@ func CreatePresetTuning(ctx context.Context, workspaceObj *kaitov1alpha1.Workspa
Name: "PYTORCH_CUDA_ALLOC_CONF",
Value: "expandable_segments:True",
})
jobObj := resources.GenerateTuningJobManifest(ctx, workspaceObj, revisionNum, tuningImage, imagePullSecrets, *workspaceObj.Resource.Count, commands,
jobObj := manifests.GenerateTuningJobManifest(ctx, workspaceObj, revisionNum, tuningImage, imagePullSecrets, *workspaceObj.Resource.Count, commands,
containerPorts, nil, nil, resourceReq, tolerations, initContainers, sidecarContainers, volumes, volumeMounts, envVars)

err = resources.CreateResource(ctx, jobObj, kubeClient)
Expand Down
3 changes: 1 addition & 2 deletions presets/models/falcon/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ package falcon
import (
"time"

"github.com/kaito-project/kaito/pkg/tuning"

kaitov1alpha1 "github.com/kaito-project/kaito/api/v1alpha1"
"github.com/kaito-project/kaito/pkg/model"
"github.com/kaito-project/kaito/pkg/utils/plugin"
"github.com/kaito-project/kaito/pkg/workspace/inference"
"github.com/kaito-project/kaito/pkg/workspace/tuning"
)

func init() {
Expand Down