Skip to content

Commit 9ded30a

Browse files
committed
fix: only filter RayCluster events for reconciliation
ray-project#639 accidentally applied event filters for child resources Pods and Services. This change does not filter Pod or Service related events. This means Pod updates will trigger RayCluster reconciliation. closes ray-project#872
1 parent cbe1865 commit 9ded30a

3 files changed

Lines changed: 20 additions & 4 deletions

File tree

ray-operator/controllers/ray/raycluster_controller.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"k8s.io/apimachinery/pkg/runtime"
3030
"k8s.io/apimachinery/pkg/types"
3131
ctrl "sigs.k8s.io/controller-runtime"
32+
"sigs.k8s.io/controller-runtime/pkg/builder"
3233
"sigs.k8s.io/controller-runtime/pkg/client"
3334
controller "sigs.k8s.io/controller-runtime/pkg/controller"
3435
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
@@ -811,8 +812,12 @@ func (r *RayClusterReconciler) buildWorkerPod(instance rayiov1alpha1.RayCluster,
811812
// SetupWithManager builds the reconciler.
812813
func (r *RayClusterReconciler) SetupWithManager(mgr ctrl.Manager, reconcileConcurrency int) error {
813814
b := ctrl.NewControllerManagedBy(mgr).
814-
For(&rayiov1alpha1.RayCluster{}).Named("raycluster-controller").
815-
WithEventFilter(predicate.Or(predicate.GenerationChangedPredicate{}, predicate.LabelChangedPredicate{}, predicate.AnnotationChangedPredicate{})).
815+
Named("raycluster-controller").
816+
For(&rayiov1alpha1.RayCluster{}, builder.WithPredicates(predicate.Or(
817+
predicate.GenerationChangedPredicate{},
818+
predicate.LabelChangedPredicate{},
819+
predicate.AnnotationChangedPredicate{},
820+
))).
816821
Watches(&source.Kind{Type: &corev1.Event{}}, &handler.EnqueueRequestForObject{}).
817822
Owns(&corev1.Pod{}).
818823
Owns(&corev1.Service{})

ray-operator/controllers/ray/raycluster_controller_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,13 @@ var _ = Context("Inside the default namespace", func() {
157157
}
158158
})
159159

160+
It("cluster's .status.state should be updated to 'ready'", func() {
161+
Eventually(
162+
getResourceFunc(ctx, client.ObjectKey{Name: myRayCluster.Name, Namespace: "default"}, myRayCluster),
163+
time.Millisecond*500).Should(BeNil(), "My myRayCluster = %v", myRayCluster.Name)
164+
Expect(myRayCluster.Status.State).Should(Equal(rayiov1alpha1.Ready))
165+
})
166+
160167
It("should create a head pod resource", func() {
161168
var headPods corev1.PodList
162169
filterLabels := client.MatchingLabels{common.RayClusterLabelKey: myRayCluster.Name, common.RayNodeGroupLabelKey: "headgroup"}

ray-operator/controllers/ray/rayservice_controller.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"k8s.io/apimachinery/pkg/api/errors"
2222
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2323
"k8s.io/client-go/tools/record"
24+
"sigs.k8s.io/controller-runtime/pkg/builder"
2425
"sigs.k8s.io/controller-runtime/pkg/manager"
2526
"sigs.k8s.io/controller-runtime/pkg/predicate"
2627

@@ -219,8 +220,11 @@ func (r *RayServiceReconciler) Reconcile(ctx context.Context, request ctrl.Reque
219220
// SetupWithManager sets up the controller with the Manager.
220221
func (r *RayServiceReconciler) SetupWithManager(mgr ctrl.Manager) error {
221222
return ctrl.NewControllerManagedBy(mgr).
222-
For(&rayv1alpha1.RayService{}).
223-
WithEventFilter(predicate.Or(predicate.GenerationChangedPredicate{}, predicate.LabelChangedPredicate{}, predicate.AnnotationChangedPredicate{})).
223+
For(&rayv1alpha1.RayService{}, builder.WithPredicates(predicate.Or(
224+
predicate.GenerationChangedPredicate{},
225+
predicate.LabelChangedPredicate{},
226+
predicate.AnnotationChangedPredicate{},
227+
))).
224228
Owns(&rayv1alpha1.RayCluster{}).
225229
Owns(&corev1.Service{}).
226230
Owns(&networkingv1.Ingress{}).

0 commit comments

Comments
 (0)