controllers

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2023 License: Apache-2.0, MIT Imports: 40 Imported by: 0

Documentation

Overview

Package controllers is used to provide the core functionalities of hvpa-controller

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RecheckDeletionTimestamp

func RecheckDeletionTimestamp(getObject func() (metav1.Object, error)) func() error

RecheckDeletionTimestamp returns a CanAdopt() function to recheck deletion.

The CanAdopt() function calls getObject() to fetch the latest value, and denies adoption attempts if that object has a non-nil DeletionTimestamp.

Types

type BaseControllerRefManager

type BaseControllerRefManager struct {
	Controller metav1.Object
	Selector   labels.Selector

	CanAdoptFunc func() error
	// contains filtered or unexported fields
}

BaseControllerRefManager is the struct is used to identify the base controller of the object

func (*BaseControllerRefManager) CanAdopt

func (m *BaseControllerRefManager) CanAdopt() error

CanAdopt is used to identify if the object can be adopted by the controller

func (*BaseControllerRefManager) ClaimObject

func (m *BaseControllerRefManager) ClaimObject(obj metav1.Object, match func(metav1.Object) bool, adopt, release func(metav1.Object) error) (bool, error)

ClaimObject tries to take ownership of an object for this controller.

It will reconcile the following:

  • Adopt orphans if the match function returns true.
  • Release owned objects if the match function returns false.

A non-nil error is returned if some form of reconciliation was attempted and failed. Usually, controllers should try again later in case reconciliation is still needed.

If the error is nil, either the reconciliation succeeded, or no reconciliation was necessary. The returned boolean indicates whether you now own the object.

No reconciliation will be attempted if the controller is being deleted.

type HvpaControllerRefManager

type HvpaControllerRefManager struct {
	BaseControllerRefManager
	// contains filtered or unexported fields
}

HvpaControllerRefManager is the struct used to manage its child objects

func NewHvpaControllerRefManager

func NewHvpaControllerRefManager(
	reconciler *HvpaReconciler,
	controller metav1.Object,
	selector labels.Selector,
	controllerKind schema.GroupVersionKind,
	canAdopt func() error,
) *HvpaControllerRefManager

NewHvpaControllerRefManager returns a HvpaControllerRefManager that exposes methods to manage the controllerRef of its child objects.

The CanAdopt() function can be used to perform a potentially expensive check (such as a live GET from the API server) prior to the first adoption. It will only be called (at most once) if an adoption is actually attempted. If CanAdopt() returns a non-nil error, all adoptions will fail.

NOTE: Once CanAdopt() is called, it will not be called again by the same

HvpaControllerRefManager HPA/VPA. Create a new HPA/VPA if it makes
sense to check CanAdopt() again (e.g. in a different sync pass).

func (*HvpaControllerRefManager) AdoptHpa

AdoptHpa sends a patch to take control of the Hpa. It returns the error if the patching fails.

func (*HvpaControllerRefManager) AdoptVpa

AdoptVpa sends a patch to take control of the Vpa. It returns the error if the patching fails.

func (*HvpaControllerRefManager) ClaimHpas

ClaimHpas tries to take ownership of a list of Hpas.

It will reconcile the following:

  • Adopt orphans if the selector matches.
  • Release owned objects if the selector no longer matches.

Optional: If one or more filters are specified, a Hpa will only be claimed if all filters return true.

A non-nil error is returned if some form of reconciliation was attempted and failed. Usually, controllers should try again later in case reconciliation is still needed.

If the error is nil, either the reconciliation succeeded, or no reconciliation was necessary. The list of Hpas that you now own is returned.

func (*HvpaControllerRefManager) ClaimVpas

ClaimVpas tries to take ownership of a list of Vpas.

It will reconcile the following:

  • Adopt orphans if the selector matches.
  • Release owned objects if the selector no longer matches.

Optional: If one or more filters are specified, a Vpa will only be claimed if all filters return true.

A non-nil error is returned if some form of reconciliation was attempted and failed. Usually, controllers should try again later in case reconciliation is still needed.

If the error is nil, either the reconciliation succeeded, or no reconciliation was necessary. The list of Vpas that you now own is returned.

func (*HvpaControllerRefManager) ReleaseHpa

ReleaseHpa sends a patch to free the Hpa from the control of the controller. It returns the error if the patching fails. 404 and 422 errors are ignored.

func (*HvpaControllerRefManager) ReleaseVpa

ReleaseVpa sends a patch to free the Vpa from the control of the controller. It returns the error if the patching fails. 404 and 422 errors are ignored.

type HvpaReconciler

type HvpaReconciler struct {
	client.Client
	Scheme                *runtime.Scheme
	EnableDetailedMetrics bool

	IsAutoscalingV2Enabled bool
	// contains filtered or unexported fields
}

HvpaReconciler reconciles a Hvpa object

func (*HvpaReconciler) AddMetrics

func (r *HvpaReconciler) AddMetrics() error

AddMetrics initializes and registers the custom metrics for HVPA controller.

func (*HvpaReconciler) Convert_v2_HPA_to_v2beta1 added in v0.12.0

func (*HvpaReconciler) Convert_v2_HorizontalPodAutoscalerList_To_v2beta1 added in v0.12.0

func (r *HvpaReconciler) Convert_v2_HorizontalPodAutoscalerList_To_v2beta1(in *autoscalingv2.HorizontalPodAutoscalerList) (*autoscaling.HorizontalPodAutoscalerList, error)

func (*HvpaReconciler) Convert_v2beta1_HPA_to_v2 added in v0.12.0

func (*HvpaReconciler) Convert_v2beta1_HorizontalPodAutoscalerList_To_v2 added in v0.12.0

func (r *HvpaReconciler) Convert_v2beta1_HorizontalPodAutoscalerList_To_v2(in *autoscaling.HorizontalPodAutoscalerList) (*autoscalingv2.HorizontalPodAutoscalerList, error)

func (*HvpaReconciler) Convert_v2beta1_MetricSpec_to_v2 added in v0.12.0

func (r *HvpaReconciler) Convert_v2beta1_MetricSpec_to_v2(err error, in autoscaling.MetricSpec) (*autoscalingv2.MetricSpec, error)

func (*HvpaReconciler) Convert_v2beta1_TargetRef_to_v2 added in v0.12.0

func (*HvpaReconciler) ManageCache

func (r *HvpaReconciler) ManageCache(instance *autoscalingv1alpha1.Hvpa, namespacedName types.NamespacedName, foundHvpa bool)

ManageCache manages the global map of HVPAs

func (*HvpaReconciler) Reconcile

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

Reconcile reads that state of the cluster for a Hvpa object and makes changes based on the state read and what is in the Hvpa.Spec Automatically generate RBAC rules to allow the Controller to read and write HPAs and VPAs +kubebuilder:rbac:groups=autoscaling,resources=horizontalpodautoscalers,verbs=get;list;watch;create;update;patch;delete +kubebuilder:rbac:groups=autoscaling.k8s.io,resources=verticalpodautoscalers,verbs=get;list;watch;create;update;patch;delete +kubebuilder:rbac:groups=batch,resources=jobs,verbs=get;list;watch;update;patch +kubebuilder:rbac:groups="",resources=pods;replicationcontrollers,verbs=get;list;watch;update;patch +kubebuilder:rbac:groups=apps,resources=daemonsets;replicasets;statefulsets;deployments,verbs=get;list;watch;update;patch +kubebuilder:rbac:groups=autoscaling.k8s.io,resources=hvpas,verbs=get;list;watch;create;update;patch;delete +kubebuilder:rbac:groups=autoscaling.k8s.io,resources=hvpas/status,verbs=get;update;patch +kubebuilder:rbac:groups="",resources=events,verbs=get;watch;list

func (*HvpaReconciler) SetupWithManager

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

SetupWithManager sets up manager with a new controller and r as the reconcile.Reconciler

func (*HvpaReconciler) UpdateHpaV2WithRetries added in v0.12.0

func (r *HvpaReconciler) UpdateHpaV2WithRetries(namespace, name string, applyUpdate updateHpaV2Func) (*autoscalingv2.HorizontalPodAutoscaler, error)

func (*HvpaReconciler) UpdateHpaWithRetries

func (r *HvpaReconciler) UpdateHpaWithRetries(namespace, name string, applyUpdate updateHpaFunc) (*autoscaling.HorizontalPodAutoscaler, error)

UpdateHpaWithRetries updates a hpa with given applyUpdate function. Note that hpa not found error is ignored.

func (*HvpaReconciler) UpdateVpaWithRetries

func (r *HvpaReconciler) UpdateVpaWithRetries(namespace, name string, applyUpdate updateVpaFunc) (*vpa_api.VerticalPodAutoscaler, error)

UpdateVpaWithRetries updates a vpa with given applyUpdate function. Note that vpa not found error is ignored.

type OomkillPredicate

type OomkillPredicate struct {
	predicate.Funcs
}

OomkillPredicate implements a oomkill predicate function

Jump to

Keyboard shortcuts

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