cachedresources

package
v0.29.0-rc.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2025 License: Apache-2.0 Imports: 40 Imported by: 0

README

CachedResources controller

This controller acts on CachedResources objects and based on configured GroupVersionKind - replicated them into cache server. To replicate objects 'wrapper' object is used CachedObject. Objects are named based on the original gvr. Example:

Object targeted by CachedResource bellow:

apiVersion: machines.svm.io/v1alpha1
kind: Instance
metadata:
  name: web-server-1

would be replicated into cache server:

apiVersion: cache.kcp.io/v1alpha1
Kind: CachedObject
metadata:
  name: v1alpha1.instances.machines.svm.io.web-server-1
  labels:
    cache.kcp.io/object-schema: v1alpha1.instances.machines.svm.io
    cache.kcp.io/object-group: machines.svm.io
    cache.kcp.io/object-version: v1alpha1
    cache.kcp.io/object-resource: instances
    cache.kcp.io/object-original-name: web-server-1
    cache.kcp.io/object-original-namespace: <empty>

Labels are used to filter object based on group, schema, etc. This way we can get individual object by knowing full gvr + name or just schema.

Main controller (CachedResources) for each CachedResource starts child replication controller with 2 informers:

  • Local - targeting native type (in example instances) to get every change for it.
  • Global - targeting CachedObject from the cache server

It will observe both cache and local states and makes sure object are replicated. On deletion of CachedResources cache is purged and controller stopped after purge is done.

Delete flow:

  1. CachedResource is deleted
  2. Root controller sets phase to Deleting
  3. Root controller gives signal to child controller as its deleted so its stops replicating
  4. Replication root controller will purge the selected resources and flips the status to Deleted
  5. Once it flips status to Deleted - finalizer is removed and controller stopped.

TODO

  1. Make global informer filtered, so it filters only its own schema. Else, with multiple objects in the API it will get everything.
  2. Add secrets reference for Identity hash
  3. Potentially see if we can remove roundtripping to unstructured in the child replication controller.

Documentation

Index

Constants

View Source
const (
	ControllerName = "kcp-cached-resources-controller"

	DefaultIdentitySecretNamespace = "kcp-system"
)

This Controller starts 1 published resource controller per shard. This is bit wasteful for now. We can optimize this by starting a single controller per logical cluster. But this required stopping and starting the controller when a new published resource is created. This would be fist optimization we need todo as follow-up before removing feature flag and making it enabled by default.

View Source
const (
	// ByGVRAndLogicalCluster is the name for the index that indexes by an object's gvr and logical cluster.
	ByGVRAndLogicalCluster = "kcp-byGVRAndLogicalCluster"
)

Variables

This section is empty.

Functions

func GVRAndLogicalClusterKey

func GVRAndLogicalClusterKey(gvr schema.GroupVersionResource, cluster logicalcluster.Name) string

GVRAndShardAndLogicalClusterAndNamespaceKey creates an index key from the given parameters. Key will be in the form of version.resource.group|cluster.

func GenerateIdentitySecret

func GenerateIdentitySecret(ctx context.Context, ns string, name string) (*corev1.Secret, error)

TODO: This is copy from apiexport controller. We should move it to a shared location.

func IdentityHash

func IdentityHash(secret *corev1.Secret) (string, error)

TODO: This is copy from apiexport controller. We should move it to a shared location.

func IndexByGVRAndLogicalCluster

func IndexByGVRAndLogicalCluster(obj interface{}) ([]string, error)

IndexByShardAndLogicalClusterAndNamespace is an index function that indexes by an object's gvr and logical cluster.

Types

type Controller

type Controller struct {
	CachedResourceIndexer cache.Indexer
	CachedResourceLister  cachev1alpha1listers.CachedResourceClusterLister

	CachedResourceEndpointSliceInformer cacheinformers.CachedResourceEndpointSliceClusterInformer
	// contains filtered or unexported fields
}

func NewController

func NewController(
	shardName string,
	kcpClusterClient kcpclientset.ClusterInterface,
	kcpCacheClient kcpclientset.ClusterInterface,
	dynamicClient kcpdynamic.ClusterInterface,
	cacheDynamicClient kcpdynamic.ClusterInterface,

	kubeClusterClient kcpkubernetesclientset.ClusterInterface,
	namespaceInformer kcpcorev1informers.NamespaceClusterInformer,
	secretInformer kcpcorev1informers.SecretClusterInformer,

	dynRESTMapper *dynamicrestmapper.DynamicRESTMapper,

	discoveringDynamicKcpInformers *informer.DiscoveringDynamicSharedInformerFactory,
	cacheKcpInformers kcpinformers.SharedInformerFactory,

	cachedResourceInformer cacheinformers.CachedResourceClusterInformer,
	cachedResourceEndpointSliceInformer cacheinformers.CachedResourceEndpointSliceClusterInformer,
) (*Controller, error)

NewController returns a new controller for CachedResource objects.

func (*Controller) Start

func (c *Controller) Start(ctx context.Context, numThreads int)

Start starts the controller, which stops when ctx.Done() is closed.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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