clustersmngr

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2022 License: MPL-2.0 Imports: 23 Imported by: 14

Documentation

Index

Constants

View Source
const (
	// Clusters Client context key
	ClustersClientCtxKey key = iota
)

Variables

View Source
var (
	Registry = prometheus.NewRegistry()
)

Functions

This section is empty.

Types

type Client

type Client interface {
	// Get retrieves an obj for the given object key.
	Get(ctx context.Context, cluster string, key client.ObjectKey, obj client.Object) error
	// List retrieves list of objects for a given namespace and list options.
	List(ctx context.Context, cluster string, list client.ObjectList, opts ...client.ListOption) error

	// Create saves the object obj.
	Create(ctx context.Context, cluster string, obj client.Object, opts ...client.CreateOption) error
	// Delete deletes the given obj
	Delete(ctx context.Context, cluster string, obj client.Object, opts ...client.DeleteOption) error
	// Update updates the given obj.
	Update(ctx context.Context, cluster string, obj client.Object, opts ...client.UpdateOption) error
	// Patch patches the given obj
	Patch(ctx context.Context, cluster string, obj client.Object, patch client.Patch, opts ...client.PatchOption) error

	// ClusteredList loops through the list of clusters and namespaces the client has access and
	// queries the list of objects for each of them in parallel.
	// This method supports pagination with a caveat, the client.Limit passed will be multiplied
	// by the number of clusters and namespaces, we decided to do this to avoid the complex coordination
	// that would be required to make sure the number of items returned match the limit passed.
	ClusteredList(ctx context.Context, clist ClusteredObjectList, namespaced bool, opts ...client.ListOption) error

	// ClientsPool returns the clients pool.
	ClientsPool() ClientsPool

	// Scoped returns a client that is scoped to a single cluster
	Scoped(cluster string) (client.Client, error)
}

Client is wrapper to controller-runtime/client adding multi clusters context. it contains the list of clusters and namespaces the user has access to allowing cross cluster/namespace querying

func NewClient

func NewClient(clientsPool ClientsPool, namespaces map[string][]v1.Namespace) Client

type ClientError added in v0.9.1

type ClientError struct {
	ClusterName string
	Err         error
}

ClientError is an error returned by the GetImpersonatedClient function which contains the details of the cluster that caused the error.

func (*ClientError) Error added in v0.9.1

func (ce *ClientError) Error() string

Error() returns the error message of the underlying error.

type ClientsPool

type ClientsPool interface {
	Add(c client.Client, cluster cluster.Cluster) error
	Clients() map[string]client.Client
	Client(cluster string) (client.Client, error)
}

ClientsPool stores all clients to the leaf clusters

func NewClustersClientsPool

func NewClustersClientsPool() ClientsPool

NewClustersClientsPool initializes a new ClientsPool

type ClusterFetcher

type ClusterFetcher interface {
	Fetch(ctx context.Context) ([]cluster.Cluster, error)
}

ClusterFetcher fetches all leaf clusters

type ClusterListUpdate added in v0.9.5

type ClusterListUpdate struct {
	Added   []cluster.Cluster
	Removed []cluster.Cluster
}

ClusterListUpdate records the changes to the cluster state managed by the factory.

type ClusterNotFoundError

type ClusterNotFoundError struct {
	Cluster string
}

ClusterNotFoundError cluster client can be found in the pool

func (ClusterNotFoundError) Error

func (e ClusterNotFoundError) Error() string

type ClusteredList

type ClusteredList struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func (*ClusteredList) AddObjectList added in v0.8.0

func (cl *ClusteredList) AddObjectList(cluster string, list client.ObjectList)

func (*ClusteredList) GetContinue added in v0.8.0

func (cl *ClusteredList) GetContinue() string

func (*ClusteredList) Lists

func (cl *ClusteredList) Lists() map[string][]client.ObjectList

func (*ClusteredList) NewList added in v0.8.0

func (cl *ClusteredList) NewList() client.ObjectList

func (*ClusteredList) SetContinue added in v0.8.0

func (cl *ClusteredList) SetContinue(continueToken string)

type ClusteredListError added in v0.8.1

type ClusteredListError struct {
	Errors []ListError
}

func (*ClusteredListError) Add added in v0.8.1

func (cle *ClusteredListError) Add(err ListError)

func (ClusteredListError) Error added in v0.8.1

func (cle ClusteredListError) Error() string

type ClusteredObjectList

type ClusteredObjectList interface {
	// NewList is a factory that returns a new concrete list being queried
	NewList() client.ObjectList
	// AddObjectList adds a result list of objects to the lists map
	AddObjectList(cluster string, list client.ObjectList)
	// Lists returns the map of lists from all clusters
	Lists() map[string][]client.ObjectList
	// GetContinue returns the continue token used for pagination
	GetContinue() string
	// SetContinue sets the continue token used for pagination
	SetContinue(continueToken string)
}

ClusteredObjectList represents the returns of the lists of all clusters and namespaces user could query

func NewClusteredList

func NewClusteredList(listFactory func() client.ObjectList) ClusteredObjectList

type Clusters added in v0.8.0

type Clusters struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*Clusters) Get added in v0.8.0

func (c *Clusters) Get() []cluster.Cluster

func (*Clusters) Hash added in v0.8.1

func (c *Clusters) Hash() string

func (*Clusters) Set added in v0.8.0

func (c *Clusters) Set(newClusters []cluster.Cluster) (added, removed []cluster.Cluster)

Set updates Clusters.clusters, and returns the newly added clusters and removed clusters.

type ClustersManager added in v0.9.5

type ClustersManager interface {
	// GetImpersonatedClient returns the clusters client for the given user
	GetImpersonatedClient(ctx context.Context, user *auth.UserPrincipal) (Client, error)
	// GetImpersonatedClientForCluster returns the client for the given user and cluster
	GetImpersonatedClientForCluster(ctx context.Context, user *auth.UserPrincipal, clusterName string) (Client, error)
	// GetImpersonatedDiscoveryClient returns the discovery for the given user and for the given cluster
	GetImpersonatedDiscoveryClient(ctx context.Context, user *auth.UserPrincipal, clusterName string) (discovery.DiscoveryInterface, error)
	// UpdateClusters updates the clusters list
	UpdateClusters(ctx context.Context) error
	// UpdateNamespaces updates the namespaces all namespaces for all clusters
	UpdateNamespaces(ctx context.Context) error
	// UpdateUserNamespaces updates the cache of accessible namespaces for the user
	UpdateUserNamespaces(ctx context.Context, user *auth.UserPrincipal)
	// GetServerClient returns the cluster client with gitops server permissions
	GetServerClient(ctx context.Context) (Client, error)
	// GetClustersNamespaces returns the namespaces for all clusters
	GetClustersNamespaces() map[string][]v1.Namespace
	// GetUserNamespaces returns the accessible namespaces for the user
	GetUserNamespaces(user *auth.UserPrincipal) map[string][]v1.Namespace
	// Start starts go routines to keep clusters and namespaces lists up to date
	Start(ctx context.Context)
	// Subscribe returns a new ClustersWatcher
	Subscribe() *ClustersWatcher
	// RemoveWatcher removes the given ClustersWatcher from the list of watchers
	RemoveWatcher(cw *ClustersWatcher)
	// GetClusters returns all the currently known clusters
	GetClusters() []cluster.Cluster
}

ClustersManager is a manager for creating clients for clusters

func NewClustersManager added in v0.9.5

func NewClustersManager(fetchers []ClusterFetcher, nsChecker nsaccess.Checker, logger logr.Logger) ClustersManager

type ClustersNamespaces added in v0.8.0

type ClustersNamespaces struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*ClustersNamespaces) Clear added in v0.8.1

func (cn *ClustersNamespaces) Clear()

func (*ClustersNamespaces) Get added in v0.8.0

func (cn *ClustersNamespaces) Get(cluster string) []v1.Namespace

func (*ClustersNamespaces) Set added in v0.8.0

func (cn *ClustersNamespaces) Set(cluster string, namespaces []v1.Namespace)

type ClustersWatcher added in v0.9.5

type ClustersWatcher struct {
	Updates chan ClusterListUpdate
	// contains filtered or unexported fields
}

ClustersWatcher watches for cluster list updates and notifies the registered clients.

func (*ClustersWatcher) Notify added in v0.9.5

func (cw *ClustersWatcher) Notify(addedClusters, removedClusters []cluster.Cluster)

Notify publishes cluster updates to the current watcher.

func (*ClustersWatcher) Unsubscribe added in v0.9.5

func (cw *ClustersWatcher) Unsubscribe()

Unsubscribe removes the given ClustersWatcher from the list of watchers.

type ListError added in v0.8.1

type ListError struct {
	Cluster   string
	Namespace string
	Err       error
}

func (ListError) Error added in v0.8.1

func (le ListError) Error() string

type PaginationInfo added in v0.8.0

type PaginationInfo struct {
	sync.Mutex
	ContinueTokens map[string]map[string]string
}

func (*PaginationInfo) Get added in v0.8.0

func (pi *PaginationInfo) Get(cluster string, namespace string) string

func (*PaginationInfo) Set added in v0.8.0

func (pi *PaginationInfo) Set(cluster string, namespace string, token string)

type UsersClients added in v0.10.1

type UsersClients struct {
	Cache *ttlcache.Cache
}

func (*UsersClients) Clear added in v0.10.1

func (uc *UsersClients) Clear()

func (*UsersClients) Get added in v0.10.1

func (uc *UsersClients) Get(user *auth.UserPrincipal, clusterName string) (client.Client, bool)

func (*UsersClients) Set added in v0.10.1

func (uc *UsersClients) Set(user *auth.UserPrincipal, clusterName string, client client.Client)

type UsersNamespaces added in v0.8.0

type UsersNamespaces struct {
	Cache *ttlcache.Cache
}

func (*UsersNamespaces) Clear added in v0.8.1

func (un *UsersNamespaces) Clear()

func (*UsersNamespaces) Get added in v0.8.0

func (un *UsersNamespaces) Get(user *auth.UserPrincipal, cluster string) ([]v1.Namespace, bool)

func (*UsersNamespaces) GetAll added in v0.8.0

func (un *UsersNamespaces) GetAll(user *auth.UserPrincipal, clusters []cluster.Cluster) map[string][]v1.Namespace

GetAll will return all namespace mappings based on the list of clusters provided. The cache very well may contain more, but this List is targeted.

func (*UsersNamespaces) Set added in v0.8.0

func (un *UsersNamespaces) Set(user *auth.UserPrincipal, cluster string, nsList []v1.Namespace)

Directories

Path Synopsis
clusterfakes
Code generated by counterfeiter.
Code generated by counterfeiter.
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

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