Skip to content

Commit

Permalink
[RayService] Refactor fake http proxy client and test (#2636)
Browse files Browse the repository at this point in the history
Signed-off-by: kaihsun <[email protected]>
  • Loading branch information
kevin85421 authored Dec 12, 2024
1 parent e4a9645 commit 8e1b922
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 29 deletions.
2 changes: 1 addition & 1 deletion docs/reference/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ _Appears in:_
| `upgradeStrategy` _[RayServiceUpgradeStrategy](#rayserviceupgradestrategy)_ | UpgradeStrategy represents the strategy used when upgrading the RayService. Currently supports `NewCluster` and `None` | | |
| `serveConfigV2` _string_ | Important: Run "make" to regenerate code after modifying this file<br />Defines the applications and deployments to deploy, should be a YAML multi-line scalar string. | | |
| `rayClusterConfig` _[RayClusterSpec](#rayclusterspec)_ | | | |
| `excludeHeadPodFromServeSvc` _boolean_ | If the field is set to true, the value of the label `ray.io/serve` on the head Pod should always be false. | | |
| `excludeHeadPodFromServeSvc` _boolean_ | If the field is set to true, the value of the label `ray.io/serve` on the head Pod should always be false.<br />Therefore, the head Pod's endpoint will not be added to the Kubernetes Serve service. | | |



Expand Down
1 change: 1 addition & 0 deletions ray-operator/apis/ray/v1/rayservice_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ type RayServiceSpec struct {
ServeConfigV2 string `json:"serveConfigV2,omitempty"`
RayClusterSpec RayClusterSpec `json:"rayClusterConfig,omitempty"`
// If the field is set to true, the value of the label `ray.io/serve` on the head Pod should always be false.
// Therefore, the head Pod's endpoint will not be added to the Kubernetes Serve service.
ExcludeHeadPodFromServeSvc bool `json:"excludeHeadPodFromServeSvc,omitempty"`
}

Expand Down
19 changes: 6 additions & 13 deletions ray-operator/controllers/ray/rayservice_controller_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -921,18 +921,11 @@ func initFakeDashboardClient(appName string, deploymentStatus string, appStatus
return &fakeDashboardClient
}

type FakeRayHttpProxyClient struct {
isHealthy bool
}

func (*FakeRayHttpProxyClient) InitClient() {}
func (f *FakeRayHttpProxyClient) CheckProxyActorHealth(_ context.Context) error {
if f.isHealthy {
return nil
func initFakeRayHttpProxyClient(isHealthy bool) utils.RayHttpProxyClientInterface {
return &utils.FakeRayHttpProxyClient{
IsHealthy: isHealthy,
}
return fmt.Errorf("the proxy actor is unhealthy")
}
func (*FakeRayHttpProxyClient) SetHostIp(_, _, _ string, _ int) {}

func TestLabelHeadPodForServeStatus(t *testing.T) {
tests := map[string]struct {
Expand Down Expand Up @@ -995,15 +988,15 @@ func TestLabelHeadPodForServeStatus(t *testing.T) {
runtimeObjects := []runtime.Object{headPod}
fakeClient := clientFake.NewClientBuilder().WithScheme(newScheme).WithRuntimeObjects(runtimeObjects...).Build()
ctx := context.TODO()

fakeRayHttpProxyClient := initFakeRayHttpProxyClient(tc.isHealthy)
// Initialize RayService reconciler.
r := &RayServiceReconciler{
Client: fakeClient,
Recorder: &record.FakeRecorder{},
Scheme: newScheme,
httpProxyClientFunc: func() utils.RayHttpProxyClientInterface {
return &FakeRayHttpProxyClient{
isHealthy: tc.isHealthy,
}
return fakeRayHttpProxyClient
},
}

Expand Down
22 changes: 7 additions & 15 deletions ray-operator/controllers/ray/utils/fake_httpproxy_httpclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,19 @@ package utils
import (
"context"
"fmt"
"net/http"
"time"
)

type FakeRayHttpProxyClient struct {
client http.Client
httpProxyURL string
IsHealthy bool
}

func (r *FakeRayHttpProxyClient) InitClient() {
r.client = http.Client{
Timeout: 20 * time.Millisecond,
}
}
func (fc *FakeRayHttpProxyClient) InitClient() {}

func (r *FakeRayHttpProxyClient) SetHostIp(hostIp, _, _ string, port int) {
r.httpProxyURL = fmt.Sprintf("http://%s:%d", hostIp, port)
}
func (fc *FakeRayHttpProxyClient) SetHostIp(_, _, _ string, _ int) {}

func (r *FakeRayHttpProxyClient) CheckProxyActorHealth(_ context.Context) error {
// TODO: test check return error cases.
// Always return successful.
func (fc *FakeRayHttpProxyClient) CheckProxyActorHealth(_ context.Context) error {
if !fc.IsHealthy {
return fmt.Errorf("fake proxy actor is not healthy")
}
return nil
}

0 comments on commit 8e1b922

Please sign in to comment.