forked from rabbitmq/cluster-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreconcile_status.go
59 lines (51 loc) · 1.93 KB
/
reconcile_status.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package controllers
import (
"context"
"reflect"
rabbitmqv1beta1 "github.com/rabbitmq/cluster-operator/api/v1beta1"
"github.com/rabbitmq/cluster-operator/internal/resource"
corev1 "k8s.io/api/core/v1"
)
// reconcileStatus sets status.defaultUser (secret and service reference) and status.binding.
// when vault is used as secret backend for default user, no user secret object is created
// therefore only status.defaultUser.serviceReference is set.
// status.binding exposes the default user secret which contains the binding
// information for this RabbitmqCluster.
// Default user secret implements the service binding Provisioned Service
// See: https://k8s-service-bindings.github.io/spec/#provisioned-service
func (r *RabbitmqClusterReconciler) reconcileStatus(ctx context.Context, rmq *rabbitmqv1beta1.RabbitmqCluster) error {
var binding *corev1.LocalObjectReference
defaultUserStatus := &rabbitmqv1beta1.RabbitmqClusterDefaultUser{
ServiceReference: &rabbitmqv1beta1.RabbitmqClusterServiceReference{
Name: rmq.ChildResourceName(""),
Namespace: rmq.Namespace,
},
}
if !rmq.VaultDefaultUserSecretEnabled() {
defaultUserStatus.SecretReference = &rabbitmqv1beta1.RabbitmqClusterSecretReference{
Name: rmq.ChildResourceName(resource.DefaultUserSecretName),
Namespace: rmq.Namespace,
Keys: map[string]string{
"username": "username",
"password": "password",
},
}
if !rmq.ExternalSecretEnabled() {
binding = &corev1.LocalObjectReference{
Name: rmq.ChildResourceName(resource.DefaultUserSecretName),
}
} else {
binding = &corev1.LocalObjectReference{
Name: rmq.Spec.SecretBackend.ExternalSecret.Name,
}
}
}
if !reflect.DeepEqual(rmq.Status.DefaultUser, defaultUserStatus) || !reflect.DeepEqual(rmq.Status.Binding, binding) {
rmq.Status.DefaultUser = defaultUserStatus
rmq.Status.Binding = binding
if err := r.Status().Update(ctx, rmq); err != nil {
return err
}
}
return nil
}