in internal/controller/deployment_to_pdb_controller.go [119:151]
func (r *DeploymentToPDBReconciler) updateMinAvailableAsNecessary(ctx context.Context,
deployment *v1.Deployment, EvictionAutoScaler *myappsv1.EvictionAutoScaler, pdb policyv1.PodDisruptionBudget) (reconcile.Result, error) {
logger := log.FromContext(ctx)
logger.Info("deployment replicas got updated", " EvictionAutoScaler.Status.TargetGeneration", EvictionAutoScaler.Status.TargetGeneration, "deployment.Generation", deployment.GetGeneration())
if EvictionAutoScaler.Status.TargetGeneration != deployment.GetGeneration() {
//EvictionAutoScaler can fail between updating deployment and EvictionAutoScaler targetGeneration;
//hence we need to rely on checking if annotation exists and compare with deployment.Spec.Replicas
// no surge happened but customer already increased deployment replicas, then annotation would not exist
if surgeReplicas, scaleUpAnnotationExists := deployment.Annotations[EvictionSurgeReplicasAnnotationKey]; scaleUpAnnotationExists {
newReplicas, err := strconv.Atoi(surgeReplicas)
if err != nil {
logger.Error(err, "unable to parse surge replicas from annotation NOT updating",
"namespace", deployment.Namespace, "name", deployment.Name, "replicas", surgeReplicas)
return reconcile.Result{}, nil
}
if int32(newReplicas) == *deployment.Spec.Replicas {
return reconcile.Result{}, nil
}
}
//someone else changed deployment num of replicas
pdb.Spec.MinAvailable = &intstr.IntOrString{IntVal: *deployment.Spec.Replicas}
e := r.Update(ctx, &pdb)
if e != nil {
logger.Error(e, "unable to update pdb minAvailable to deployment replicas ",
"namespace", pdb.Namespace, "name", pdb.Name, "replicas", *deployment.Spec.Replicas)
return reconcile.Result{}, e
}
logger.Info("Successfully updated pdb minAvailable to deployment replicas ",
"namespace", pdb.Namespace, "name", pdb.Name, "replicas", *deployment.Spec.Replicas)
}
return reconcile.Result{}, nil
}