client

package
v2.32.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 15, 2026 License: Apache-2.0 Imports: 8 Imported by: 120

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EvictCluster added in v2.32.0

func EvictCluster(clusterPath logicalcluster.Path)

EvictCluster notifies every registered cache that clusterPath has been deleted and its cached client (and everything that client transitively pins — REST client, codec factory, JSON decoder state, OpenAPI schemas) can be released. Wire this to a LogicalCluster delete handler to bound retained memory per workspace lifetime. See https://github.com/kcp-dev/kcp/issues/4071.

Dead entries (caches whose only remaining reference was the weak entry in this registry) are pruned in-place during the iteration.

func SetCluster

func SetCluster(cfg *rest.Config, clusterPath logicalcluster.Path) *rest.Config

SetCluster modifies the config host path to include the cluster endpoint.

Note: it is the caller responsibility to make a copy of the rest config.

Types

type Cache

type Cache[R any] interface {
	ClusterOrDie(clusterPath logicalcluster.Path) R
	Cluster(clusterPath logicalcluster.Path) (R, error)
	// Evict drops the cached client for clusterPath, if any. Used to release
	// per-cluster client state (REST clients, codec factories, parsed
	// schemas) when a logical cluster is deleted. Safe to call concurrently
	// with Cluster / ClusterOrDie. No-op if the path is not cached.
	Evict(clusterPath logicalcluster.Path)
}

Cache is a client factory that caches previous results.

func NewCache

func NewCache[R any](cfg *rest.Config, client *http.Client, constructor *Constructor[R]) Cache[R]

NewCache creates a new client factory cache using the given constructor. The cache is auto-registered with the package-level EvictCluster fan-out so per-cluster entries can be released when a LogicalCluster is deleted. The registry holds the cache weakly: if all references to the returned Cache are dropped, it becomes eligible for GC and is pruned from the registry lazily.

type Constructor

type Constructor[R any] struct {
	NewForConfigAndClient func(*rest.Config, *http.Client) (R, error)
}

Constructor is a wrapper around a constructor method for the client of type R.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL