Skip to content

Conversation

@ikchifo
Copy link
Contributor

@ikchifo ikchifo commented Jan 9, 2026

Why are these changes needed?

NewSimpleClientset and its successor NewClientset do not support FieldSelector filtering for List operations in unit tests. Tests currently rely on manual name checking as a workaround, which diverges from real Kubernetes API server behavior.

This PR adds client-go reactors to simulate server-side FieldSelector filtering, making fake client behavior match the real Kubernetes API more closely.

Before

Tests manually filter results after List calls:

for _, rayCluster := range rayClusterList.Items {
    if cluster != "" && rayCluster.Name != cluster {
        continue
    }

After

Reactor handles filtering automatically, matching real API behavior. Manual workarounds removed.

What did I do?

  1. Created AddRayClusterFieldSelectorReactor helper in pkg/util/client/testing/reactor.go
  2. Applied reactor to completion_test.go and get_cluster_test.go
  3. Removed manual name filtering workaround from completion.go
  4. Migrated 6 test files from deprecated NewSimpleClientset to NewClientset

Related issue number

Closes #4337

Checks

  • I've made sure the tests are passing.
  • Testing Strategy
    • Unit tests
    • Manual tests
    • This PR is not tested :(

cc @justinyeh1995 @CheyuWu @rueian

…t tests

Add AddRayClusterFieldSelectorReactor helper that simulates server-side
FieldSelector filtering in fake client tests. This addresses issue ray-project#4337
by allowing tests to verify filtering behavior without manual name checks.

Refs: ray-project#4337
Use the new AddRayClusterFieldSelectorReactor in workergroup completion
tests to properly simulate server-side filtering behavior.

Refs: ray-project#4337
Remove the workaround that manually filtered clusters by name since the
fake client now properly supports FieldSelector filtering via reactors.

Refs: ray-project#4337
NewSimpleClientset is deprecated in favor of NewClientset for better
server-side apply testing support.

Note: scale_cluster_test.go is not migrated because it uses Update
operations that require schema definitions missing from the generated
applyconfiguration internal schema.

Refs: ray-project#4337
Copy link
Contributor

@justinyeh1995 justinyeh1995 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @ikchifo, would you mind helping update
kubectl-plugin/pkg/cmd/scale/scale_cluster_test.go as well?

@justinyeh1995
Copy link
Contributor

Manual test looks good to me with

pushd kubectl-plugin > /dev/null
go build cmd/kubectl-ray.go
mv kubectl-ray ~/.krew/bin
popd > /dev/null
export PATH=$PATH:$HOME/.kubectl-plugin-completion
image

@ikchifo
Copy link
Contributor Author

ikchifo commented Jan 10, 2026

Hi @ikchifo, would you mind helping update kubectl-plugin/pkg/cmd/scale/scale_cluster_test.go as well?

@justinyeh1995 Investigated this - and couldn't migrate scale_cluster_test.go as is because it uses Update() operations, and NewClientset requires Server-Side Apply schemas that aren't generated for RayCluster.
Reactors can't bypass this since validation happens before they're invoked. We would need changes in ray-operator's codegen to fix it.

schema error: no type found matching: com.github.ray-project.kuberay.ray-operator.apis.ray.v1.RayCluster

ikchifo and others added 2 commits January 10, 2026 07:25
…t setup

Add a convenience wrapper that creates a fake Ray clientset with
FieldSelector reactor pre-configured. This simplifies test setup
and ensures consistent behavior across tests.

Also applies reactor to get_cluster_test.go and fixes test data
to match actual cluster names now that FieldSelector properly filters.

Refs: ray-project#4337
Co-authored-by: JustinYeh <justinyeh1995@gmail.com>
Signed-off-by: Ikenna <ikennachifo@gmail.com>
@ikchifo ikchifo force-pushed the kubectl-plugin/fieldselector-reactor-tests branch from df9ad48 to f3df8bc Compare January 10, 2026 12:30
@justinyeh1995
Copy link
Contributor

Hi @ikchifo, would you mind helping update kubectl-plugin/pkg/cmd/scale/scale_cluster_test.go as well?

@justinyeh1995 Investigated this - and couldn't migrate scale_cluster_test.go as is because it uses Update() operations, and NewClientset requires Server-Side Apply schemas that aren't generated for RayCluster. Reactors can't bypass this since validation happens before they're invoked. We would need changes in ray-operator's codegen to fix it.

schema error: no type found matching: com.github.ray-project.kuberay.ray-operator.apis.ray.v1.RayCluster

Thanks for the investigation. I am fine with leaving it as-is for now.

@justinyeh1995
Copy link
Contributor

cc @machichima for another pass of review if you still have bandwidth. Thanks.

@CheyuWu CheyuWu self-requested a review January 10, 2026 16:37
Update clientset.go and reactor_test.go to use the renamed function
AddRayClusterListFieldSelectorReactor.
@ikchifo ikchifo force-pushed the kubectl-plugin/fieldselector-reactor-tests branch from f3df8bc to e5fdf04 Compare January 10, 2026 20:37
Copy link
Contributor

@justinyeh1995 justinyeh1995 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, unit tests and manual test passed as well. Thanks!

image image

Comment on lines -112 to -114
if cluster != "" && rayCluster.Name != cluster {
continue
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why delete this line??

cc @cheyu @lorriexingfang @Jiekai for review

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah since we use field selector now

@rueian rueian merged commit 81c526d into ray-project:master Jan 12, 2026
29 checks passed
@github-project-automation github-project-automation bot moved this from can be merged to Done in @Future-Outlier's kuberay project Jan 12, 2026
@ikchifo ikchifo deleted the kubectl-plugin/fieldselector-reactor-tests branch January 12, 2026 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[kubectl-plugin][Test] Use client-go reactors to support FieldSelector filtering in fake client tests

4 participants