mirror of
https://github.com/hanzo-ml/kuberay.git
synced 2026-10-30 19:48:47 +00:00
+6








a5adbbe18b
* [RayService] More envtests that follow the most common scenario in the RayService code path (#2880) Signed-off-by: Rueian <[email protected]> * [RayService] Remove outdated env tests (#2886) Signed-off-by: kaihsun <[email protected]> * [RayService] Refactor envtests (#2888) * [docs][ray-operator] fix typo in Golang version (#2893) Project uses Golang 1.22 not 1.20. Signed-off-by: David Xia <[email protected]> * [Fix][kubectl-plugin] Fix no context nil error SIGSEGV in tests (#2892) Signed-off-by: Chi-Sheng Liu <[email protected]> * [CI] Enable testifylint rule (#2896) Signed-off-by: Chi-Sheng Liu <[email protected]> * [CI] Enable `testifylint` `error-nil` rule (#2907) * [kubectl-plugin][feat] support specifying number of head GPUs (#2895) when creating a RayCluster with `kubectl ray create cluster NAME --head-gpu N`. Similar to the `--worker-gpu` switch. Signed-off-by: David Xia <[email protected]> * Use webhook.CustomValidator instead of deprecated webhook.Validator. (#2803) * Use webhook.CustomValidator instead of deprecated webhook.Validator. * Move RayClusterWebhook to pkg/webhook/v1. * [kubectl-plugin] update context error messages (#2891) to tell user they can use `--context` to set the K8s context. Add tests Signed-off-by: David Xia <[email protected]> Co-authored-by: Chi-Sheng Liu <[email protected]> * [Fix][kubectl-plugin] make tests use a temporary kube config (#2894) file that's not at the default path. Right now tests fail if there's a K8s current context set with a command like `kubectl config use-context my-context`. This change allows tests to pass regardless of current context. Signed-off-by: David Xia <[email protected]> * [CI] Enable testifylint formatter rule (#2915) Signed-off-by: 400Ping <[email protected]> * [CI] Enable `testifylint` `empty` rule (#2908) * [CI] Enable testifylint bool-compare rule (#2911) Signed-off-by: 400Ping <[email protected]> * [CI] Auto download golang tools in pre-commit (#2917) Signed-off-by: Chi-Sheng Liu <[email protected]> * [RayService] a safeguard for preventing overriding the pending cluster during a upgrade (#2887) Signed-off-by: Rueian <[email protected]> * [RayService] Refactor unit tests for ShouldPrepareNewCluster (#2928) Signed-off-by: kaihsun <[email protected]> * [chore][kubectl-plugin] use consistent capitalization (#2922) in comments and console messages. * capitalize "Ray" when used as a proper noun * capitalize Ray K8s CRDs like "RayJob" and "RayCluster" * capitalize acronyms like "YAML" * fix some minor typos No functional changes. Signed-off-by: David Xia <[email protected]> * [CI] Enable `testifylint` `require-error` rule (#2909) * [kubectl-plugin] support general `kubectl` switches like `--context` (#2883) * [CI] Fix lint error (require-error) (#2931) Signed-off-by: Chi-Sheng Liu <[email protected]> * [CI] Enable `testifylint` `float-compare` rule (#2910) * [docs] move pre-commit instructions to main dev docs (#2921) * [CI] Enable `testifylint` `expected-actual` rule (#2914) * [CI] Generate CRD json schema separately in pre-commit (#2930) * [release][1/N] Update YAMLs from Ray 2.9 to Ray 2.41 (#2934) * Delete `[raycluster|rayjob|rayservice]_types_test.go` unnecessary tests (#2935) * [release][2/N] Update RayCluster Helm chart from Ray 2.9 to Ray 2.41 (#2936) Signed-off-by: kaihsun <[email protected]> * [release][3/N] Update RayService e2e tests YAML files from Ray 2.9 to Ray 2.41 (#2937) * [release][4/N] Update Ray images / versions in kubectl plugin (#2938) Signed-off-by: kaihsun <[email protected]> * [release][5/N] Update some RayJob YAMLs from Ray 2.9 to Ray 2.41 (#2941) Signed-off-by: kaihsun <[email protected]> * [release][6/N] Remove unnecessary YAMLs (#2946) Signed-off-by: kaihsun <[email protected]> * [docs][kubectl-plugin] add dev docs (#2912) Signed-off-by: David Xia <[email protected]> Co-authored-by: Chi-Sheng Liu <[email protected]> * [CI] Add shellcheck and fix error of it (#2933) * [chore][kubectl-plugin] use better test assertions (#2955) Fix two places. * use `assert.EqualError()` instead of `assert.Error()` to check the error string is what we expect * use testify assertion instead of string checking for better error output Signed-off-by: David Xia <[email protected]> * [chore] add Markdown linting pre-commit hook (#2953) Ignore most rules we violate for now. Fix these two violations. ``` pre-commit run markdownlint --all-files --show-diff-on-failure ... clients/python-client/README.md:106 MD001/heading-increment Heading levels should only increment by one level at a time [Expected: h3; Actual: h4] CHANGELOG.md:420:1 MD030/list-marker-space Spaces after list markers [Expected: 1; Actual: 2] ``` Signed-off-by: David Xia <[email protected]> * [chore][kubectl-plugin] use consistent capitalization (#2950) in comments and console messages. capitalize "Ray" when used as a proper noun. Similar to #2922. Signed-off-by: David Xia <[email protected]> * [Fix][RayJob] Invalid quote for RayJob submitter (#2949) Closes: ray-project/kuberay#2943 Signed-off-by: Chi-Sheng Liu <[email protected]> * [release][7/N] Update RayService YAMLs (#2956) * [CI] Enable testifylint len rule (#2945) Signed-off-by: LeoLiao123 <[email protected]> * [docs][kubectl-plugin] improve help messages (#2952) Signed-off-by: David Xia <[email protected]> * [kubectl-plugin] Fix panic when GPU resource is not set (#2954) Signed-off-by: win5923 <[email protected]> * [release][8/N] Upgrade Stable Diffusion RayService to Ray 2.41 (#2960) * [docs][kubectl-plugin] fix incorrect example commands (#2951) Signed-off-by: David Xia <[email protected]> Co-authored-by: Chi-Sheng Liu <[email protected]> * [fix][kubectl-plugin] set worker group CPU limit (#2958) when creating a new worker group with `kubectl ray create workergroup`. Write a unit test. I noticed we are setting resource limits equal to resource requests everywhere else but in this command. I have a K8s [LimitRange] that prevented the creation of these worker Pods that had CPU limit defaulting to less than their CPU requests. Describing the RayCluster showed this warning event. `Failed to create worker Pod hyperkube/, Pod "dxia-test-other-group-worker-pm2sh" is invalid: spec.containers[0].resources.requests: Invalid value: "2": must be less than or equal to cpu limit of 250m` Signed-off-by: David Xia <[email protected]> [LimitRange]: https://kubernetes.io/docs/concepts/policy/limit-range/ * [RayJob] Deflaky RayJob e2e tests (#2963) Signed-off-by: kaihsun <[email protected]> * [RayService] Deflaky RayService envtest (#2962) Signed-off-by: kaihsun <[email protected]> * [release][9/N] Update text summarizer RayService to Ray 2.41 (#2961) * [RayService] adapter vllm 0.6.1.post2 (#2823) * adapter vllm 0.6.1.post2 * fix var define * Unify the cpu Settings in serve.py in service.yaml, all set to 1 * Maintain the configuration with vllm0.5x * [Release] Upgrade ray-job.batch-inference.yaml image to 2.41 (#2971) Signed-off-by: Chi-Sheng Liu <[email protected]> * [chore][docs] enable Markdownlint rule MD010 (#2975) * [CI] Change Pre-commit-shellcheck-to-shellcheck-py (#2974) Signed-off-by: owenowenisme <[email protected]> * [release] Update Yunikorn YAML file to Ray 2.41 (#2969) Signed-off-by: Cheng-Yeh Chung <[email protected]> * [release] Update YuniKorn YAML files to Ray 2.41 (#2976) Signed-off-by: win5923 <[email protected]> * [chore][docs] enable Markdownlint rule MD004 (#2973) [Unordered list style][1] [1]: https://github.com/DavidAnson/markdownlint/blob/main/doc/Rules.md#md004---unordered-list-style * [Test] Use GcsFaultToleranceOptions in test and backward compatibility (#2972) * Update samples to use Ray 2.41.0 images (#2964) Signed-off-by: Andrew Sy Kim <[email protected]> * Update TPU Ray CR manifests to use Ray 2.41.0 (#2965) * [Refactor] Use constants for image tag, image repo, and versions in golang to avoid hard-coded strings (#2978) --------- Signed-off-by: Rueian <[email protected]> Signed-off-by: kaihsun <[email protected]> Signed-off-by: David Xia <[email protected]> Signed-off-by: Chi-Sheng Liu <[email protected]> Signed-off-by: 400Ping <[email protected]> Signed-off-by: LeoLiao123 <[email protected]> Signed-off-by: win5923 <[email protected]> Signed-off-by: owenowenisme <[email protected]> Signed-off-by: Cheng-Yeh Chung <[email protected]> Signed-off-by: Andrew Sy Kim <[email protected]> Co-authored-by: Rueian <[email protected]> Co-authored-by: Kai-Hsun Chen <[email protected]> Co-authored-by: David Xia <[email protected]> Co-authored-by: Chi-Sheng Liu <[email protected]> Co-authored-by: David Xia <[email protected]> Co-authored-by: Mykhailo Bobrovskyi <[email protected]> Co-authored-by: Ping <[email protected]> Co-authored-by: Owen Lin <[email protected]> Co-authored-by: Leo Liao <[email protected]> Co-authored-by: Blocka <[email protected]> Co-authored-by: zrant <[email protected]> Co-authored-by: kenchung285 <[email protected]> Co-authored-by: fscnick <[email protected]> Co-authored-by: ryanaoleary <[email protected]>
222 lines
6.7 KiB
Go
222 lines
6.7 KiB
Go
package get
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/ray-project/kuberay/kubectl-plugin/pkg/util"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
"k8s.io/apimachinery/pkg/api/resource"
|
|
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
"k8s.io/cli-runtime/pkg/genericclioptions"
|
|
"k8s.io/cli-runtime/pkg/printers"
|
|
kubefake "k8s.io/client-go/kubernetes/fake"
|
|
cmdtesting "k8s.io/kubectl/pkg/cmd/testing"
|
|
|
|
"github.com/ray-project/kuberay/kubectl-plugin/pkg/util/client"
|
|
|
|
rayv1 "github.com/ray-project/kuberay/ray-operator/apis/ray/v1"
|
|
rayClientFake "github.com/ray-project/kuberay/ray-operator/pkg/client/clientset/versioned/fake"
|
|
)
|
|
|
|
// This is to test Complete() and ensure that it is setting the namespace and arguments correctly
|
|
// No validation test is done here
|
|
func TestRayClusterGetComplete(t *testing.T) {
|
|
// Initialize members of the cluster get option struct and the struct itself
|
|
testStreams, _, _, _ := genericclioptions.NewTestIOStreams()
|
|
fakeClusterGetOptions := NewGetClusterOptions(testStreams)
|
|
fakeArgs := []string{"Expected", "output"}
|
|
|
|
*fakeClusterGetOptions.configFlags.Namespace = ""
|
|
fakeClusterGetOptions.AllNamespaces = false
|
|
|
|
err := fakeClusterGetOptions.Complete(fakeArgs)
|
|
require.NoError(t, err)
|
|
|
|
assert.True(t, fakeClusterGetOptions.AllNamespaces)
|
|
assert.Equal(t, fakeClusterGetOptions.args, fakeArgs)
|
|
}
|
|
|
|
// Test the Validation() step of the command.
|
|
func TestRayClusterGetValidate(t *testing.T) {
|
|
testStreams, _, _, _ := genericclioptions.NewTestIOStreams()
|
|
|
|
testNS, testContext, testBT, testImpersonate := "test-namespace", "test-context", "test-bearer-token", "test-person"
|
|
|
|
kubeConfigWithCurrentContext, err := util.CreateTempKubeConfigFile(t, testContext)
|
|
require.NoError(t, err)
|
|
|
|
kubeConfigWithoutCurrentContext, err := util.CreateTempKubeConfigFile(t, "")
|
|
require.NoError(t, err)
|
|
|
|
tests := []struct {
|
|
name string
|
|
opts *GetClusterOptions
|
|
expect string
|
|
expectError string
|
|
}{
|
|
{
|
|
name: "Test validation when no context is set",
|
|
opts: &GetClusterOptions{
|
|
configFlags: &genericclioptions.ConfigFlags{
|
|
KubeConfig: &kubeConfigWithoutCurrentContext,
|
|
},
|
|
AllNamespaces: false,
|
|
args: []string{"random_arg"},
|
|
ioStreams: &testStreams,
|
|
},
|
|
expectError: "no context is currently set, use \"--context\" or \"kubectl config use-context <context>\" to select a new one",
|
|
},
|
|
{
|
|
name: "no error when kubeconfig has current context and --context switch isn't set",
|
|
opts: &GetClusterOptions{
|
|
configFlags: &genericclioptions.ConfigFlags{
|
|
KubeConfig: &kubeConfigWithCurrentContext,
|
|
},
|
|
ioStreams: &testStreams,
|
|
},
|
|
},
|
|
{
|
|
name: "no error when kubeconfig has no current context and --context switch is set",
|
|
opts: &GetClusterOptions{
|
|
configFlags: &genericclioptions.ConfigFlags{
|
|
KubeConfig: &kubeConfigWithoutCurrentContext,
|
|
Context: &testContext,
|
|
},
|
|
ioStreams: &testStreams,
|
|
},
|
|
},
|
|
{
|
|
name: "no error when kubeconfig has current context and --context switch is set",
|
|
opts: &GetClusterOptions{
|
|
configFlags: &genericclioptions.ConfigFlags{
|
|
KubeConfig: &kubeConfigWithCurrentContext,
|
|
Context: &testContext,
|
|
},
|
|
ioStreams: &testStreams,
|
|
},
|
|
},
|
|
{
|
|
name: "Test validation when more than 1 arg",
|
|
opts: &GetClusterOptions{
|
|
// Use fake config to bypass the config flag checks
|
|
configFlags: &genericclioptions.ConfigFlags{
|
|
Namespace: &testNS,
|
|
Context: &testContext,
|
|
KubeConfig: &kubeConfigWithCurrentContext,
|
|
BearerToken: &testBT,
|
|
Impersonate: &testImpersonate,
|
|
ImpersonateGroup: &[]string{"fake-group"},
|
|
},
|
|
AllNamespaces: false,
|
|
args: []string{"fake", "args"},
|
|
ioStreams: &testStreams,
|
|
},
|
|
expectError: "too many arguments, either one or no arguments are allowed",
|
|
},
|
|
{
|
|
name: "Successful validation call",
|
|
opts: &GetClusterOptions{
|
|
// Use fake config to bypass the config flag checks
|
|
configFlags: &genericclioptions.ConfigFlags{
|
|
Namespace: &testNS,
|
|
Context: &testContext,
|
|
KubeConfig: &kubeConfigWithCurrentContext,
|
|
BearerToken: &testBT,
|
|
Impersonate: &testImpersonate,
|
|
ImpersonateGroup: &[]string{"fake-group"},
|
|
},
|
|
AllNamespaces: false,
|
|
args: []string{"random_arg"},
|
|
ioStreams: &testStreams,
|
|
},
|
|
expectError: "",
|
|
},
|
|
}
|
|
|
|
for _, tc := range tests {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
err := tc.opts.Validate()
|
|
if tc.expectError != "" {
|
|
require.Error(t, err, tc.expectError)
|
|
} else {
|
|
require.NoError(t, err)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
// Tests the Run() step of the command and ensure that the output is as expected.
|
|
func TestRayClusterGetRun(t *testing.T) {
|
|
tf := cmdtesting.NewTestFactory().WithNamespace("test")
|
|
defer tf.Cleanup()
|
|
|
|
testStreams, _, resBuf, _ := genericclioptions.NewTestIOStreams()
|
|
|
|
fakeClusterGetOptions := NewGetClusterOptions(testStreams)
|
|
|
|
rayCluster := &rayv1.RayCluster{
|
|
ObjectMeta: v1.ObjectMeta{
|
|
Name: "raycluster-kuberay",
|
|
Namespace: "test",
|
|
},
|
|
Status: rayv1.RayClusterStatus{
|
|
DesiredWorkerReplicas: 2,
|
|
AvailableWorkerReplicas: 2,
|
|
DesiredCPU: resource.MustParse("6"),
|
|
DesiredGPU: resource.MustParse("1"),
|
|
DesiredTPU: resource.MustParse("1"),
|
|
DesiredMemory: resource.MustParse("24Gi"),
|
|
State: rayv1.Ready,
|
|
},
|
|
}
|
|
|
|
kubeClientSet := kubefake.NewClientset()
|
|
rayClient := rayClientFake.NewSimpleClientset(rayCluster)
|
|
k8sClients := client.NewClientForTesting(kubeClientSet, rayClient)
|
|
|
|
// Initialize the printer with an empty print options since we are setting the column definition later
|
|
expectedTestResultTable := printers.NewTablePrinter(printers.PrintOptions{})
|
|
|
|
// Define the column names and types
|
|
testResTable := &v1.Table{
|
|
ColumnDefinitions: []v1.TableColumnDefinition{
|
|
{Name: "Name", Type: "string"},
|
|
{Name: "Namespace", Type: "string"},
|
|
{Name: "Desired Workers", Type: "string"},
|
|
{Name: "Available Workers", Type: "string"},
|
|
{Name: "CPUs", Type: "string"},
|
|
{Name: "GPUs", Type: "string"},
|
|
{Name: "TPUs", Type: "string"},
|
|
{Name: "Memory", Type: "string"},
|
|
{Name: "Age", Type: "string"},
|
|
},
|
|
}
|
|
|
|
testResTable.Rows = append(testResTable.Rows, v1.TableRow{
|
|
Cells: []interface{}{
|
|
"raycluster-kuberay",
|
|
"test",
|
|
"2",
|
|
"2",
|
|
"6",
|
|
"1",
|
|
"1",
|
|
"24Gi",
|
|
"<unknown>",
|
|
},
|
|
})
|
|
|
|
// Result buffer for the expected table result
|
|
var resbuffer bytes.Buffer
|
|
err := expectedTestResultTable.PrintObj(testResTable, &resbuffer)
|
|
require.NoError(t, err)
|
|
|
|
err = fakeClusterGetOptions.Run(context.Background(), k8sClients)
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, resbuffer.String(), resBuf.String())
|
|
}
|