Skip to content

Commit

Permalink
fix: expose Cloudflare token errors in GatewayClass condition
Browse files Browse the repository at this point in the history
Signed-off-by: Tom Plant <[email protected]>
  • Loading branch information
pl4nty committed Oct 13, 2024
1 parent 1ed2ab4 commit 8a96cba
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions internal/controller/gatewayclass_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package controller

import (
"context"
"fmt"
"time"

apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 8a96cba

Please sign in to comment.