resourcerequestoperator

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2022 License: Apache-2.0 Imports: 46 Imported by: 0

Documentation

Overview

Package resourcerequestoperator contains the ResourceRequest controller which reconciles the resource and creates new ResourceOffer and related tests. utils.go contains all utility function.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetResourceRequest added in v0.3.2

func GetResourceRequest(ctx context.Context, k8sClient client.Client, clusterID string) (
	*discoveryv1alpha1.ResourceRequest, error)

GetResourceRequest returns ResourceRequest for the given cluster.

func GetTenantName added in v0.4.0

func GetTenantName(cluster discoveryv1alpha1.ClusterIdentity) string

GetTenantName returns the name of the Tenant for the given cluster.

func ScaleResources added in v0.3.2

func ScaleResources(resourceName corev1.ResourceName, quantity *resource.Quantity, factor float32)

ScaleResources multiplies a resource by a factor.

Types

type LocalResourceMonitor added in v0.3.2

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

LocalResourceMonitor is an object that keeps track of the cluster's resources.

func NewLocalMonitor added in v0.3.2

func NewLocalMonitor(ctx context.Context, clientset kubernetes.Interface,
	resyncPeriod time.Duration) *LocalResourceMonitor

NewLocalMonitor creates a new LocalResourceMonitor.

func (*LocalResourceMonitor) ReadResources added in v0.3.2

func (m *LocalResourceMonitor) ReadResources(clusterID string) corev1.ResourceList

ReadResources returns the resources available in the cluster (total minus used), multiplied by resourceSharingPercentage.

func (*LocalResourceMonitor) Register added in v0.3.2

func (m *LocalResourceMonitor) Register(notifier ResourceUpdateNotifier)

Register sets an update notifier.

func (*LocalResourceMonitor) RemoveClusterID added in v0.3.2

func (m *LocalResourceMonitor) RemoveClusterID(clusterID string)

RemoveClusterID removes a clusterID from all broadcaster internal structures it is useful when a particular foreign cluster has no more peering and its ResourceRequest has been deleted.

type OfferQueue added in v0.3.2

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

OfferQueue is a component that periodically commands a broadcaster/broker to update its ResourceOffers. It also provides rate-limited retries for transient errors in the offering process.

func NewOfferQueue added in v0.3.2

func NewOfferQueue(offerUpdater *OfferUpdater) OfferQueue

NewOfferQueue constructs an OfferQueue.

func (*OfferQueue) Push added in v0.3.2

func (u *OfferQueue) Push(cluster discoveryv1alpha1.ClusterIdentity)

Push pushes a cluster ID into the queue.

func (*OfferQueue) RemoveClusterID added in v0.3.2

func (u *OfferQueue) RemoveClusterID(clusterID string)

RemoveClusterID clears updates for the given cluster.

func (*OfferQueue) Start added in v0.3.2

func (u *OfferQueue) Start(ctx context.Context) error

Start starts the update loop and blocks.

type OfferUpdater

type OfferUpdater struct {
	ResourceReader ResourceReader
	OfferQueue
	// contains filtered or unexported fields
}

OfferUpdater is a component that responds to ResourceRequests with the cluster's resources read from ResourceReader.

func NewOfferUpdater added in v0.3.2

func NewOfferUpdater(k8sClient client.Client, homeCluster discoveryv1alpha1.ClusterIdentity,
	clusterLabels map[string]string, reader ResourceReader, updateThresholdPercentage uint,
	localRealStorageClassName string, enableStorage bool) *OfferUpdater

NewOfferUpdater constructs a new OfferUpdater.

func (*OfferUpdater) CreateOrUpdateOffer added in v0.3.2

func (u *OfferUpdater) CreateOrUpdateOffer(cluster discoveryv1alpha1.ClusterIdentity) (requeue bool, err error)

CreateOrUpdateOffer creates an offer into the given cluster, reading resources from the ResourceReader.

func (*OfferUpdater) NotifyChange added in v0.3.2

func (u *OfferUpdater) NotifyChange()

NotifyChange is used by the ResourceReader to notify that resources were added or removed. It checks if any resources have changed by at least a set percentage since we last updated a ResourceOffer, and if so it triggers a new update.

func (*OfferUpdater) RemoveClusterID added in v0.3.2

func (u *OfferUpdater) RemoveClusterID(clusterID string)

RemoveClusterID stops tracking the resources to be offered to a given cluster.

func (*OfferUpdater) SetThreshold added in v0.3.2

func (u *OfferUpdater) SetThreshold(updateThresholdPercentage uint)

SetThreshold sets the threshold for resource updates to trigger an update of the ResourceOffers.

func (*OfferUpdater) Start

func (u *OfferUpdater) Start(ctx context.Context) error

Start starts the OfferUpdater and blocks.

type PodTransition

type PodTransition uint8

PodTransition represents a podReady condition possible transitions.

const (
	// PendingToReady represents a transition from PodReady status = false to PodReady status = true.
	PendingToReady PodTransition = iota
	// ReadyToReady represents no change in PodReady status when status = true.
	ReadyToReady
	// ReadyToPending represents a transition from PodReady status = true to PodReady status = false.
	ReadyToPending
	// PendingToPending represents no change in PodReady status when status = false.
	PendingToPending
)

type ResourceReader added in v0.3.2

type ResourceReader interface {
	// ReadResources returns the resources available for usage by the given cluster.
	ReadResources(clusterID string) corev1.ResourceList
	// Register sets the component that will be notified of changes.
	Register(ResourceUpdateNotifier)
	// RemoveClusterID removes the given clusterID from all internal structures.
	RemoveClusterID(clusterID string)
}

ResourceReader represents an interface to read the available resources in this cluster.

type ResourceRequestReconciler

type ResourceRequestReconciler struct {
	client.Client
	Scheme      *runtime.Scheme
	HomeCluster discoveryv1alpha1.ClusterIdentity
	*OfferUpdater
	EnableIncomingPeering bool
}

ResourceRequestReconciler reconciles a ResourceRequest object.

func (*ResourceRequestReconciler) Reconcile

func (r *ResourceRequestReconciler) Reconcile(ctx context.Context, req ctrl.Request) (result ctrl.Result, err error)

Reconcile is the main function of the controller which reconciles ResourceRequest resources.

func (*ResourceRequestReconciler) SetupWithManager

func (r *ResourceRequestReconciler) SetupWithManager(mgr ctrl.Manager) error

SetupWithManager is the setup function of the controller.

type ResourceScaler added in v0.3.2

type ResourceScaler struct {
	Provider ResourceReader
	Factor   float32
	Notifier ResourceUpdateNotifier
}

ResourceScaler scales the resources of a ResourceReader by a given amount. It is used to let one reserve resources for local usage and not share them (Factor < 1).

func (*ResourceScaler) ReadResources added in v0.3.2

func (s *ResourceScaler) ReadResources(clusterID string) corev1.ResourceList

ReadResources returns the provider's resources scaled by the given amount.

func (*ResourceScaler) Register added in v0.3.2

func (s *ResourceScaler) Register(notifier ResourceUpdateNotifier)

Register sets an update notifier.

func (*ResourceScaler) RemoveClusterID added in v0.3.2

func (s *ResourceScaler) RemoveClusterID(clusterID string)

RemoveClusterID removes the given clusterID from the provider.

type ResourceUpdateNotifier added in v0.3.2

type ResourceUpdateNotifier interface {
	// NotifyChange signals that a change in resources may have occurred.
	NotifyChange()
}

ResourceUpdateNotifier represents an interface for OfferUpdater to receive resource updates.

Jump to

Keyboard shortcuts

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