Skip to content

Commit 330ed00

Browse files
authored
Merge pull request #612 from jlarriba/watch_secret
Add watch to PrometheusEndpoint secret in Autoscaling
2 parents c7dad0f + 7ee7d76 commit 330ed00

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

controllers/autoscaling_controller.go

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ func (r *AutoscalingReconciler) reconcileNormal(
452452
Namespace: instance.Namespace,
453453
}, prometheusEndpointSecret)
454454
if err != nil {
455-
Log.Info("No Prometheus Endpoint Secret found")
455+
Log.Info("Prometheus Endpoint Secret not found")
456456
}
457457

458458
if instance.Spec.PrometheusHost == "" {
@@ -825,7 +825,7 @@ func (r *AutoscalingReconciler) SetupWithManager(ctx context.Context, mgr ctrl.M
825825
}
826826
return nil
827827
}
828-
metricStorageFn := func(_ context.Context, o client.Object) []reconcile.Request {
828+
prometheusEndpointFn := func(_ context.Context, o client.Object) []reconcile.Request {
829829
result := []reconcile.Request{}
830830

831831
// get all autoscaling CRs
@@ -840,14 +840,17 @@ func (r *AutoscalingReconciler) SetupWithManager(ctx context.Context, mgr ctrl.M
840840

841841
for _, cr := range autoscalings.Items {
842842
if cr.Spec.PrometheusHost == "" {
843-
// the autoscaling is using MetricStorage for metrics
844-
name := client.ObjectKey{
845-
Namespace: o.GetNamespace(),
846-
Name: cr.Name,
843+
// the autoscaling is using PrometheusEndpoint secret for metrics
844+
if o.GetName() == autoscaling.PrometheusEndpointSecret {
845+
name := client.ObjectKey{
846+
Namespace: o.GetNamespace(),
847+
Name: cr.Name,
848+
}
849+
Log.Info(fmt.Sprintf("Secret %s is used by Autoscaling CR %s", o.GetName(), cr.Name))
850+
result = append(result, reconcile.Request{NamespacedName: name})
847851
}
848-
Log.Info(fmt.Sprintf("MetricStorage %s is used by Autoscaling CR %s", o.GetName(), cr.Name))
849-
result = append(result, reconcile.Request{NamespacedName: name})
850852
}
853+
851854
}
852855
if len(result) > 0 {
853856
return result
@@ -921,16 +924,12 @@ func (r *AutoscalingReconciler) SetupWithManager(ctx context.Context, mgr ctrl.M
921924
handler.EnqueueRequestsFromMapFunc(transportURLSecretFn)).
922925
Watches(&memcachedv1.Memcached{},
923926
handler.EnqueueRequestsFromMapFunc(memcachedFn)).
924-
Watches(
925-
&corev1.Secret{},
927+
Watches(&corev1.Secret{},
926928
handler.EnqueueRequestsFromMapFunc(r.findObjectsForSrc),
927929
builder.WithPredicates(predicate.ResourceVersionChangedPredicate{}),
928930
).
929-
Watches(
930-
&telemetryv1.MetricStorage{},
931-
handler.EnqueueRequestsFromMapFunc(metricStorageFn),
932-
builder.WithPredicates(predicate.ResourceVersionChangedPredicate{}),
933-
).
931+
Watches(&corev1.Secret{},
932+
handler.EnqueueRequestsFromMapFunc(prometheusEndpointFn)).
934933
Watches(&topologyv1.Topology{},
935934
handler.EnqueueRequestsFromMapFunc(r.findObjectsForSrc),
936935
builder.WithPredicates(predicate.GenerationChangedPredicate{})).

0 commit comments

Comments
 (0)