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

[CI] apply resource logger to ray cluster test #3075

Merged
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
1 change: 1 addition & 0 deletions ray-operator/test/sampleyaml/raycluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func TestRayCluster(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
test := With(t)
g := NewWithT(t)
g.ConfigureWithT(WithRayClusterResourceLogger(test))

yamlFilePath := path.Join(GetSampleYAMLDir(test), tt.name)
namespace := test.NewTestNamespace()
Expand Down
24 changes: 24 additions & 0 deletions ray-operator/test/support/resource_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const (
JOBS_RESOURCE
SERVICES_RESOURCE
RAYJOBS_RESOURCE
RAYCLUSTERS_RESOURCE
)

type ResourceLoggerFunc = func(sb *strings.Builder)
Expand All @@ -23,6 +24,11 @@ func WithRayJobResourceLogger(t Test) types.GomegaTestingT {
return &RayResourceLogger{t: t, resources: resources}
}

func WithRayClusterResourceLogger(t Test) types.GomegaTestingT {
resources := []int{SERVICES_RESOURCE, RAYCLUSTERS_RESOURCE}
return &RayResourceLogger{t: t, resources: resources}
}

type RayResourceLogger struct {
t Test
resources []int
Expand Down Expand Up @@ -108,6 +114,22 @@ func (l *RayResourceLogger) FprintRayJobs(sb *strings.Builder) {
}
}

func (l *RayResourceLogger) FprintRayClusters(sb *strings.Builder) {
if rayClusters, err := l.t.Client().Ray().RayV1().RayClusters("").List(l.t.Ctx(), metav1.ListOptions{}); err == nil {
fmt.Fprintf(sb, "\n=== RayClusters across all namespaces ===\n")
for _, rayCluster := range rayClusters.Items {
rayClusterJSON, err := json.MarshalIndent(rayCluster, "", " ")
if err != nil {
fmt.Fprintf(sb, "Error marshaling rayCluster %s/%s: %v\n", rayCluster.Namespace, rayCluster.Name, err)
continue
}
fmt.Fprintf(sb, "---\n# rayCluster: %s/%s\n%s\n", rayCluster.Namespace, rayCluster.Name, string(rayClusterJSON))
}
} else {
fmt.Fprintf(sb, "Failed to get rayCluster: %v\n", err)
}
}

func (l *RayResourceLogger) MakeFprintUnsupportedResource(resource int) func(sb *strings.Builder) {
return func(sb *strings.Builder) {
fmt.Fprintf(sb, "Error: Unsupported resource: %d for RayResourceLogger\n", resource)
Expand All @@ -126,6 +148,8 @@ func (l *RayResourceLogger) GetLoggers() []ResourceLoggerFunc {
loggers = append(loggers, l.FprintServices)
case RAYJOBS_RESOURCE:
loggers = append(loggers, l.FprintRayJobs)
case RAYCLUSTERS_RESOURCE:
loggers = append(loggers, l.FprintRayClusters)
default:
loggers = append(loggers, l.MakeFprintUnsupportedResource(resource))
}
Expand Down
Loading