|
7 | 7 | rabbitmqv1beta1 "github.com/rabbitmq/cluster-operator/api/v1beta1" |
8 | 8 | appsv1 "k8s.io/api/apps/v1" |
9 | 9 | corev1 "k8s.io/api/core/v1" |
10 | | - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
11 | 10 | "k8s.io/apimachinery/pkg/api/errors" |
12 | 11 | "k8s.io/apimachinery/pkg/api/meta" |
| 12 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
13 | 13 | "k8s.io/apimachinery/pkg/types" |
14 | 14 | "k8s.io/client-go/util/retry" |
15 | 15 | "sigs.k8s.io/controller-runtime/pkg/client" |
@@ -67,16 +67,21 @@ func (r *RabbitmqClusterReconciler) statefulSet(ctx context.Context, rmq *rabbit |
67 | 67 | return sts, nil |
68 | 68 | } |
69 | 69 |
|
| 70 | +// statefulSetUID only returns the UID successfully when the controller reference uid matches the rmq uid |
70 | 71 | func (r *RabbitmqClusterReconciler) statefulSetUID(ctx context.Context, rmq *rabbitmqv1beta1.RabbitmqCluster) (types.UID, error) { |
71 | | - uid := types.UID("") |
72 | | - if sts, err := r.statefulSet(ctx, rmq); err == nil { |
73 | | - if ref := metav1.GetControllerOf(sts); ref != nil { |
74 | | - if string(rmq.GetUID()) == string(ref.UID) { |
75 | | - return sts.UID, nil |
76 | | - } |
77 | | - } |
| 72 | + var err error |
| 73 | + var sts *appsv1.StatefulSet |
| 74 | + var ref *metav1.OwnerReference |
| 75 | + if sts, err = r.statefulSet(ctx, rmq); err != nil { |
| 76 | + return "", fmt.Errorf("failed to get statefulSet: %s", err.Error()) |
| 77 | + } |
| 78 | + if ref = metav1.GetControllerOf(sts); ref == nil { |
| 79 | + return "", errors.New("failed to get controller reference for statefulSet") |
| 80 | + } |
| 81 | + if string(rmq.GetUID()) != string(ref.UID) { |
| 82 | + return "", errors.New("statefulSet not owner by current RabbitmqCluster") |
78 | 83 | } |
79 | | - return uid, fmt.Errorf("failed to get the uid of the statefulset owned by the current rabbitmqCluster") |
| 84 | + return sts.UID, nil |
80 | 85 | } |
81 | 86 |
|
82 | 87 | func (r *RabbitmqClusterReconciler) configMap(ctx context.Context, rmq *rabbitmqv1beta1.RabbitmqCluster, name string) (*corev1.ConfigMap, error) { |
|
0 commit comments