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

Move matching labels to association.go #2734

Conversation

owenowenisme
Copy link
Contributor

@owenowenisme owenowenisme commented Jan 13, 2025

Why are these changes needed?

#2733

Related issue number

Closes #2733

Checks

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

@owenowenisme owenowenisme force-pushed the move-matchingLabels-to-association.go branch from f89cc2d to 9e9031f Compare January 13, 2025 01:01
@owenowenisme
Copy link
Contributor Author

@rueian please take a look🙏🙏🙏

@rueian
Copy link
Contributor

rueian commented Jan 13, 2025

Hi @owenowenisme,

I noticed that there are RayClusterHeadPodsAssociationOptions and RayClusterWorkerPodsAssociationOptions in the association.go. Could you reuse them?

@@ -100,6 +100,16 @@ func RayClusterWorkerPodsAssociationOptions(instance *rayv1.RayCluster) Associat
}
}

func RayClusterRedisPodsAssociationOptions(instance *rayv1.RayCluster) AssociationOptions {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add a test for this new method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do!

utils.RayNodeTypeLabelKey: "head",
}
if err := r.List(ctx, &rayHeadSvc, client.InNamespace(instance.Namespace), filterLabels); err != nil {
filterLabels := common.RayClusterAllPodsAssociationOptions(instance).ToListOptions()
Copy link
Member

Choose a reason for hiding this comment

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

Use RayClusterHeadServiceListOptions instead?

@@ -544,9 +544,9 @@ func (r *RayClusterReconciler) reconcileIngressKubernetes(ctx context.Context, i
func (r *RayClusterReconciler) reconcileHeadService(ctx context.Context, instance *rayv1.RayCluster) error {
logger := ctrl.LoggerFrom(ctx)
services := corev1.ServiceList{}
filterLabels := client.MatchingLabels{utils.RayClusterLabelKey: instance.Name, utils.RayNodeTypeLabelKey: string(rayv1.HeadNode)}
filterLabels := common.RayClusterHeadPodsAssociationOptions(instance).ToListOptions()
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
filterLabels := common.RayClusterHeadPodsAssociationOptions(instance).ToListOptions()
filterLabels := common.RayClusterHeadServiceListOptions(instance).ToListOptions()

@@ -286,9 +286,9 @@ func (r *RayClusterReconciler) rayClusterReconcile(ctx context.Context, instance
}

// We can start the Redis cleanup process now because the head Pod has been terminated.
filterLabels := client.MatchingLabels{utils.RayClusterLabelKey: instance.Name, utils.RayNodeTypeLabelKey: string(rayv1.RedisCleanupNode)}
filterLabels := common.RayClusterRedisPodsAssociationOptions(instance).ToListOptions()
Copy link
Member

Choose a reason for hiding this comment

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

  1. It is used to associate a K8s Job instead of Pod.
  2. It is not a Redis Pod.

Please rename to RayClusterRedisCleanupJobAssociationOptions

@@ -481,8 +481,8 @@ func (r *RayClusterReconciler) reconcileIngress(ctx context.Context, instance *r
func (r *RayClusterReconciler) reconcileRouteOpenShift(ctx context.Context, instance *rayv1.RayCluster) error {
logger := ctrl.LoggerFrom(ctx)
headRoutes := routev1.RouteList{}
filterLabels := client.MatchingLabels{utils.RayClusterLabelKey: instance.Name}
if err := r.List(ctx, &headRoutes, client.InNamespace(instance.Namespace), filterLabels); err != nil {
filterLabels := common.RayClusterAllPodsAssociationOptions(instance).ToListOptions()
Copy link
Member

Choose a reason for hiding this comment

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

It's misleading to use RayClusterAllPodsAssociationOptions to associate K8s ingress / route. Please create a new function RayClusterNetworkResourcesOptions for both ingress and route instead.

@owenowenisme owenowenisme force-pushed the move-matchingLabels-to-association.go branch from 4fa5f6a to 1c1c6b7 Compare January 15, 2025 03:09
@@ -194,3 +194,12 @@ func GetRayClusterHeadPod(ctx context.Context, reader client.Reader, instance *r
}
return &runtimePods.Items[0], nil
}

func RayClusterNetworkResourcesOptions(instance *rayv1.RayCluster) AssociationOptions {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since the new function is created, please add a test for it.

@owenowenisme owenowenisme force-pushed the move-matchingLabels-to-association.go branch 2 times, most recently from 72c369f to e570111 Compare January 15, 2025 18:12
@@ -292,3 +293,77 @@ func TestGetRayClusterHeadPod(t *testing.T) {
assert.Nil(t, err)
assert.Equal(t, ret, headPod)
}

func TestRayClusterRedisPodsAssociationOptions(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
func TestRayClusterRedisPodsAssociationOptions(t *testing.T) {
func TestRayClusterRedisCleanupJobAssociationOptions(t *testing.T) {


_ = &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "redis-pod",
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Name: "redis-pod",
Name: "redis-cleanup",

@owenowenisme
Copy link
Contributor Author

@rueian @kevin85421
Thanks for the detailed review 🙏.

@rueian
Copy link
Contributor

rueian commented Jan 17, 2025

Just a note: these failing tests seem unrelated to this PR
image

@kevin85421
Copy link
Member

rerun the test

@kevin85421
Copy link
Member

CI still fails. @owenowenisme could you rebase with the master branch?

@owenowenisme owenowenisme force-pushed the move-matchingLabels-to-association.go branch from b36aea0 to e8ddab1 Compare January 17, 2025 23:22
@owenowenisme
Copy link
Contributor Author

@kevin85421 Only unrelated test failed is remaining.

@@ -573,8 +572,8 @@ func (r *RayClusterReconciler) reconcileRouteOpenShift(ctx context.Context, inst
func (r *RayClusterReconciler) reconcileIngressKubernetes(ctx context.Context, instance *rayv1.RayCluster) error {
logger := ctrl.LoggerFrom(ctx)
headIngresses := networkingv1.IngressList{}
filterLabels := client.MatchingLabels{utils.RayClusterLabelKey: instance.Name}
if err := r.List(ctx, &headIngresses, client.InNamespace(instance.Namespace), filterLabels); err != nil {
filterLabels := common.RayClusterAllPodsAssociationOptions(instance).ToListOptions()
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
filterLabels := common.RayClusterAllPodsAssociationOptions(instance).ToListOptions()
filterLabels := common.RayClusterNetworkResourcesOptions(instance).ToListOptions()

utils.RayNodeTypeLabelKey: string(rayv1.RedisCleanupNode),
}),
}
for k, v := range expected {
Copy link
Member

Choose a reason for hiding this comment

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

removed

@owenowenisme
Copy link
Contributor Author

@kevin85421
Sorry for such careless mistakes, I'll pay attention more in the future.

@kevin85421 kevin85421 merged commit 5fde3c6 into ray-project:master Jan 18, 2025
23 of 24 checks passed
@owenowenisme owenowenisme deleted the move-matchingLabels-to-association.go branch January 18, 2025 02:44
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.

[Refactor] Move MatchingLabels to association.go [2/N]
3 participants