Skip to content

Commit a8ff77d

Browse files
authored
fix(diag): get rid of wrongly logged errors (#5846)
1 parent 3e4d430 commit a8ff77d

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ Adding a new version? You'll need three changes:
9393
server. This endpoint outputs the original Kong `/config` endpoint error for
9494
failed configuration pushes in case error parsing fails. Attempt to log the
9595
`message` field of errors that KIC cannot fully parse.
96-
[#5773](https://github.com/Kong/kubernetes-ingress-controller/issues/5773)
96+
[#5773](https://github.com/Kong/kubernetes-ingress-controller/issues/5773), [#5846](https://github.com/Kong/kubernetes-ingress-controller/pull/5846)
9797
- Add constraint to limit items in `Credentials` and `ConsumerGroups` in
9898
`KongConsumer`s to be unique in validating admission webhooks.
9999
[#5787](https://github.com/Kong/kubernetes-ingress-controller/pull/5787)

internal/dataplane/kong_client.go

+17-8
Original file line numberDiff line numberDiff line change
@@ -577,21 +577,30 @@ func (c *KongClient) sendToClient(
577577
c.updateStrategyResolver,
578578
c.configChangeDetector,
579579
)
580-
581-
c.recordResourceFailureEvents(err.ResourceFailures, KongConfigurationApplyFailedEventReason)
582580
// Only record events on applying configuration to Kong gateway here.
581+
// Nil error is expected to be passed to indicate success.
583582
if !client.IsKonnect() {
584583
c.recordApplyConfigurationEvents(err, client.BaseRootURL())
585584
}
586-
sendDiagnostic(err.Err != nil, err.RawBody)
585+
if err != nil {
586+
var updateErr sendconfig.UpdateError
587+
if errors.As(err, &updateErr) {
588+
c.recordResourceFailureEvents(updateErr.ResourceFailures, KongConfigurationApplyFailedEventReason)
587589

588-
if err.Err != nil {
589-
if expired, ok := timedCtx.Deadline(); ok && time.Now().After(expired) {
590-
logger.Error(nil, "Exceeded Kong API timeout, consider increasing --proxy-timeout-seconds")
590+
sendDiagnostic(updateErr.Err != nil, updateErr.RawBody)
591+
592+
if updateErr.Err != nil {
593+
if err := ctx.Err(); err != nil {
594+
logger.Error(err, "Exceeded Kong API timeout, consider increasing --proxy-timeout-seconds")
595+
}
596+
return "", fmt.Errorf("performing update for %s failed: %w", client.BaseRootURL(), updateErr)
597+
}
598+
} else {
599+
// It should never happen.
600+
return "", fmt.Errorf("performing update for %s failed with unexpected type of error: %w", client.BaseRootURL(), err)
591601
}
592-
return "", fmt.Errorf("performing update for %s failed: %w", client.AdminAPIClient().BaseRootURL(), err)
593602
}
594-
603+
sendDiagnostic(false, nil) // No error occurred.
595604
// update the lastConfigSHA with the new updated checksum
596605
client.SetLastConfigSHA(newConfigSHA)
597606

internal/dataplane/sendconfig/sendconfig.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func PerformUpdate(
6767
promMetrics *metrics.CtrlFuncMetrics,
6868
updateStrategyResolver UpdateStrategyResolver,
6969
configChangeDetector ConfigurationChangeDetector,
70-
) ([]byte, UpdateError) {
70+
) ([]byte, error) {
7171
oldSHA := client.LastConfigSHA()
7272
newSHA, err := deckgen.GenerateSHA(targetContent)
7373
if err != nil {
@@ -86,7 +86,7 @@ func PerformUpdate(
8686
} else {
8787
logger.V(util.DebugLevel).Info("No configuration change, skipping sync to Kong")
8888
}
89-
return oldSHA, UpdateError{}
89+
return oldSHA, nil
9090
}
9191
}
9292

@@ -119,7 +119,7 @@ func PerformUpdate(
119119
logger.V(util.InfoLevel).Info("Successfully synced configuration to Kong")
120120
}
121121

122-
return newSHA, UpdateError{}
122+
return newSHA, nil
123123
}
124124

125125
// -----------------------------------------------------------------------------

0 commit comments

Comments
 (0)