in shardingsphere-operator/pkg/controllers/proxy_controller.go [142:183]
func (r *ProxyReconciler) reconcileHPA(ctx context.Context, namespacedName types.NamespacedName) (ctrl.Result, error) {
proxy, err := r.getRuntimeShardingSphereProxy(ctx, namespacedName)
if err != nil {
return ctrl.Result{}, err
}
// Get the HPA
hpa := &autoscalingv2beta2.HorizontalPodAutoscaler{}
err = r.Get(ctx, namespacedName, hpa)
// If the HPA doesn't exist, create it
if apierrors.IsNotFound(err) {
if proxy.Spec.AutomaticScaling != nil && proxy.Spec.AutomaticScaling.Enable {
exp := reconcile.NewHPA(proxy)
if err := r.Create(ctx, exp); err != nil {
return ctrl.Result{}, err
}
}
return ctrl.Result{}, nil
}
if err != nil {
return ctrl.Result{}, err
}
// If the HPA exists, but we don't want it, delete it
if proxy.Spec.AutomaticScaling == nil || !proxy.Spec.AutomaticScaling.Enable {
if err := r.Delete(ctx, hpa); err != nil {
return ctrl.Result{}, err
}
return ctrl.Result{}, nil
}
// If the HPA exists and we want it, update it
act := hpa.DeepCopy()
exp := reconcile.UpdateHPA(proxy, act)
if err := r.Update(ctx, exp); err != nil {
return ctrl.Result{}, err
}
return ctrl.Result{}, nil
}