Documentation ¶
Index ¶
- Constants
- Variables
- func ApplyKubeConfigOptions(config *rest.Config, options ...KubeConfigOption) (*rest.Config, error)
- func WithFlowControl(config *rest.Config) (*rest.Config, error)
- type Client
- type ClientError
- type ClientsFactory
- type ClientsPool
- type Cluster
- type ClusterClientConfigFunc
- type ClusterFetcher
- type ClusterNotFoundError
- type ClusterPoolFactoryFn
- type ClusteredList
- func (cl *ClusteredList) AddObjectList(cluster string, list client.ObjectList)
- func (cl *ClusteredList) GetContinue() string
- func (cl *ClusteredList) Lists() map[string][]client.ObjectList
- func (cl *ClusteredList) NewList() client.ObjectList
- func (cl *ClusteredList) SetContinue(continueToken string)
- type ClusteredListError
- type ClusteredObjectList
- type Clusters
- type ClustersNamespaces
- type KubeConfigOption
- type ListError
- type PaginationInfo
- type UsersNamespaces
- func (un *UsersNamespaces) Clear()
- func (un *UsersNamespaces) Get(user *auth.UserPrincipal, cluster string) ([]v1.Namespace, bool)
- func (un *UsersNamespaces) GetAll(user *auth.UserPrincipal, clusters []Cluster) map[string][]v1.Namespace
- func (un *UsersNamespaces) Set(user *auth.UserPrincipal, cluster string, nsList []v1.Namespace)
Constants ¶
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 ¶
var DefaultKubeConfigOptions = []KubeConfigOption{WithFlowControl}
Functions ¶
func ApplyKubeConfigOptions ¶ added in v0.9.4
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
type ClientError ¶ added in v0.9.1
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 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) // 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) }
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, kubeConfigOptions []KubeConfigOption) ClientsFactory
type ClientsPool ¶
type ClientsPool interface { Add(cfg ClusterClientConfigFunc, 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
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 ¶
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 ¶
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 ClustersNamespaces ¶ added in v0.8.0
func (*ClustersNamespaces) Clear ¶ added in v0.8.1
func (cn *ClustersNamespaces) Clear()
type KubeConfigOption ¶ added in v0.9.4
type PaginationInfo ¶ added in v0.8.0
type UsersNamespaces ¶ added in v0.8.0
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)