in pkg/controller/elasticquota.go [166:208]
func (ctrl *ElasticQuotaController) syncHandler(key string) error {
// Convert the namespace/name string into a distinct namespace and name
namespace, name, err := cache.SplitMetaNamespaceKey(key)
if err != nil {
runtime.HandleError(fmt.Errorf("invalid resource key: %s", key))
return nil
}
// Get the elastic quota resource with this namespace/name
eq, err := ctrl.eqLister.ElasticQuotas(namespace).Get(name)
if apierrs.IsNotFound(err) {
klog.V(5).Infof("Elastic quota %q has been deleted ", key)
return nil
}
if err != nil {
klog.V(3).Infof("Unable to retrieve elastic quota %q from store: %v", key, err)
return err
}
klog.V(5).Infof("Try to process elastic quota: %q", key)
used, err := ctrl.computeElasticQuotaUsed(namespace, eq)
if err != nil {
return err
}
// 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
// Ignore this loop if the usage value has not changed
if apiequality.Semantic.DeepEqual(newEQ.Status, eq.Status) {
return nil
}
patch, err := util.CreateMergePatch(eq, newEQ)
if err != nil {
return err
}
if _, err = ctrl.schedClient.SchedulingV1alpha1().ElasticQuotas(namespace).
Patch(context.TODO(), eq.Name, types.MergePatchType,
patch, metav1.PatchOptions{}); err != nil {
return err
}
ctrl.recorder.Event(eq, v1.EventTypeNormal, "Synced", fmt.Sprintf("Elastic Quota %s synced successfully", key))
return nil
}