mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 02:41:25 +00:00
Merge pull request #99125 from tkashem/apf-response-header-fix
apf: set response headers for rejected requests
This commit is contained in:
commit
7ab447fd4d
@ -122,12 +122,7 @@ func WithPriorityAndFairness(
|
||||
served = true
|
||||
innerCtx := context.WithValue(ctx, priorityAndFairnessKey, classification)
|
||||
innerReq := r.Clone(innerCtx)
|
||||
|
||||
// We intentionally set the UID of the flow-schema and priority-level instead of name. This is so that
|
||||
// the names that cluster-admins choose for categorization and priority levels are not exposed, also
|
||||
// the names might make it obvious to the users that they are rejected due to classification with low priority.
|
||||
w.Header().Set(flowcontrol.ResponseHeaderMatchedPriorityLevelConfigurationUID, string(classification.PriorityLevelUID))
|
||||
w.Header().Set(flowcontrol.ResponseHeaderMatchedFlowSchemaUID, string(classification.FlowSchemaUID))
|
||||
setResponseHeaders(classification, w)
|
||||
|
||||
handler.ServeHTTP(w, innerReq)
|
||||
}
|
||||
@ -140,6 +135,8 @@ func WithPriorityAndFairness(
|
||||
}
|
||||
}, execute)
|
||||
if !served {
|
||||
setResponseHeaders(classification, w)
|
||||
|
||||
if isMutatingRequest {
|
||||
epmetrics.DroppedRequests.WithContext(ctx).WithLabelValues(epmetrics.MutatingKind).Inc()
|
||||
} else {
|
||||
@ -158,3 +155,15 @@ func StartPriorityAndFairnessWatermarkMaintenance(stopCh <-chan struct{}) {
|
||||
startWatermarkMaintenance(watermark, stopCh)
|
||||
startWatermarkMaintenance(waitingMark, stopCh)
|
||||
}
|
||||
|
||||
func setResponseHeaders(classification *PriorityAndFairnessClassification, w http.ResponseWriter) {
|
||||
if classification == nil {
|
||||
return
|
||||
}
|
||||
|
||||
// We intentionally set the UID of the flow-schema and priority-level instead of name. This is so that
|
||||
// the names that cluster-admins choose for categorization and priority levels are not exposed, also
|
||||
// the names might make it obvious to the users that they are rejected due to classification with low priority.
|
||||
w.Header().Set(flowcontrol.ResponseHeaderMatchedPriorityLevelConfigurationUID, string(classification.PriorityLevelUID))
|
||||
w.Header().Set(flowcontrol.ResponseHeaderMatchedFlowSchemaUID, string(classification.FlowSchemaUID))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user