fix by checking ownership and uid before deleting sts
@@ -958,10 +958,11 @@ func (r *ReconcilePerconaXtraDBCluster) deleteStatefulSetPods(namespace string,
}
func (r *ReconcilePerconaXtraDBCluster) deleteStatefulSet(cr *api.PerconaXtraDBCluster, sfs api.StatefulApp, deletePVC bool) error {
+ sfsWithOwner := appsv1.StatefulSet{}
err := r.client.Get(context.TODO(), types.NamespacedName{
Name: sfs.StatefulSet().Name,
Namespace: cr.Namespace,
- }, &appsv1.StatefulSet{})
+ }, &sfsWithOwner)
if err != nil && !k8serrors.IsNotFound(err) {
return errors.Wrapf(err, "get statefulset: %s", sfs.StatefulSet().Name)
}
@@ -970,7 +971,12 @@ func (r *ReconcilePerconaXtraDBCluster) deleteStatefulSet(cr *api.PerconaXtraDBC
return nil
}
- err = r.client.Delete(context.TODO(), sfs.StatefulSet())
+ if !metav1.IsControlledBy(&sfsWithOwner, cr){
+ return nil
+ }
+
+ uid := sfsWithOwner.UID
+ err = r.client.Delete(context.TODO(), sfs.StatefulSet(), &client.DeleteOptions{Preconditions: &metav1.Preconditions{UID: &uid}})
if err != nil && !k8serrors.IsNotFound(err) {
return errors.Wrapf(err, "delete statefulset: %s", sfs.StatefulSet().Name)
}
