forked from rabbitmq/cluster-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreconcile_status.go
56 lines (48 loc) · 1.71 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
package controllers
import (
"context"
rabbitmqv1beta1 "github.com/rabbitmq/cluster-operator/api/v1beta1"
"github.com/rabbitmq/cluster-operator/internal/resource"
corev1 "k8s.io/api/core/v1"
"reflect"
)
func (r *RabbitmqClusterReconciler) setDefaultUserStatus(ctx context.Context, rmq *rabbitmqv1beta1.RabbitmqCluster) error {
defaultUserStatus := &rabbitmqv1beta1.RabbitmqClusterDefaultUser{}
serviceRef := &rabbitmqv1beta1.RabbitmqClusterServiceReference{
Name: rmq.ChildResourceName(""),
Namespace: rmq.Namespace,
}
defaultUserStatus.ServiceReference = serviceRef
secretRef := &rabbitmqv1beta1.RabbitmqClusterSecretReference{
Name: rmq.ChildResourceName(resource.DefaultUserSecretName),
Namespace: rmq.Namespace,
Keys: map[string]string{
"username": "username",
"password": "password",
},
}
defaultUserStatus.SecretReference = secretRef
if !reflect.DeepEqual(rmq.Status.DefaultUser, defaultUserStatus) {
rmq.Status.DefaultUser = defaultUserStatus
if err := r.Status().Update(ctx, rmq); err != nil {
return err
}
}
return nil
}
// 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) setBinding(ctx context.Context, rmq *rabbitmqv1beta1.RabbitmqCluster) error {
binding := &corev1.LocalObjectReference{
Name: rmq.ChildResourceName(resource.DefaultUserSecretName),
}
if !reflect.DeepEqual(rmq.Status.Binding, binding) {
rmq.Status.Binding = binding
if err := r.Status().Update(ctx, rmq); err != nil {
return err
}
}
return nil
}