Documentation ¶
Index ¶
- Variables
- type ClientManager
- type ClientProvider
- type FakeClientProvider
- func (f *FakeClientProvider) AddK8sClient(key types.NamespacedName, client k8s.Client) (bool, metav1.MicroTime)
- func (f *FakeClientProvider) GetK8sClient(clusterKey types.NamespacedName) (k8s.Client, metav1.MicroTime, error)
- func (f *FakeClientProvider) SetClusterError(key types.NamespacedName, err error)
- func (f *FakeClientProvider) SetK8sClient(key types.NamespacedName, client k8s.Client) metav1.MicroTime
Constants ¶
This section is empty.
Variables ¶
var NotFoundError = errors.New("cluster client does not exist")
NotFoundError indicates there is no cluster client for the given key.
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(defaultClient k8s.Client) *FakeClientProvider
NewFakeClientProvider creates a client provider suitable for tests.
If defaultClient is not nil, it will be immediately available for the "default" Cluster connection. It's possible to store additional clients for other Cluster connections as well.
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) GetK8sClient ¶
func (f *FakeClientProvider) GetK8sClient(clusterKey types.NamespacedName) (k8s.Client, metav1.MicroTime, error)
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.