clustersmngr

package
v0.9.1-rc.2 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2022 License: MPL-2.0 Imports: 21 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
	ClientQPS = 1000
	// ClientBurst is the burst to use while creating the k8s clients
	ClientBurst = 2000
)

Variables

This section is empty.

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 ClientsFactory added in v0.8.0

type ClientsFactory interface {
	// GetImpersonatedClient returns the clusters client for the given user
	GetImpersonatedClient(ctx context.Context, user *auth.UserPrincipal) (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)
}

ClientsFactory is a factory for creating clients for clusters

func NewClientFactory added in v0.8.0

func NewClientFactory(fetcher ClusterFetcher, nsChecker nsaccess.Checker, logger logr.Logger, scheme *apiruntime.Scheme, clusterPoolFactory ClusterPoolFactoryFn) ClientsFactory

type ClientsPool

type ClientsPool interface {
	Add(cfg ClusterClientConfig, 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 ClusterClientConfig

type ClusterClientConfig func(Cluster) *rest.Config

func ClientConfigWithUser

func ClientConfigWithUser(user *auth.UserPrincipal) ClusterClientConfig

type ClusterFetcher

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

ClusterFetcher fetches all leaf clusters

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)

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