mirror of
https://github.com/hanzo-ml/kuberay.git
synced 2026-10-30 19:48:47 +00:00
* feat: extract compute template from spec Signed-off-by: machichima <[email protected]> * feat: add compute template middleware Signed-off-by: machichima <[email protected]> * fix: extract cluster spec from request correctly Signed-off-by: machichima <[email protected]> * feat: convert request to map then to clusterSpec Signed-off-by: machichima <[email protected]> * feat: parse anno/cpu/mem from compute template to request Signed-off-by: machichima <[email protected]> * fix: get compute template name without converting to ClusterSpec struct Signed-off-by: machichima <[email protected]> * feat: apply gpu/extend/toleration Signed-off-by: machichima <[email protected]> * feat: forward modified request body Signed-off-by: machichima <[email protected]> * feat: deal with case with no head/workerGroupSpec set Signed-off-by: machichima <[email protected]> * feat: also support for rayjob and rayservice Signed-off-by: machichima <[email protected]> * test: structure for test compute template middleware Just a structure, test does not work now Signed-off-by: machichima <[email protected]> * fix: update field and match types Signed-off-by: machichima <[email protected]> * feat: use remote execute for apiserver sdk e2e test Signed-off-by: machichima <[email protected]> * feat: pass through if no spec & convert to json Signed-off-by: machichima <[email protected]> * feat: check request body type for unmarshal Signed-off-by: machichima <[email protected]> * test: enable setitng content type in execCommandWithCurlInPod * Trigger CI Signed-off-by: machichima <[email protected]> * fix: extract client manager for mocking * Trigger CI Signed-off-by: machichima <[email protected]> * fix: add missing methods & clean up code * refactor: clean up print * build: go mod tidy * Trigger CI Signed-off-by: machichima <[email protected]> * Trigger CI Signed-off-by: machichima <[email protected]> * refactor: remove unused args * refactor: interface to any * refactor: remove redundant else block * refactor: status code 500 to 422 * feat: support memory unit * fix: use ProxyRoundTripper is apiserver client & remove remote execute client * fix: base url use kubernetesConfig.Host --------- Signed-off-by: machichima <[email protected]>
83 lines
2.2 KiB
Go
83 lines
2.2 KiB
Go
package manager
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/golang/mock/gomock"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
corev1 "k8s.io/api/core/v1"
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
kubernetesfake "k8s.io/client-go/kubernetes/fake"
|
|
|
|
"github.com/ray-project/kuberay/apiserver/pkg/client"
|
|
api "github.com/ray-project/kuberay/proto/go_client"
|
|
)
|
|
|
|
func TestPopulateComputeTemplate(t *testing.T) {
|
|
ctx := context.Background()
|
|
namespace := "test-namespace"
|
|
headConfigMapName := "head"
|
|
workerConfigMapName := "worker"
|
|
|
|
headConfigMap := &corev1.ConfigMap{
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
Name: headConfigMapName,
|
|
Namespace: namespace,
|
|
},
|
|
Data: map[string]string{
|
|
"name": headConfigMapName,
|
|
"namespace": namespace,
|
|
"cpu": "2",
|
|
"memory": "4",
|
|
},
|
|
}
|
|
workerConfigMap := &corev1.ConfigMap{
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
Name: workerConfigMapName,
|
|
Namespace: namespace,
|
|
},
|
|
Data: map[string]string{
|
|
"name": workerConfigMapName,
|
|
"namespace": namespace,
|
|
"cpu": "2",
|
|
"memory": "4",
|
|
},
|
|
}
|
|
|
|
clusterSpec := &api.ClusterSpec{
|
|
HeadGroupSpec: &api.HeadGroupSpec{
|
|
ComputeTemplate: headConfigMapName,
|
|
},
|
|
WorkerGroupSpec: []*api.WorkerGroupSpec{
|
|
{
|
|
ComputeTemplate: workerConfigMapName,
|
|
},
|
|
},
|
|
}
|
|
|
|
// mock controller
|
|
ctrl := gomock.NewController(t)
|
|
|
|
// mock client manager
|
|
mockClientManager := NewMockClientManagerInterface(ctrl)
|
|
mockKubeClient := client.NewMockKubernetesClientInterface(ctrl)
|
|
mockClientManager.EXPECT().KubernetesClient().Return(mockKubeClient).Times(2)
|
|
|
|
// mock config map client
|
|
fakeClientset := kubernetesfake.NewClientset(headConfigMap, workerConfigMap)
|
|
configMapClient := fakeClientset.CoreV1().ConfigMaps(namespace)
|
|
mockKubeClient.EXPECT().ConfigMapClient(namespace).Return(configMapClient).Times(2)
|
|
|
|
// Run
|
|
resourceManager := NewResourceManager(mockClientManager)
|
|
computeTemplates, err := resourceManager.PopulateComputeTemplate(ctx, clusterSpec, namespace)
|
|
|
|
// Assert
|
|
require.NoError(t, err)
|
|
assert.Len(t, computeTemplates, 2)
|
|
assert.Contains(t, computeTemplates, headConfigMapName)
|
|
assert.Contains(t, computeTemplates, workerConfigMapName)
|
|
}
|