clientmap

package
v1.98.6 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2024 License: Apache-2.0 Imports: 18 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// LookupHost is an alias to net.LookupHost which allows it to be mocked for testing.
	LookupHost = net.LookupHost
)

net aliases

View Source
var MaxRefreshInterval = 5 * time.Second

MaxRefreshInterval is the maximum rate at which the version and hash of a single ClientSet are checked, to decide whether the ClientSet should be refreshed. Also, the GenericClientMap waits at least MaxRefreshInterval after creating a new ClientSet before checking if it should be refreshed.

View Source
var (
	// NewClientFromSecretObject is an alias to kubernetes.NewClientFromSecretObject which allows it to be mocked for testing.
	NewClientFromSecretObject = kubernetes.NewClientFromSecretObject
)

github.com/gardener/gardener/pkg/client/kubernetes aliases

View Source
var (
	// ProjectForNamespaceFromReader is an alias to gardenerutils.ProjectForNamespaceFromReader which allows it to be mocked for testing.
	ProjectForNamespaceFromReader = gardenerutils.ProjectForNamespaceFromReader
)

github.com/gardener/gardener/pkg/utils/gardener aliases

Functions

This section is empty.

Types

type ClientMap

type ClientMap interface {
	Invalidate
	// GetClient returns the corresponding ClientSet for the given key in the ClientMap or creates a new ClientSet for
	// it if the map does not contain a corresponding ClientSet. If the ClientMap was started before by a call to Start,
	// newly created ClientSets will be started automatically using the stop channel provided to Start.
	GetClient(ctx context.Context, key ClientSetKey) (kubernetes.Interface, error)

	// Start starts the ClientMap, i.e. starts all ClientSets already contained in the map and saves the stop channel
	// for starting new ClientSets, when they are created.
	Start(ctx context.Context) error
}

A ClientMap is a collection of kubernetes ClientSets, which can be used to dynamically create and lookup different ClientSets during runtime. ClientSets are identified by a ClientSetKey, which can have different forms, as there are different kinds of ClientMaps (for example one for Seed clients and one for Shoot clients). Implementations will provide suitable mechanisms to create a ClientSet for a given key and should come with some easy ways of constructing ClientSetKeys that their callers can use to lookup ClientSets in the map.

func NewGardenClientMap added in v1.88.0

func NewGardenClientMap(log logr.Logger, factory *GardenClientSetFactory) ClientMap

NewGardenClientMap creates a new gardenClientMap with the given factory.

func NewShootClientMap added in v1.88.0

func NewShootClientMap(log logr.Logger, factory *ShootClientSetFactory) ClientMap

NewShootClientMap creates a new shootClientMap with the given factory.

type ClientSetFactory

type ClientSetFactory interface {
	// NewClientSet constructs a new ClientSet for the given key. It returns the clientset as well as its hash.
	NewClientSet(ctx context.Context, key ClientSetKey) (kubernetes.Interface, string, error)
	// CalculateClientSetHash calculates a hash for the configuration that is used to construct a ClientSet
	// (e.g. kubeconfig secret) to detect if it has changed mid-air and the ClientSet should be refreshed.
	CalculateClientSetHash(ctx context.Context, key ClientSetKey) (string, error)
}

A ClientSetFactory can be used by ClientMaps to provide the individual mechanism for constructing new ClientSets for a given ClientSetKey

type ClientSetKey

type ClientSetKey interface {
	// Key is the string representation of the ClientSetKey.
	Key() string
}

A ClientSetKey is used to identify a ClientSet within a ClientMap. There can be different implementations for ClientSetKey as there are different kinds of ClientSets (e.g. for Shoot and Seed clusters) and therefore also different means of identifying the cluster to which a ClientSet belongs.

type GardenClientSetFactory added in v1.88.0

type GardenClientSetFactory struct {
	// RuntimeClient is the runtime cluster client.
	RuntimeClient client.Client
	// ClientConnectionConfiguration is the configuration that will be used by created ClientSets.
	ClientConnectionConfig componentbaseconfig.ClientConnectionConfiguration
	// GardenNamespace is the namespace the virtual gardens run in. Defaults to `garden` if not set.
	GardenNamespace string
	// contains filtered or unexported fields
}

GardenClientSetFactory is a ClientSetFactory that can produce new ClientSets to virtual gardens.

func (*GardenClientSetFactory) CalculateClientSetHash added in v1.88.0

func (f *GardenClientSetFactory) CalculateClientSetHash(ctx context.Context, k ClientSetKey) (string, error)

CalculateClientSetHash calculates a SHA256 hash of the kubeconfig in the 'gardener' secret in the Garden's Garden namespace.

func (*GardenClientSetFactory) InvalidateClient added in v1.88.0

func (f *GardenClientSetFactory) InvalidateClient(k ClientSetKey) error

InvalidateClient invalidates information cached for the given ClientSetKey in the factory.

func (*GardenClientSetFactory) NewClientSet added in v1.88.0

NewClientSet creates a new ClientSet for a Garden cluster.

type GardenClientSetKey added in v1.88.0

type GardenClientSetKey struct {
	Name string
}

GardenClientSetKey is a ClientSetKey for a Garden cluster.

func (GardenClientSetKey) Key added in v1.88.0

func (k GardenClientSetKey) Key() string

Key returns the string representation of the ClientSetKey.

type GenericClientMap added in v1.88.0

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

GenericClientMap is a generic implementation of clientmap.ClientMap, which can be used by specific ClientMap implementations to reuse the core logic for storing, requesting, invalidating and starting ClientSets. Specific implementations only need to provide a ClientSetFactory that can produce new ClientSets for the respective keys if a corresponding entry is not found in the GenericClientMap.

func NewGenericClientMap added in v1.88.0

func NewGenericClientMap(factory ClientSetFactory, logger logr.Logger, clock clock.Clock) *GenericClientMap

NewGenericClientMap creates a new GenericClientMap with the given factory and logger.

func (*GenericClientMap) GetClient added in v1.88.0

GetClient requests a ClientSet for a cluster identified by the given key. If the ClientSet was already created before, it returns the one saved in the map, otherwise it creates a new ClientSet by using the provided ClientSetFactory. New ClientSets are immediately started if the ClientMap has already been started before. Also GetClient will regularly rediscover the server version of the targeted cluster and check if the config hash has changed and recreate the ClientSet if a config hash change is detected.

func (*GenericClientMap) InvalidateClient added in v1.88.0

func (cm *GenericClientMap) InvalidateClient(key ClientSetKey) error

InvalidateClient removes the ClientSet identified by the given key from the ClientMap after stopping its cache.

func (*GenericClientMap) Start added in v1.88.0

func (cm *GenericClientMap) Start(ctx context.Context) error

Start starts the caches of all contained ClientSets and saves the stopCh to start the caches of ClientSets, that will be created afterwards.

type Invalidate added in v1.15.0

type Invalidate interface {
	// InvalidateClient removes cached client information identified by the given `ClientSetKey`.
	InvalidateClient(key ClientSetKey) error
}

Invalidate is an interface used to invalidate client specific information.

type ShootClientSetFactory added in v1.88.0

type ShootClientSetFactory struct {
	// GardenClient is the garden cluster client.
	GardenClient client.Client
	// SeedClient is the seed cluster client.
	SeedClient client.Client
	// ClientConnectionConfiguration is the configuration that will be used by created ClientSets.
	ClientConnectionConfig componentbaseconfig.ClientConnectionConfiguration
	// contains filtered or unexported fields
}

ShootClientSetFactory is a ClientSetFactory that can produce new ClientSets to Shoot clusters.

func (*ShootClientSetFactory) CalculateClientSetHash added in v1.88.0

func (f *ShootClientSetFactory) CalculateClientSetHash(ctx context.Context, k ClientSetKey) (string, error)

CalculateClientSetHash calculates a SHA256 hash of the kubeconfig in the 'gardener' secret in the Shoot's Seed namespace.

func (*ShootClientSetFactory) InvalidateClient added in v1.88.0

func (f *ShootClientSetFactory) InvalidateClient(k ClientSetKey) error

InvalidateClient invalidates information cached for the given ClientSetKey in the factory.

func (*ShootClientSetFactory) NewClientSet added in v1.88.0

NewClientSet creates a new ClientSet for a Shoot cluster.

type ShootClientSetKey added in v1.88.0

type ShootClientSetKey struct {
	Namespace, Name string
}

ShootClientSetKey is a ClientSetKey for a Shoot cluster.

func (ShootClientSetKey) Key added in v1.88.0

func (k ShootClientSetKey) Key() string

Key returns the string representation of the ClientSetKey.

Directories

Path Synopsis
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.

Jump to

Keyboard shortcuts

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