-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: RAG engine deployment creation (#660)
**Reason for Change**: Generate and create RAGengine deployment - part 1 **Requirements** - [ ] added unit tests and e2e tests (if applicable). **Issue Fixed**: <!-- If this PR fixes GitHub issue 4321, add "Fixes #4321" to the next line. --> **Notes for Reviewers**: Signed-off-by: Bangqi Zhu <[email protected]> Co-authored-by: Bangqi Zhu <[email protected]>
- Loading branch information
1 parent
fcd5d1c
commit cafb947
Showing
9 changed files
with
543 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
package controllers | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/kaito-project/kaito/pkg/utils" | ||
"github.com/kaito-project/kaito/pkg/utils/consts" | ||
|
||
kaitov1alpha1 "github.com/kaito-project/kaito/api/v1alpha1" | ||
"github.com/kaito-project/kaito/pkg/ragengine/manifests" | ||
"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" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
const ( | ||
ProbePath = "/health" | ||
Port5000 = int32(5000) | ||
) | ||
|
||
var ( | ||
containerPorts = []corev1.ContainerPort{{ | ||
ContainerPort: Port5000, | ||
}, | ||
} | ||
|
||
livenessProbe = &corev1.Probe{ | ||
ProbeHandler: corev1.ProbeHandler{ | ||
HTTPGet: &corev1.HTTPGetAction{ | ||
Port: intstr.FromInt(5000), | ||
Path: ProbePath, | ||
}, | ||
}, | ||
InitialDelaySeconds: 600, // 10 minutes | ||
PeriodSeconds: 10, | ||
} | ||
|
||
readinessProbe = &corev1.Probe{ | ||
ProbeHandler: corev1.ProbeHandler{ | ||
HTTPGet: &corev1.HTTPGetAction{ | ||
Port: intstr.FromInt(5000), | ||
Path: ProbePath, | ||
}, | ||
}, | ||
InitialDelaySeconds: 30, | ||
PeriodSeconds: 10, | ||
} | ||
|
||
tolerations = []corev1.Toleration{ | ||
{ | ||
Effect: corev1.TaintEffectNoSchedule, | ||
Operator: corev1.TolerationOpExists, | ||
Key: resources.CapacityNvidiaGPU, | ||
}, | ||
{ | ||
Effect: corev1.TaintEffectNoSchedule, | ||
Value: consts.GPUString, | ||
Key: consts.SKUString, | ||
Operator: corev1.TolerationOpEqual, | ||
}, | ||
} | ||
) | ||
|
||
func CreatePresetRAG(ctx context.Context, ragEngineObj *kaitov1alpha1.RAGEngine, revisionNum string, kubeClient client.Client) (client.Object, error) { | ||
var volumes []corev1.Volume | ||
var volumeMounts []corev1.VolumeMount | ||
|
||
shmVolume, shmVolumeMount := utils.ConfigSHMVolume(*ragEngineObj.Spec.Compute.Count) | ||
if shmVolume.Name != "" { | ||
volumes = append(volumes, shmVolume) | ||
} | ||
if shmVolumeMount.Name != "" { | ||
volumeMounts = append(volumeMounts, shmVolumeMount) | ||
} | ||
|
||
var resourceReq corev1.ResourceRequirements | ||
|
||
if ragEngineObj.Spec.Embedding.Local != nil { | ||
skuNumGPUs, err := utils.GetSKUNumGPUs(ctx, kubeClient, ragEngineObj.Status.WorkerNodes, | ||
ragEngineObj.Spec.Compute.InstanceType, "1") | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to get SKU num GPUs: %v", err) | ||
} | ||
|
||
resourceReq = corev1.ResourceRequirements{ | ||
Requests: corev1.ResourceList{ | ||
corev1.ResourceName(resources.CapacityNvidiaGPU): resource.MustParse(skuNumGPUs), | ||
}, | ||
Limits: corev1.ResourceList{ | ||
corev1.ResourceName(resources.CapacityNvidiaGPU): resource.MustParse(skuNumGPUs), | ||
}, | ||
} | ||
|
||
} | ||
commands := utils.ShellCmd("python3 main.py") | ||
// TODO: provide this image | ||
image := "mcr.microsoft.com/aks/kaito/kaito-rag-service:0.0.1" | ||
imagePullSecretRefs := []corev1.LocalObjectReference{} | ||
|
||
depObj := manifests.GenerateRAGDeploymentManifest(ctx, ragEngineObj, revisionNum, image, imagePullSecretRefs, *ragEngineObj.Spec.Compute.Count, commands, | ||
containerPorts, livenessProbe, readinessProbe, resourceReq, tolerations, volumes, volumeMounts) | ||
|
||
err := resources.CreateResource(ctx, depObj, kubeClient) | ||
if client.IgnoreAlreadyExists(err) != nil { | ||
return nil, err | ||
} | ||
return depObj, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
package controllers | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/kaito-project/kaito/pkg/utils/consts" | ||
"github.com/kaito-project/kaito/pkg/utils/test" | ||
"github.com/stretchr/testify/mock" | ||
appsv1 "k8s.io/api/apps/v1" | ||
) | ||
|
||
func TestCreatePresetRAG(t *testing.T) { | ||
test.RegisterTestModel() | ||
|
||
testcases := map[string]struct { | ||
nodeCount int | ||
callMocks func(c *test.MockClient) | ||
expectedCmd string | ||
expectedGPUReq string | ||
expectedImage string | ||
expectedVolume string | ||
}{ | ||
"test-rag-model": { | ||
nodeCount: 1, | ||
callMocks: func(c *test.MockClient) { | ||
c.On("Create", mock.IsType(context.TODO()), mock.IsType(&appsv1.Deployment{}), mock.Anything).Return(nil) | ||
}, | ||
expectedCmd: "/bin/sh -c python3 main.py", | ||
expectedImage: "mcr.microsoft.com/aks/kaito/kaito-rag-service:0.0.1", | ||
}, | ||
} | ||
|
||
for k, tc := range testcases { | ||
t.Run(k, func(t *testing.T) { | ||
os.Setenv("CLOUD_PROVIDER", consts.AzureCloudName) | ||
mockClient := test.NewClient() | ||
tc.callMocks(mockClient) | ||
|
||
ragEngineObj := test.MockRAGEngineWithPreset | ||
createdObject, _ := CreatePresetRAG(context.TODO(), ragEngineObj, "1", mockClient) | ||
|
||
workloadCmd := strings.Join((createdObject.(*appsv1.Deployment)).Spec.Template.Spec.Containers[0].Command, " ") | ||
|
||
if workloadCmd != tc.expectedCmd { | ||
t.Errorf("%s: main cmdline is not expected, got %s, expected %s", k, workloadCmd, tc.expectedCmd) | ||
} | ||
|
||
image := (createdObject.(*appsv1.Deployment)).Spec.Template.Spec.Containers[0].Image | ||
|
||
if image != tc.expectedImage { | ||
t.Errorf("%s: image is not expected, got %s, expected %s", k, image, tc.expectedImage) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.