fix: smartupdate starts after pod deletion
* fix: smartupdate starts after pod deletion
Fix statefulSet change detection logic
* Fix check
* Change variable name
@@ -240,7 +240,24 @@ func (r *ReconcilePerconaXtraDBCluster) smartUpdate(sfs api.StatefulApp, cr *api
return errors.Wrap(err, "failed to get current sfs")
}
- if currentSet.Status.UpdatedReplicas >= currentSet.Status.Replicas {
+ list := corev1.PodList{}
+ if err := r.client.List(context.TODO(),
+ &list,
+ &client.ListOptions{
+ Namespace: currentSet.Namespace,
+ LabelSelector: labels.SelectorFromSet(sfs.Labels()),
+ },
+ ); err != nil {
+ return errors.Wrap(err, "get pod list")
+ }
+ statefulSetChanged := false
+ for _, pod := range list.Items {
+ if pod.ObjectMeta.Labels["controller-revision-hash"] != currentSet.Status.UpdateRevision {
+ statefulSetChanged = true
+ break
+ }
+ }
+ if !statefulSetChanged {
return nil
}
@@ -263,17 +280,6 @@ func (r *ReconcilePerconaXtraDBCluster) smartUpdate(sfs api.StatefulApp, cr *api
return nil
}
- list := corev1.PodList{}
- if err := r.client.List(context.TODO(),
- &list,
- &client.ListOptions{
- Namespace: currentSet.Namespace,
- LabelSelector: labels.SelectorFromSet(sfs.Labels()),
- },
- ); err != nil {
- return errors.Wrap(err, "get pod list")
- }
-
primary, err := r.getPrimaryPod(cr)
if err != nil {
return errors.Wrap(err, "get primary pod")
