-
Notifications
You must be signed in to change notification settings - Fork 601
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MT-Broker: return retriable status code based on the state to leverage retries #8366
Merged
knative-prow
merged 2 commits into
knative:main
from
pierDipi:respond-404-when-trigger-or-subscription-is-not-found
Dec 3, 2024
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,8 @@ import ( | |
"net/http" | ||
"time" | ||
|
||
apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
|
||
messagingv1 "knative.dev/eventing/pkg/apis/messaging/v1" | ||
messaginginformers "knative.dev/eventing/pkg/client/informers/externalversions/messaging/v1" | ||
"knative.dev/eventing/pkg/reconciler/broker/resources" | ||
|
@@ -178,16 +180,14 @@ func (h *Handler) ServeHTTP(writer http.ResponseWriter, request *http.Request) { | |
} | ||
|
||
trigger, err := h.getTrigger(triggerRef) | ||
if err != nil { | ||
h.logger.Info("Unable to get the Trigger", zap.Error(err), zap.Any("triggerRef", triggerRef)) | ||
writer.WriteHeader(http.StatusBadRequest) | ||
if apierrors.IsNotFound(err) { | ||
h.logger.Info("Unable to find the Trigger", zap.Error(err), zap.Any("triggerRef", triggerRef)) | ||
writer.WriteHeader(http.StatusNotFound) | ||
return | ||
} | ||
|
||
subscription, err := h.getSubscription(features, trigger) | ||
if err != nil { | ||
h.logger.Info("Unable to get the Subscription of the Trigger", zap.Error(err), zap.Any("triggerRef", triggerRef)) | ||
Comment on lines
-187
to
-189
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. moved behind authn feature flag as this is only needed for that |
||
writer.WriteHeader(http.StatusInternalServerError) | ||
h.logger.Info("Unable to get the Trigger", zap.Error(err), zap.Any("triggerRef", triggerRef)) | ||
writer.WriteHeader(http.StatusBadRequest) | ||
return | ||
} | ||
|
||
|
@@ -216,6 +216,18 @@ func (h *Handler) ServeHTTP(writer http.ResponseWriter, request *http.Request) { | |
if features.IsOIDCAuthentication() { | ||
h.logger.Debug("OIDC authentication is enabled") | ||
|
||
subscription, err := h.getSubscription(features, trigger) | ||
if apierrors.IsNotFound(err) { | ||
h.logger.Info("Unable to find the Subscription for trigger", zap.Error(err), zap.Any("triggerRef", triggerRef)) | ||
writer.WriteHeader(http.StatusNotFound) | ||
return | ||
} | ||
if err != nil { | ||
h.logger.Info("Unable to get the Subscription of the Trigger", zap.Error(err), zap.Any("triggerRef", triggerRef)) | ||
writer.WriteHeader(http.StatusInternalServerError) | ||
return | ||
} | ||
|
||
audience := FilterAudience | ||
|
||
if subscription.Status.Auth == nil || subscription.Status.Auth.ServiceAccountName == nil { | ||
|
@@ -266,6 +278,11 @@ func (h *Handler) handleDispatchToReplyRequest(ctx context.Context, trigger *eve | |
} | ||
|
||
broker, err := h.brokerLister.Brokers(brokerNamespace).Get(brokerName) | ||
if apierrors.IsNotFound(err) { | ||
h.logger.Info("Unable to get the Broker", zap.Error(err)) | ||
writer.WriteHeader(http.StatusNotFound) | ||
return | ||
} | ||
if err != nil { | ||
h.logger.Info("Unable to get the Broker", zap.Error(err)) | ||
writer.WriteHeader(http.StatusBadRequest) | ||
|
@@ -311,6 +328,11 @@ func (h *Handler) handleDispatchToDLSRequest(ctx context.Context, trigger *event | |
brokerNamespace = trigger.Namespace | ||
} | ||
broker, err := h.brokerLister.Brokers(brokerNamespace).Get(brokerName) | ||
if apierrors.IsNotFound(err) { | ||
h.logger.Info("Unable to get the Broker", zap.Error(err)) | ||
writer.WriteHeader(http.StatusNotFound) | ||
return | ||
} | ||
if err != nil { | ||
h.logger.Info("Unable to get the Broker", zap.Error(err)) | ||
writer.WriteHeader(http.StatusBadRequest) | ||
|
@@ -331,6 +353,9 @@ func (h *Handler) handleDispatchToDLSRequest(ctx context.Context, trigger *event | |
Audience: broker.Status.DeadLetterSinkAudience, | ||
} | ||
} | ||
if target == nil { | ||
return | ||
} | ||
|
||
reportArgs := &ReportArgs{ | ||
ns: trigger.Namespace, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ import ( | |
"strings" | ||
"time" | ||
|
||
apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
"k8s.io/utils/ptr" | ||
|
||
opencensusclient "github.com/cloudevents/sdk-go/observability/opencensus/v2/client" | ||
|
@@ -226,6 +227,11 @@ func (h *Handler) ServeHTTP(writer http.ResponseWriter, request *http.Request) { | |
} | ||
|
||
broker, err := h.getBroker(brokerName, brokerNamespace) | ||
if apierrors.IsNotFound(err) { | ||
h.Logger.Warn("Failed to retrieve broker", zap.Error(err)) | ||
writer.WriteHeader(http.StatusNotFound) | ||
return | ||
} | ||
if err != nil { | ||
h.Logger.Warn("Failed to retrieve broker", zap.Error(err)) | ||
writer.WriteHeader(http.StatusBadRequest) | ||
|
@@ -315,7 +321,7 @@ func (h *Handler) receive(ctx context.Context, headers http.Header, event *cloud | |
channelAddress, err := h.getChannelAddress(brokerObj) | ||
if err != nil { | ||
h.Logger.Warn("could not get channel address from broker", zap.Error(err)) | ||
return http.StatusBadRequest, kncloudevents.NoDuration | ||
return http.StatusInternalServerError, kncloudevents.NoDuration | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 |
||
} | ||
|
||
opts := []kncloudevents.SendOption{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1