From 31f171af73568069550d8facfbfaa30231ed3448 Mon Sep 17 00:00:00 2001 From: Aaron Liang Date: Mon, 2 Dec 2024 11:08:59 -0800 Subject: [PATCH] Add kubernetes event to inform user of upgrade strategy --- 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..afd02d9d50 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("Zero Downtime Environmental Variable is set to `%s`, zero downtime upgrade is set to `%t`", strings.ToLower(zeroDowntimeEnvVar), enableZeroDowntime) } if rayServiceSpecUpgradeStrategy != nil { enableZeroDowntime = *rayServiceSpecUpgradeStrategy == rayv1.NewCluster + strategyMessage = fmt.Sprintf("Upgrade Strategy is set to `%s`, zero downtime upgrade is set to `%t`", *rayServiceSpecUpgradeStrategy, enableZeroDowntime) } 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 44b234bd80..df3138d59d 100644 --- a/ray-operator/controllers/ray/rayservice_controller_unit_test.go +++ b/ray-operator/controllers/ray/rayservice_controller_unit_test.go @@ -882,8 +882,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 != "" {