Browse Source

cleanup labels

master
Andrey Inishev 1 year ago
parent
commit
e054b130f0
2 changed files with 12 additions and 20 deletions
  1. +6
    -7
      pkg/controller/rabbitmq/rabbitmq_controller.go
  2. +6
    -13
      pkg/controller/rabbitmq/rabbitmq_services.go

+ 6
- 7
pkg/controller/rabbitmq/rabbitmq_controller.go View File

@@ -91,19 +91,19 @@ func add(mgr manager.Manager, reconciler reconcile.Reconciler) error {
mapFn := handler.ToRequestsFunc(
func(a handler.MapObject) []reconcile.Request {
return []reconcile.Request{
{NamespacedName: types.NamespacedName{Name: a.Meta.GetLabels()["app.improvado.io/instance"], Namespace: a.Meta.GetNamespace()}},
{NamespacedName: types.NamespacedName{Name: a.Meta.GetLabels()["rabbitmq.improvado.io/instance"], Namespace: a.Meta.GetNamespace()}},
}
})

p := predicate.Funcs{
UpdateFunc: func(e event.UpdateEvent) bool {
if _, ok := e.MetaOld.GetLabels()["app.improvado.io/instance"]; !ok {
if _, ok := e.MetaOld.GetLabels()["rabbitmq.improvado.io/instance"]; !ok {
return false
}
return e.ObjectOld != e.ObjectNew
},
CreateFunc: func(e event.CreateEvent) bool {
if _, ok := e.Meta.GetLabels()["app.improvado.io/instance"]; !ok {
if _, ok := e.Meta.GetLabels()["rabbitmq.improvado.io/instance"]; !ok {
return false
}
return true
@@ -154,8 +154,7 @@ func mergeMaps(itermaps ...map[string]string) map[string]string {

func returnLabels(cr *rabbitmqv1.Rabbitmq) map[string]string {
labels := map[string]string{
"app.improvado.io/application": "rabbitmq",
"app.improvado.io/instance": cr.Name,
"rabbitmq.improvado.io/instance": cr.Name,
}
return labels
}
@@ -454,7 +453,7 @@ func newStatefulSet(cr *rabbitmqv1.Rabbitmq, secretNames secretResouces) *v1.Sta
podTemplate := corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: mergeMaps(returnLabels(cr),
map[string]string{"app.improvado.io/component": "messaging"},
map[string]string{"rabbitmq.improvado.io/component": "messaging"},
),
Annotations: returnAnnotations(cr),
},
@@ -526,7 +525,7 @@ func newStatefulSet(cr *rabbitmqv1.Rabbitmq, secretNames secretResouces) *v1.Sta
Name: cr.Name,
Namespace: cr.Namespace,
Labels: mergeMaps(returnLabels(cr),
map[string]string{"app.improvado.io/component": "messaging"},
map[string]string{"rabbitmq.improvado.io/component": "messaging"},
),
},
Spec: v1.StatefulSetSpec{


+ 6
- 13
pkg/controller/rabbitmq/rabbitmq_services.go View File

@@ -54,6 +54,10 @@ func (r *ReconcileRabbitmq) reconcileService(reqLogger logr.Logger, cr *rabbitmq
found.Spec.Selector = service.Spec.Selector
}

if !reflect.DeepEqual(found.Labels, service.Labels) {
found.Labels = service.Labels
}

if err = r.client.Update(context.TODO(), found); err != nil {
reqLogger.Info("Error updating service", "Service.Namespace", service.Namespace, "Service.Name", service.Name)
return reconcile.Result{}, err
@@ -126,10 +130,6 @@ func (r *ReconcileRabbitmq) reconcileHAService(reqLogger logr.Logger, cr *rabbit
ObjectMeta: metav1.ObjectMeta{
Name: cr.Name,
Namespace: cr.Namespace,
Labels: mergeMaps(returnLabels(cr),
map[string]string{"rabbitmq.improvado.io/service": "general"},
map[string]string{"rabbitmq.improvado.io/component": "networking"},
),
},
Spec: corev1.ServiceSpec{
Type: corev1.ServiceTypeClusterIP,
@@ -169,8 +169,7 @@ func (r *ReconcileRabbitmq) reconcileHTTPService(reqLogger logr.Logger, cr *rabb
Name: cr.Name + "-api",
Namespace: cr.Namespace,
Labels: mergeMaps(returnLabels(cr),
map[string]string{"rabbitmq.improvado.io/service": "api"},
map[string]string{"rabbitmq.improvado.io/component": "networking"},
map[string]string{"rabbitmq.improvado.io/service": "management"},
),
},
Spec: corev1.ServiceSpec{
@@ -199,9 +198,7 @@ func (r *ReconcileRabbitmq) reconcilePrometheusExporterService(reqLogger logr.Lo
Name: cr.Name + "-exporter",
Namespace: cr.Namespace,
Labels: mergeMaps(returnLabels(cr),
map[string]string{"rabbitmq.improvado.io/service": "prometheus-exporter"},
map[string]string{"rabbitmq.improvado.io/component": "monitoring"},
map[string]string{"rabbitmq.improvado.io/component": "networking"},
),
},
Spec: corev1.ServiceSpec{
@@ -233,11 +230,7 @@ func (r *ReconcileRabbitmq) reconcilePrometheusExporterServiceMonitor(reqLogger
},
Spec: v12.ServiceMonitorSpec{
Selector: metav1.LabelSelector{
MatchLabels: mergeMaps(returnLabels(cr),
map[string]string{"rabbitmq.improvado.io/service": "prometheus-exporter"},
map[string]string{"rabbitmq.improvado.io/component": "monitoring"},
map[string]string{"rabbitmq.improvado.io/component": "networking"},
),
MatchLabels: returnLabels(cr),
},
Endpoints: []v12.Endpoint{
{


Loading…
Cancel
Save