func()

in pkg/controllers/elasticquota_controller.go [50:89]


func (r *ElasticQuotaReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
	log := log.FromContext(ctx)
	log.Info("reconciling")
	eqList := &schedv1alpha1.ElasticQuotaList{}
	if err := r.List(ctx, eqList, client.InNamespace(req.Namespace)); err != nil {
		if apierrs.IsNotFound(err) {
			log.V(5).Info("no elasticquota found")
			return ctrl.Result{}, nil
		}
		log.V(3).Error(err, "Unable to retrieve elasticquota")
		return ctrl.Result{}, err
	}

	// TODO: When elastic quota supports multiple instances in a namespace, modify this
	if len(eqList.Items) == 0 {
		log.V(5).Info("no elasticquota found")
		return ctrl.Result{}, nil
	}

	eq := &eqList.Items[0]
	used, err := r.computeElasticQuotaUsed(ctx, req.Namespace, eq)
	if err != nil {
		return ctrl.Result{}, err
	}

	// Ignore this loop if the usage value has not changed
	if apiequality.Semantic.DeepEqual(used, eq.Status.Used) {
		return ctrl.Result{}, nil
	}

	// create a usage object that is based on the elastic quota version that will handle updates
	// by default, we set used to the current status
	newEQ := eq.DeepCopy()
	newEQ.Status.Used = used
	if err = r.patchElasticQuota(ctx, eq, newEQ); err != nil {
		return ctrl.Result{}, err
	}
	r.recorder.Event(eq, v1.EventTypeNormal, "Synced", fmt.Sprintf("Elastic Quota %s synced successfully", req.NamespacedName))
	return ctrl.Result{}, nil
}