From c8f826bc74361697599b95a80af2ca86711c5b10 Mon Sep 17 00:00:00 2001 From: Chia-Yi Liang Date: Tue, 17 Dec 2024 18:52:21 -0800 Subject: [PATCH] Add kubernetes event to inform user of upgrade strategy (#2592) --- ray-operator/controllers/ray/rayservice_controller.go | 6 ++++++ .../controllers/ray/rayservice_controller_unit_test.go | 5 +++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/ray-operator/controllers/ray/rayservice_controller.go b/ray-operator/controllers/ray/rayservice_controller.go index 6c211d196d..52aad6c304 100644 --- a/ray-operator/controllers/ray/rayservice_controller.go +++ b/ray-operator/controllers/ray/rayservice_controller.go @@ -435,14 +435,20 @@ func (r *RayServiceReconciler) reconcileRayCluster(ctx context.Context, rayServi // If no fields are set, zero downtime upgrade by default is enabled. // Spec.UpgradeStrategy takes precedence over ENABLE_ZERO_DOWNTIME. enableZeroDowntime := true + strategyMessage := "" if zeroDowntimeEnvVar != "" { enableZeroDowntime = strings.ToLower(zeroDowntimeEnvVar) != "false" + strategyMessage = fmt.Sprintf("ENABLE_ZERO_DOWNTIME environmental variable is set to %q", strings.ToLower(zeroDowntimeEnvVar)) } if rayServiceSpecUpgradeStrategy != nil { enableZeroDowntime = *rayServiceSpecUpgradeStrategy == rayv1.NewCluster + strategyMessage = fmt.Sprintf("Upgrade Strategy is set to %q", *rayServiceSpecUpgradeStrategy) } if enableZeroDowntime || !enableZeroDowntime && activeRayCluster == nil { + if enableZeroDowntime && activeRayCluster != nil { + r.Recorder.Event(rayServiceInstance, "Normal", "UpgradeStrategy", strategyMessage) + } // Add a pending cluster name. In the next reconcile loop, shouldPrepareNewRayCluster will return DoNothing and we will // actually create the pending RayCluster instance. r.markRestartAndAddPendingClusterName(ctx, rayServiceInstance) diff --git a/ray-operator/controllers/ray/rayservice_controller_unit_test.go b/ray-operator/controllers/ray/rayservice_controller_unit_test.go index af7e7c4a64..7fd2ccf297 100644 --- a/ray-operator/controllers/ray/rayservice_controller_unit_test.go +++ b/ray-operator/controllers/ray/rayservice_controller_unit_test.go @@ -883,8 +883,9 @@ func TestReconcileRayCluster(t *testing.T) { } fakeClient := clientFake.NewClientBuilder().WithScheme(newScheme).WithRuntimeObjects(runtimeObjects...).Build() r := RayServiceReconciler{ - Client: fakeClient, - Scheme: newScheme, + Client: fakeClient, + Scheme: newScheme, + Recorder: record.NewFakeRecorder(1), } service := rayService.DeepCopy() if tc.rayServiceUpgradeStrategy != "" {