From 8a96cbafe03fb67482be1109249700e17d69960c Mon Sep 17 00:00:00 2001 From: Tom Plant Date: Sun, 13 Oct 2024 03:00:22 +0000 Subject: [PATCH] fix: expose Cloudflare token errors in GatewayClass condition Signed-off-by: Tom Plant --- internal/controller/gatewayclass_controller.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/internal/controller/gatewayclass_controller.go b/internal/controller/gatewayclass_controller.go index a500a743..8b8347bd 100644 --- a/internal/controller/gatewayclass_controller.go +++ b/internal/controller/gatewayclass_controller.go @@ -2,6 +2,7 @@ package controller import ( "context" + "fmt" "time" apierrors "k8s.io/apimachinery/pkg/api/errors" @@ -56,22 +57,28 @@ func (r *GatewayClassReconciler) Reconcile(ctx context.Context, req ctrl.Request } // validate parameters - var ok bool + msg := "" _, api, err := InitCloudflareApi(ctx, r.Client, gatewayClass.Name) if err == nil { token, err := api.User.Tokens.Verify(ctx) if err == nil { - ok = token.Status == "active" + if token.Status != "active" { + msg = fmt.Sprintf("Token status is %s, is not active. Please check the Cloudflare dashboard", token.Status) + } + } else { + msg = err.Error() + " Ensure ACCOUNT_ID and TOKEN are valid" } + } else { + msg = err.Error() + " Ensure ACCOUNT_ID and TOKEN are set" } var condition metav1.Condition - if !ok { + if msg != "" { condition = metav1.Condition{ Type: string(gatewayv1.GatewayClassConditionStatusAccepted), Status: metav1.ConditionFalse, Reason: string(gatewayv1.GatewayClassReasonInvalidParameters), - Message: "Unable to initialize Cloudflare API from secret in GatewayClass parameterRef. Ensure ACCOUNT_ID and TOKEN are set", + Message: "Unable to initialize Cloudflare API. " + msg, ObservedGeneration: gatewayClass.Generation, } } else {