clustersmngr

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2022 License: MPL-2.0 Imports: 29 Imported by: 14

Documentation

Index

Constants

View Source
const (
	// Clusters Client context key
	ClustersClientCtxKey key = iota
	// DefaultCluster name
	DefaultCluster = "Default"
	// ClientQPS is the QPS to use while creating the k8s clients (actually a float32)
	ClientQPS = 1000
	// ClientBurst is the burst to use while creating the k8s clients
	ClientBurst = 2000
)

Variables

View Source
var DefaultKubeConfigOptions = []KubeConfigOption{WithFlowControl}

Functions

func ApplyKubeConfigOptions added in v0.9.4

func ApplyKubeConfigOptions(config *rest.Config, options ...KubeConfigOption) (*rest.Config, error)

func CachedClientFactory added in v0.10.1

func CachedClientFactory(cfgFunc ClusterClientConfigFunc, cluster Cluster, scheme *apiruntime.Scheme) (client.Client, error)

func ClientFactory added in v0.10.1

func ClientFactory(cfgFunc ClusterClientConfigFunc, cluster Cluster, scheme *apiruntime.Scheme) (client.Client, error)

func NewDelegatingCache added in v0.10.1

func NewDelegatingCache(cr client.Reader, cache cache.Cache, scheme *runtime.Scheme) cache.Cache

func WithFlowControl added in v0.9.4

func WithFlowControl(config *rest.Config) (*rest.Config, error)

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 ClientFactoryFn added in v0.10.1

type ClientFactoryFn func(cfgFunc ClusterClientConfigFunc, cluster Cluster, scheme *apiruntime.Scheme) (client.Client, error)

type ClientsPool

type ClientsPool interface {
	Add(c client.Client, 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(scheme *apiruntime.Scheme) ClientsPool

NewClustersClientsPool initializes a new ClientsPool

type Cluster

type Cluster struct {
	// Name defines the cluster name
	Name string `yaml:"name"`
	// Server defines cluster api address
	Server string `yaml:"server"`

	// SecretRef defines secret name that holds the cluster Bearer Token
	SecretRef string `yaml:"secretRef"`
	// BearerToken cluster access token read from SecretRef
	BearerToken string

	// TLSConfig holds configuration for TLS connection with the cluster values read from SecretRef
	TLSConfig rest.TLSClientConfig
}

Cluster defines a leaf cluster

type ClusterClientConfigFunc added in v0.9.2

type ClusterClientConfigFunc func(Cluster) (*rest.Config, error)

func ClientConfigAsServer added in v0.9.4

func ClientConfigAsServer(options ...KubeConfigOption) ClusterClientConfigFunc

clientConfigAsServer returns a *rest.Config for a given cluster as the server service acconut

func ClientConfigWithUser

func ClientConfigWithUser(user *auth.UserPrincipal, options ...KubeConfigOption) ClusterClientConfigFunc

ClientConfigWithUser returns a function that returns a *rest.Config with the relevant user authentication details pre-defined for a given cluster.

type ClusterFetcher

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

ClusterFetcher fetches all leaf clusters

type ClusterListUpdate added in v0.9.5

type ClusterListUpdate struct {
	Added   []Cluster
	Removed []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 ClusterPoolFactoryFn added in v0.9.1

type ClusterPoolFactoryFn func(*apiruntime.Scheme) ClientsPool

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

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(clusters []Cluster) (added, removed []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.DiscoveryClient, 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
}

ClustersManager is a manager for creating clients for clusters

func NewClustersManager added in v0.9.5

func NewClustersManager(fetcher ClusterFetcher, nsChecker nsaccess.Checker, logger logr.Logger, scheme *apiruntime.Scheme, clientFactory ClientFactoryFn, kubeConfigOptions []KubeConfigOption) 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)

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 KubeConfigOption added in v0.9.4

type KubeConfigOption func(*rest.Config) (*rest.Config, error)

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) 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
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