apiserverk8s.io/apiserver/pkg/endpoints/discovery/aggregated Index | Files

package aggregated

import "k8s.io/apiserver/pkg/endpoints/discovery/aggregated"

Index

Variables

var (
	PeerAggregatedCacheHitsCounter = metrics.NewCounter(
		&metrics.CounterOpts{
			Name:           "peer_aggregated_cache_hits_total",
			Subsystem:      subsystem,
			Help:           "Counter of number of times discovery was served from peer-aggregated cache",
			StabilityLevel: metrics.ALPHA,
		},
	)

	PeerAggregatedCacheMissesCounter = metrics.NewCounter(
		&metrics.CounterOpts{
			Name:           "peer_aggregated_cache_misses_total",
			Subsystem:      subsystem,
			Help:           "Counter of number of times discovery was aggregated across all API servers",
			StabilityLevel: metrics.ALPHA,
		},
	)

	NoPeerDiscoveryRequestCounter = metrics.NewCounter(
		&metrics.CounterOpts{
			Name:           "nopeer_requests_total",
			Subsystem:      subsystem,
			Help:           "Counter of number of times no-peer (non peer-aggregated) discovery was requested",
			StabilityLevel: metrics.ALPHA,
		},
	)
)
var DiscoveryEndpointRestrictions = discoveryEndpointRestrictions{}

DiscoveryEndpointRestrictions allows requests to /apis to provide a Content Negotiation GVK for aggregated discovery.

Functions

func IsAggregatedDiscoveryGVK

func IsAggregatedDiscoveryGVK(gvk *schema.GroupVersionKind) bool

IsAggregatedDiscoveryGVK checks if a provided GVK is the GVK for serving aggregated discovery.

func ServeHTTPWithETag

func ServeHTTPWithETag(
	object runtime.Object,
	hash string,
	targetGV schema.GroupVersion,
	serializer runtime.NegotiatedSerializer,
	w http.ResponseWriter,
	req *http.Request,
)

Attaches Cache-Busting functionality to an endpoint

hash should be the value of calculateETag on object. If hash is empty, then the object is simply serialized without E-Tag functionality

func TestFetchFromCache

func TestFetchFromCache(serverID string, localResourceManager ResourceManager, peerDiscoveryProvider PeerDiscoveryProvider) (apidiscoveryv2.APIGroupDiscoveryList, string)

TestFetchFromCache is for testing only. It allows tests to call fetchFromCache without exporting peerAggregatedDiscoveryHandler. Returns the cached response and ETag.

func TestMergeResources

func TestMergeResources(serverID string, localGroups []apidiscoveryv2.APIGroupDiscovery, peerGroupDiscovery map[string][]apidiscoveryv2.APIGroupDiscovery) []apidiscoveryv2.APIGroupDiscovery

TestMergeResources is for testing only. It allows tests to call MergeResources without exporting peerAggregatedDiscoveryHandler.

Types

type FakeResourceManager

type FakeResourceManager interface {
	ResourceManager
	Expect() ResourceManager

	HasExpectedNumberActions() bool
	Validate() error
	WaitForActions(ctx context.Context, timeout time.Duration) error
}

func NewFakeResourceManager

func NewFakeResourceManager() FakeResourceManager

type PeerAggregatedResourceManager

type PeerAggregatedResourceManager interface {
	// InvalidateCache invalidates the peer-aggregated discovery caches
	// This should be called when peer discovery data changes.
	InvalidateCache()

	// ServeHTTP handles peer-aggregated discovery HTTP requests.
	http.Handler
}

PeerAggregatedResourceManager defines the interface for managing peer-aggregated discovery resources that combines both local and peer server resources.

func NewPeerAggregatedDiscoveryHandler

func NewPeerAggregatedDiscoveryHandler(serverID string, localDiscoveryProvider ResourceManager, peerDiscoveryProvider PeerDiscoveryProvider, path string) PeerAggregatedResourceManager

NewPeerAggregatedDiscoveryHandler creates a new handler for peer-aggregated discovery.

type PeerDiscoveryProvider

type PeerDiscoveryProvider interface {
	GetPeerResources() map[string][]apidiscoveryv2.APIGroupDiscovery
}

PeerDiscoveryProvider defines an interface to get peer resources for peer-aggregated discovery.

type ResourceManager

type ResourceManager interface {
	// Adds knowledge of the given groupversion to the discovery document
	// If it was already being tracked, updates the stored APIVersionDiscovery
	// Thread-safe
	AddGroupVersion(groupName string, value apidiscoveryv2.APIVersionDiscovery)

	// Sets a priority to be used while sorting a specific group and
	// group-version. If two versions report different priorities for
	// the group, the higher one will be used. If the group is not
	// known, the priority is ignored. The priority for this version
	// is forgotten once the group-version is forgotten
	SetGroupVersionPriority(gv metav1.GroupVersion, grouppriority, versionpriority int)

	// Removes all group versions for a given group
	// Thread-safe
	RemoveGroup(groupName string)

	// Removes a specific groupversion. If all versions of a group have been
	// removed, then the entire group is unlisted.
	// Thread-safe
	RemoveGroupVersion(gv metav1.GroupVersion)

	// Resets the manager's known list of group-versions and replaces them
	// with the given groups
	// Thread-Safe
	SetGroups([]apidiscoveryv2.APIGroupDiscovery)

	// Returns the same resource manager using a different source
	// The source is used to decide how to de-duplicate groups.
	// The group from the least-numbered source is used
	WithSource(source Source) ResourceManager

	// AddInvalidationCallback adds a callback to be called when the discovery cache is invalidated.
	AddInvalidationCallback(callback func())

	http.Handler
}

This handler serves the /apis endpoint for an aggregated list of api resources indexed by their group version.

func NewResourceManager

func NewResourceManager(path string) ResourceManager

type Source

type Source uint
const (
	AggregatorSource Source = 0
	BuiltinSource    Source = 100
	CRDSource        Source = 200
)

The GroupVersion from the lowest Source takes precedence

type WrappedHandler

type WrappedHandler struct {
	// contains filtered or unexported fields
}

func WrapAggregatedDiscoveryToHandler

func WrapAggregatedDiscoveryToHandler(handler, aggHandler, peerAggregatedHandler http.Handler) *WrappedHandler

WrapAggregatedDiscoveryToHandler wraps a handler with an option to emit the aggregated discovery by passing in the aggregated discovery type in content negotiation headers: eg: (Accept: application/json;v=v2;g=apidiscovery.k8s.io;as=APIGroupDiscoveryList)

If peerAggregatedHandler is non-nil, it will be used to serve peer-aggregated discovery requests which aggregate discovery information from peer API servers. To request a no-peer aggregation, the client must include the "profile=nopeer" parameter in the Accept header eg: (Accept: application/json;g=apidiscovery.k8s.io;v=v2;as=APIGroupDiscoveryList;profile=nopeer).

func (*WrappedHandler) GenerateWebService

func (wrapped *WrappedHandler) GenerateWebService(prefix string, returnType interface{}) *restful.WebService

func (*WrappedHandler) ServeHTTP

func (wrapped *WrappedHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request)

Source Files

etag.go fake.go handler.go metrics.go negotiation.go peer_aggregated_handler.go wrapper.go

Version
v0.36.0 (latest)
Published
Apr 22, 2026
Platform
linux/amd64
Imports
34 packages
Last checked
4 days ago

Tools for package owners.