func()

in internal/controller/deployment_to_pdb_controller.go [158:180]


func (r *DeploymentToPDBReconciler) SetupWithManager(mgr ctrl.Manager) error {
	logger := mgr.GetLogger()
	// Set up the controller to watch Deployments and trigger the reconcile function
	// when controller restarts everything is seen as a create event
	return ctrl.NewControllerManagedBy(mgr).
		For(&v1.Deployment{}).
		WithEventFilter(predicate.Funcs{
			UpdateFunc: func(e event.UpdateEvent) bool {
				//logger.Info("Update event detected, no action will be taken")
				//ToDo: distinguish scales from our EvictionAutoScaler from scales from other owners and keep minAvailable up near replicas.
				// Like if I start a deployment at 3 but then later say this is popular let me bump it to 5 should our pdb change.
				if oldDeployment, ok := e.ObjectOld.(*v1.Deployment); ok {
					newDeployment := e.ObjectNew.(*v1.Deployment)
					logger.Info("Update event detected, num of replicas changed", "newReplicas", newDeployment.Spec.Replicas)
					return oldDeployment.Spec.Replicas != newDeployment.Spec.Replicas
				}
				return false
				//return e.ObjectOld.GetGeneration() != e.ObjectNew.GetGeneration()
			},
		}).
		Owns(&policyv1.PodDisruptionBudget{}). // Watch PDBs for ownership
		Complete(r)
}