From c5cc5e55b916ee62d48648c70356bc89da8c859b Mon Sep 17 00:00:00 2001 From: killianmuldoon Date: Wed, 12 Jan 2022 19:58:10 +0000 Subject: [PATCH] Fix to improper formatting of UnhealthyRange Signed-off-by: killianmuldoon --- .../machinehealthcheck/machinehealthcheck_controller.go | 6 ++++-- .../machinehealthcheck_controller_test.go | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/internal/controllers/machinehealthcheck/machinehealthcheck_controller.go b/internal/controllers/machinehealthcheck/machinehealthcheck_controller.go index ed9bcf5bf4ab..4ff8a80b911c 100644 --- a/internal/controllers/machinehealthcheck/machinehealthcheck_controller.go +++ b/internal/controllers/machinehealthcheck/machinehealthcheck_controller.go @@ -270,14 +270,16 @@ func (r *Reconciler) reconcile(ctx context.Context, logger logr.Logger, cluster Status: corev1.ConditionFalse, Severity: clusterv1.ConditionSeverityWarning, Reason: clusterv1.TooManyUnhealthyReason, - Message: message, + // Format message to account for percent sign. + Message: strings.Replace(message, "%", "%%", -1), }) r.recorder.Eventf( m, corev1.EventTypeWarning, EventRemediationRestricted, - message, + // Format message to account for percent sign. + strings.Replace(message, "%", "%%", -1), ) errList := []error{} for _, t := range append(healthy, unhealthy...) { diff --git a/internal/controllers/machinehealthcheck/machinehealthcheck_controller_test.go b/internal/controllers/machinehealthcheck/machinehealthcheck_controller_test.go index 78dd91188e4d..a57a572d1f45 100644 --- a/internal/controllers/machinehealthcheck/machinehealthcheck_controller_test.go +++ b/internal/controllers/machinehealthcheck/machinehealthcheck_controller_test.go @@ -20,6 +20,7 @@ import ( "errors" "fmt" "sort" + "strings" "testing" "time" @@ -570,7 +571,8 @@ func TestMachineHealthCheck_Reconcile(t *testing.T) { Status: corev1.ConditionFalse, Severity: clusterv1.ConditionSeverityWarning, Reason: clusterv1.TooManyUnhealthyReason, - Message: "Remediation is not allowed, the number of not started or unhealthy machines exceeds maxUnhealthy (total: 3, unhealthy: 2, maxUnhealthy: 40%)", + // // Format message to account for percent sign. + Message: strings.Replace("Remediation is not allowed, the number of not started or unhealthy machines exceeds maxUnhealthy (total: 3, unhealthy: 2, maxUnhealthy: 40%)", "%", "%%", -1), }, }, }))