cluster

package
v0.33.20 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NotFoundError = errors.New("cluster client does not exist")

NotFoundError indicates there is no cluster client for the given key.

View Source
var StaleClientError = errors.New("cluster revision is stale")

StaleClientError indicates that the Cluster object is out-of-date.

This is indicative of a bug in the caller!

If calls to ClientManager::Refresh are not made properly, StaleClientError can be returned by ClientManager::GetK8sClient. This is to prevent unintentional misuse resulting in a stale client being used while also ensuring that callers handle connection changes uniformly.

See the expected usage/flow on ClientManager.

Functions

This section is empty.

Types

type ClientManager

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

ClientManager is a convenience wrapper over ClientProvider which simplifies handling client changes.

On reconcile, the controller should:

(1) Fetch the Cluster object referenced by the type its reconciling.
(2) Call ClientManager::Refresh to determine if the client for the cluster
	has changed. If true, all state associated with the old cluster should
	be cleared.
(3) As needed, call ClientManager::GetK8sClient to get a client instance.

func NewClientManager

func NewClientManager(clientProvider ClientProvider) *ClientManager

func (*ClientManager) GetK8sClient

func (c *ClientManager) GetK8sClient(obj apis.KeyableObject, cluster *v1alpha1.Cluster) (k8s.Client, error)

GetK8sClient returns the client associated with the Cluster object.

If no client is known for the Cluster object, NotFoundError is returned. If the Cluster object's config hash in the status does not match the known client, StaleClientError is returned.

func (*ClientManager) Refresh

func (c *ClientManager) Refresh(obj apis.KeyableObject, cluster *v1alpha1.Cluster) bool

Refresh checks to see if there is an updated client for the Cluster object.

If it returns true, any state associated with this Cluster should be reset and rebuilt using a new client retrieved via a subsequent call to GetK8sClient.

type ClientProvider

type ClientProvider interface {
	// GetK8sClient returns the Kubernetes client for the cluster or an error for unknown clusters, connections
	// in a transient error state, or if the connection is of a different type (i.e. Docker Compose).
	//
	// In addition to the client, the timestamp at which the client was created is returned so callers can track
	// when the client instance has changed.
	GetK8sClient(clusterKey types.NamespacedName) (k8s.Client, metav1.MicroTime, error)
}

ClientProvider provides client instances to the ClientManager.

All clients MUST be goroutine-safe.

type FakeClientProvider

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

func NewFakeClientProvider

func NewFakeClientProvider(t testing.TB, ctrlClient ctrlclient.Client) *FakeClientProvider

NewFakeClientProvider creates a client provider suitable for tests.

func (*FakeClientProvider) AddK8sClient

func (f *FakeClientProvider) AddK8sClient(key types.NamespacedName, client k8s.Client) (bool, metav1.MicroTime)

AddK8sClient adds the client if there is currently no client/error for the cluster key.

func (*FakeClientProvider) EnsureDefaultK8sCluster added in v0.27.2

func (f *FakeClientProvider) EnsureDefaultK8sCluster(ctx context.Context) *k8s.FakeK8sClient

func (*FakeClientProvider) EnsureK8sCluster added in v0.27.2

func (f *FakeClientProvider) EnsureK8sCluster(
	ctx context.Context,
	clusterNN types.NamespacedName,
) (*k8s.FakeK8sClient, metav1.MicroTime)

func (*FakeClientProvider) EnsureK8sClusterError added in v0.27.2

func (f *FakeClientProvider) EnsureK8sClusterError(ctx context.Context, clusterNN types.NamespacedName,
	clusterErr error)

func (*FakeClientProvider) GetK8sClient

func (f *FakeClientProvider) GetK8sClient(clusterKey types.NamespacedName) (k8s.Client, metav1.MicroTime, error)

func (*FakeClientProvider) MustK8sClient added in v0.27.2

func (f *FakeClientProvider) MustK8sClient(clusterNN types.NamespacedName) *k8s.FakeK8sClient

func (*FakeClientProvider) SetClusterError

func (f *FakeClientProvider) SetClusterError(key types.NamespacedName, err error)

SetClusterError sets an error for the cluster key.

func (*FakeClientProvider) SetK8sClient

func (f *FakeClientProvider) SetK8sClient(key types.NamespacedName, client k8s.Client) metav1.MicroTime

SetK8sClient sets a client for the cluster key, overwriting any that exists.

Jump to

Keyboard shortcuts

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