Documentation ¶
Overview ¶
Package request contains everything around extracting info from a http request object. TODO: this package is temporary. Handlers must move into pkg/apiserver/handlers to avoid dependency cycle
Index ¶
- Variables
- func AuditIDFrom(ctx context.Context) (types.UID, bool)
- func GetAuditIDTruncated(req *http.Request) string
- func NamespaceFrom(ctx context.Context) (string, bool)
- func NamespaceValue(ctx context.Context) string
- func NewContext() context.Context
- func NewDefaultContext() context.Context
- func ReceivedTimestampFrom(ctx context.Context) (time.Time, bool)
- func UserFrom(ctx context.Context) (user.Info, bool)
- func WithAuditID(parent context.Context, auditID types.UID) context.Context
- func WithNamespace(parent context.Context, namespace string) context.Context
- func WithReceivedTimestamp(parent context.Context, receivedTimestamp time.Time) context.Context
- func WithRequestInfo(parent context.Context, info *RequestInfo) context.Context
- func WithUser(parent context.Context, user user.Info) context.Context
- func WithValue(parent context.Context, key interface{}, val interface{}) context.Context
- func WithWebhookDuration(parent context.Context) context.Context
- func WithWebhookDurationAndCustomClock(parent context.Context, c clock.Clock) context.Context
- type DurationTracker
- type LongRunningRequestCheck
- type RequestInfo
- type RequestInfoFactory
- type RequestInfoResolver
- type WebhookDuration
Constants ¶
This section is empty.
Variables ¶
var NamespaceSubResourcesForTest = sets.NewString(namespaceSubresources.List()...)
NamespaceSubResourcesForTest exports namespaceSubresources for testing in pkg/controlplane/master_test.go, so we never drift
Functions ¶
func AuditIDFrom ¶ added in v0.22.0
AuditIDFrom returns the value of the audit ID from the request context.
func GetAuditIDTruncated ¶ added in v0.22.0
GetAuditIDTruncated returns the audit ID (truncated) associated with a request. If the length of the Audit-ID value exceeds the limit, we truncate it to keep the first N (maxAuditIDLength) characters. This is intended to be used in logging only.
func NamespaceFrom ¶
NamespaceFrom returns the value of the namespace key on the ctx
func NamespaceValue ¶
NamespaceValue returns the value of the namespace key on the ctx, or the empty string if none
func NewContext ¶
NewContext instantiates a base context object for request flows.
func NewDefaultContext ¶
NewDefaultContext instantiates a base context object for request flows in the default namespace
func ReceivedTimestampFrom ¶ added in v0.20.0
ReceivedTimestampFrom returns the value of the ReceivedTimestamp key from the specified context.
func WithAuditID ¶ added in v0.22.0
WithAuditID returns a copy of the parent context into which the Audit-ID associated with the request is set.
If the specified auditID is empty, no value is set and the parent context is returned as is.
func WithNamespace ¶
WithNamespace returns a copy of parent in which the namespace value is set
func WithReceivedTimestamp ¶ added in v0.20.0
WithReceivedTimestamp returns a copy of parent context in which the ReceivedTimestamp (the time the request reached the apiserver) is set.
If the specified ReceivedTimestamp is zero, no value is set and the parent context is returned as is.
func WithRequestInfo ¶
func WithRequestInfo(parent context.Context, info *RequestInfo) context.Context
WithRequestInfo returns a copy of parent in which the request info value is set
func WithWebhookDuration ¶ added in v0.23.0
WithWebhookDuration returns a copy of parent context to which the WebhookDuration trackers are added.
Types ¶
type DurationTracker ¶ added in v0.23.0
DurationTracker is a simple interface for tracking functions duration
type LongRunningRequestCheck ¶
type LongRunningRequestCheck func(r *http.Request, requestInfo *RequestInfo) bool
LongRunningRequestCheck is a predicate which is true for long-running http requests.
type RequestInfo ¶
type RequestInfo struct { // IsResourceRequest indicates whether or not the request is for an API resource or subresource IsResourceRequest bool // Path is the URL path of the request Path string // Verb is the kube verb associated with the request for API requests, not the http verb. This includes things like list and watch. // for non-resource requests, this is the lowercase http verb Verb string APIPrefix string APIGroup string APIVersion string Namespace string // Resource is the name of the resource being requested. This is not the kind. For example: pods Resource string // Subresource is the name of the subresource being requested. This is a different resource, scoped to the parent resource, but it may have a different kind. // For instance, /pods has the resource "pods" and the kind "Pod", while /pods/foo/status has the resource "pods", the sub resource "status", and the kind "Pod" // (because status operates on pods). The binding resource for a pod though may be /pods/foo/binding, which has resource "pods", subresource "binding", and kind "Binding". Subresource string // Name is empty for some verbs, but if the request directly indicates a name (not in body content) then this field is filled in. Name string // Parts are the path parts for the request, always starting with /{resource}/{name} Parts []string }
RequestInfo holds information parsed from the http.Request
func RequestInfoFrom ¶
func RequestInfoFrom(ctx context.Context) (*RequestInfo, bool)
RequestInfoFrom returns the value of the RequestInfo key on the ctx
type RequestInfoFactory ¶
type RequestInfoFactory struct { APIPrefixes sets.String // without leading and trailing slashes GrouplessAPIPrefixes sets.String // without leading and trailing slashes }
func (*RequestInfoFactory) NewRequestInfo ¶
func (r *RequestInfoFactory) NewRequestInfo(req *http.Request) (*RequestInfo, error)
TODO write an integration test against the swagger doc to test the RequestInfo and match up behavior to responses NewRequestInfo returns the information from the http request. If error is not nil, RequestInfo holds the information as best it is known before the failure It handles both resource and non-resource requests and fills in all the pertinent information for each. Valid Inputs: Resource paths /apis/{api-group}/{version}/namespaces /api/{version}/namespaces /api/{version}/namespaces/{namespace} /api/{version}/namespaces/{namespace}/{resource} /api/{version}/namespaces/{namespace}/{resource}/{resourceName} /api/{version}/{resource} /api/{version}/{resource}/{resourceName}
Special verbs without subresources: /api/{version}/proxy/{resource}/{resourceName} /api/{version}/proxy/namespaces/{namespace}/{resource}/{resourceName}
Special verbs with subresources: /api/{version}/watch/{resource} /api/{version}/watch/namespaces/{namespace}/{resource}
NonResource paths /apis/{api-group}/{version} /apis/{api-group} /apis /api/{version} /api /healthz /
type RequestInfoResolver ¶
type RequestInfoResolver interface {
NewRequestInfo(req *http.Request) (*RequestInfo, error)
}
type WebhookDuration ¶ added in v0.23.0
type WebhookDuration struct { AdmitTracker DurationTracker ValidateTracker DurationTracker }
WebhookDuration stores trackers used to measure webhook request durations. Since admit webhooks are done sequentially duration is aggregated using sum function. Validate webhooks are done in parallel so max function is used.
func WebhookDurationFrom ¶ added in v0.23.0
func WebhookDurationFrom(ctx context.Context) (*WebhookDuration, bool)
WebhookDurationFrom returns the value of the WebhookDuration key from the specified context.