multicluster

package
v0.0.0-...-577c19e Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2026 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIServersConfig

type APIServersConfig struct {
	// Resources managed in the cluster where cortex is deployed.
	Home HomeConfig `json:"home"`
	// Resources managed in remote clusters.
	Remotes []RemoteConfig `json:"remotes,omitempty"`
}

APIServersConfig separates resources into home and remote clusters.

type Client

type Client struct {
	// ResourceRouters determine which cluster a resource should be written to
	// when multiple clusters serve the same GVK.
	ResourceRouters map[schema.GroupVersionKind]ResourceRouter

	// The cluster in which cortex is deployed.
	HomeCluster cluster.Cluster
	// The REST config for the home cluster in which cortex is deployed.
	HomeRestConfig *rest.Config
	// The scheme for the home cluster in which cortex is deployed.
	// This scheme should include all types used in the remote clusters.
	HomeScheme *runtime.Scheme
	// contains filtered or unexported fields
}

func (*Client) AddRemote

func (c *Client) AddRemote(ctx context.Context, host, caCert string, labels map[string]string, gvks ...schema.GroupVersionKind) (cluster.Cluster, error)

Add a remote cluster which uses the same REST config as the home cluster, but a different host, for the given resource gvks.

This can be used when the remote cluster accepts the home cluster's service account tokens. See the kubernetes documentation on structured auth to learn more about jwt-based authentication across clusters.

func (*Client) Apply

Apply is not supported in the multicluster client as the group version kind cannot be inferred from the ApplyConfiguration.

func (*Client) ClustersForGVK

func (c *Client) ClustersForGVK(gvk schema.GroupVersionKind) ([]cluster.Cluster, error)

ClustersForGVK returns all clusters that serve the given GVK. The GVK must be explicitly configured in either homeGVKs or remoteClusters. Returns an error if the GVK is unknown.

func (*Client) Create

func (c *Client) Create(ctx context.Context, obj client.Object, opts ...client.CreateOption) error

Create routes the object to the matching cluster using the ResourceRouter and performs a Create operation.

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, obj client.Object, opts ...client.DeleteOption) error

Delete routes the object to the matching cluster using the ResourceRouter and performs a Delete operation.

func (*Client) DeleteAllOf

func (c *Client) DeleteAllOf(ctx context.Context, obj client.Object, opts ...client.DeleteAllOfOption) error

DeleteAllOf iterates over all clusters with the GVK and performs DeleteAllOf on each.

func (*Client) GVKFromHomeScheme

func (c *Client) GVKFromHomeScheme(obj runtime.Object) (gvk schema.GroupVersionKind, err error)

Get the gvk registered for the given resource in the home cluster's scheme.

func (*Client) Get

func (c *Client) Get(ctx context.Context, key client.ObjectKey, obj client.Object, opts ...client.GetOption) error

Get iterates over all clusters with the GVK and returns the result. Returns an error if the resource is found in multiple clusters (duplicate). If no cluster has the resource, a NotFound error is returned. Non-NotFound errors from individual clusters are logged and silently skipped so that a single unavailable cluster does not block the entire read path.

func (*Client) GetEventRecorder

func (c *Client) GetEventRecorder(name string) events.EventRecorder

GetEventRecorder creates a multi-cluster-aware EventRecorder. It pre-creates a per-cluster recorder for the home cluster and every remote cluster currently registered in the client. The name parameter is passed through to each cluster's GetEventRecorder method (it becomes the reportingController in the Kubernetes Event).

func (*Client) GroupVersionKindFor

func (c *Client) GroupVersionKindFor(obj runtime.Object) (schema.GroupVersionKind, error)

Return the GroupVersionKind for the given object using the home cluster's RESTMapper.

func (*Client) IndexField

func (c *Client) IndexField(ctx context.Context, obj client.Object, list client.ObjectList, field string, extractValue client.IndexerFunc) error

Index a field for a resource in all matching cluster caches. Usually, you want to index the same field in both the object and list type, as both would be mapped to individual clients based on their GVK.

func (*Client) InitFromConf

func (c *Client) InitFromConf(ctx context.Context, mgr ctrl.Manager, conf ClientConfig) error

Helper function to initialize a new multicluster client during service startup, using the conf module provided by cortex.

func (*Client) IsObjectNamespaced

func (c *Client) IsObjectNamespaced(obj runtime.Object) (bool, error)

Return true if the GroupVersionKind of the object is namespaced using the home cluster's RESTMapper.

func (*Client) List

func (c *Client) List(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error

List iterates over all clusters with the GVK and returns a combined list. Returns an error if any resources share the same namespace/name across clusters. Errors from individual clusters are logged and silently skipped so that a single unavailable cluster does not block the entire read path.

func (*Client) Patch

func (c *Client) Patch(ctx context.Context, obj client.Object, patch client.Patch, opts ...client.PatchOption) error

Patch routes the object to the matching cluster using the ResourceRouter and performs a Patch operation.

func (*Client) RESTMapper

func (c *Client) RESTMapper() meta.RESTMapper

Return the RESTMapper of the home cluster.

func (*Client) Scheme

func (c *Client) Scheme() *runtime.Scheme

Return the scheme of the home cluster.

func (*Client) Status

func (c *Client) Status() client.StatusWriter

Provide a wrapper around the status subresource client which picks the right cluster based on the resource type.

func (*Client) SubResource

func (c *Client) SubResource(subResource string) client.SubResourceClient

Provide a wrapper around the given subresource client which picks the right cluster based on the resource type.

func (*Client) Update

func (c *Client) Update(ctx context.Context, obj client.Object, opts ...client.UpdateOption) error

Update routes the object to the matching cluster using the ResourceRouter and performs an Update operation.

type ClientConfig

type ClientConfig struct {
	// Apiserver configuration mapping GVKs to home or remote clusters.
	// Every GVK used through the multicluster client must be listed
	// in either Home or Remotes. Unknown GVKs will cause an error.
	APIServers APIServersConfig `json:"apiservers"`
}

type HistoryResourceRouter

type HistoryResourceRouter struct{}

HistoryResourceRouter routes histories to clusters based on availability zone.

func (HistoryResourceRouter) Match

func (h HistoryResourceRouter) Match(obj any, labels map[string]string) (bool, error)

type HomeConfig

type HomeConfig struct {
	// The resource GVKs formatted as "<group>/<version>/<Kind>".
	GVKs []string `json:"gvks"`
}

HomeConfig lists GVKs that are managed in the home cluster.

type HypervisorResourceRouter

type HypervisorResourceRouter struct{}

HypervisorResourceRouter routes hypervisors to clusters based on availability zone.

func (HypervisorResourceRouter) Match

func (h HypervisorResourceRouter) Match(obj any, labels map[string]string) (bool, error)

type MultiClusterRecorder

type MultiClusterRecorder struct {
	// contains filtered or unexported fields
}

MultiClusterRecorder implements events.EventRecorder and routes events to the correct cluster based on the GVK of the "regarding" object. It uses the same routing logic as the multicluster Client's write path.

func (*MultiClusterRecorder) Eventf

func (r *MultiClusterRecorder) Eventf(regarding, related runtime.Object, eventtype, reason, action, note string, args ...any)

Eventf routes the event to the cluster that owns the "regarding" object. Falls back to the home cluster recorder if routing fails.

type MulticlusterBuilder

type MulticlusterBuilder struct {
	// Wrapped builder provided by controller-runtime.
	*builder.Builder
	// contains filtered or unexported fields
}

Builder which provides special methods to watch resources across multiple clusters.

func BuildController

func BuildController(c *Client, mgr manager.Manager) MulticlusterBuilder

Build a multicluster controller using the multicluster client. Use this builder to watch resources across multiple clusters.

func (MulticlusterBuilder) WatchesMulticluster

func (b MulticlusterBuilder) WatchesMulticluster(object client.Object, eventHandler handler.TypedEventHandler[client.Object, reconcile.Request], predicates ...predicate.Predicate) (MulticlusterBuilder, error)

WatchesMulticluster watches a resource across all clusters that serve its GVK. If the GVK is served by multiple remote clusters, a watch is set up on each. Returns an error if the GVK is not configured in any cluster.

type RemoteConfig

type RemoteConfig struct {
	// The remote kubernetes apiserver url, e.g. "https://my-apiserver:6443".
	Host string `json:"host"`
	// The root CA certificate to verify the remote apiserver.
	CACert string `json:"caCert,omitempty"`
	// The resource GVKs this apiserver serves, formatted as "<group>/<version>/<Kind>".
	GVKs []string `json:"gvks"`
	// Labels used by ResourceRouters to match resources to this cluster
	// for write operations (Create/Update/Delete/Patch).
	Labels map[string]string `json:"labels,omitempty"`
}

RemoteConfig maps multiple GVKs to a remote kubernetes apiserver with routing labels. It is assumed that the remote apiserver accepts the serviceaccount tokens issued by the local cluster.

type ReservationsResourceRouter

type ReservationsResourceRouter struct{}

ReservationsResourceRouter routes reservations to clusters based on availability zone.

func (ReservationsResourceRouter) Match

func (r ReservationsResourceRouter) Match(obj any, labels map[string]string) (bool, error)

type ResourceRouter

type ResourceRouter interface {
	Match(obj any, labels map[string]string) (bool, error)
}

ResourceRouter determines which remote cluster a resource should be written to by matching the resource content against the cluster's labels.

Jump to

Keyboard shortcuts

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