Skip to content

Commit dce01ed

Browse files
Merge pull request #600 from jlarriba/autoscaling_prom
Autoscaling should use the prometheus secret
2 parents e1506f7 + 1df4564 commit dce01ed

File tree

4 files changed

+33
-9
lines changed

4 files changed

+33
-9
lines changed

controllers/autoscaling_controller.go

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ package controllers
1919
import (
2020
"context"
2121
"fmt"
22+
"github.com/openstack-k8s-operators/telemetry-operator/pkg/metricstorage"
23+
"strconv"
2224
"time"
2325

2426
appsv1 "k8s.io/api/apps/v1"
@@ -425,13 +427,30 @@ func (r *AutoscalingReconciler) reconcileNormal(
425427
// Get correct prometheus host, port and if TLS should be used
426428
// NOTE: Always do this before calling the generateServiceConfig to get the newest values in the ServiceConfig
427429
//
430+
prometheusEndpointSecret := &corev1.Secret{}
431+
err = r.Client.Get(ctx, client.ObjectKey{
432+
Name: autoscaling.PrometheusEndpointSecret,
433+
Namespace: instance.Namespace,
434+
}, prometheusEndpointSecret)
435+
if err != nil {
436+
Log.Info("No Prometheus Endpoint Secret found")
437+
}
438+
428439
if instance.Spec.PrometheusHost == "" {
429-
instance.Status.PrometheusHost = fmt.Sprintf("%s-prometheus.%s.svc", telemetryv1.DefaultServiceName, instance.Namespace)
440+
if prometheusEndpointSecret.Data != nil {
441+
instance.Status.PrometheusHost = string(prometheusEndpointSecret.Data[metricstorage.PrometheusHost])
442+
}
430443
} else {
431444
instance.Status.PrometheusHost = instance.Spec.PrometheusHost
432445
}
433446
if instance.Spec.PrometheusPort == 0 {
434-
instance.Status.PrometheusPort = telemetryv1.DefaultPrometheusPort
447+
if prometheusEndpointSecret.Data != nil {
448+
port, err := strconv.Atoi(string(prometheusEndpointSecret.Data[metricstorage.PrometheusPort]))
449+
if err != nil {
450+
return ctrlResult, err
451+
}
452+
instance.Status.PrometheusPort = int32(port)
453+
}
435454
} else {
436455
instance.Status.PrometheusPort = instance.Spec.PrometheusPort
437456
}
@@ -595,8 +614,6 @@ func (r *AutoscalingReconciler) generateServiceConfig(
595614
"AodhPassword": string(ospSecret.Data[instance.Spec.Aodh.PasswordSelectors.AodhService]),
596615
"KeystoneInternalURL": keystoneInternalURL,
597616
"TransportURL": string(transportURLSecret.Data["transport_url"]),
598-
"PrometheusHost": instance.Status.PrometheusHost,
599-
"PrometheusPort": instance.Status.PrometheusPort,
600617
"MemcachedServers": mc.GetMemcachedServerListString(),
601618
"MemcachedServersWithInet": mc.GetMemcachedServerListWithInetString(),
602619
"DatabaseConnection": fmt.Sprintf("mysql+pymysql://%s:%s@%s/%s?read_default_file=/etc/my.cnf",

controllers/metricstorage_controller.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -633,8 +633,8 @@ func (r *MetricStorageReconciler) prometheusEndpointSecret(
633633
}
634634

635635
secret.Data = map[string][]byte{
636-
"host": []byte(fmt.Sprintf("%s-prometheus.%s.svc", telemetryv1.DefaultServiceName, instance.Namespace)),
637-
"port": []byte(strconv.Itoa(telemetryv1.DefaultPrometheusPort)),
636+
metricstorage.PrometheusHost: []byte(fmt.Sprintf("%s-prometheus.%s.svc", telemetryv1.DefaultServiceName, instance.Namespace)),
637+
metricstorage.PrometheusPort: []byte(strconv.Itoa(telemetryv1.DefaultPrometheusPort)),
638638
}
639639

640640
if _, err := controllerutil.CreateOrUpdate(context.TODO(), helper.GetClient(), secret, func() error {
@@ -653,8 +653,8 @@ func (r *MetricStorageReconciler) prometheusEndpointSecret(
653653
if instance.Spec.PrometheusTLS.Enabled() {
654654
tlsSecret := &corev1.Secret{
655655
Data: map[string][]byte{
656-
"ca_secret": []byte(*instance.Spec.PrometheusTLS.SecretName),
657-
"ca_key": []byte(tls.CAKey),
656+
metricstorage.PrometheusCaCertSecret: []byte(*instance.Spec.PrometheusTLS.SecretName),
657+
metricstorage.PrometheusCaCertKey: []byte(tls.CAKey),
658658
},
659659
}
660660

@@ -664,7 +664,7 @@ func (r *MetricStorageReconciler) prometheusEndpointSecret(
664664
}
665665

666666
if err := r.Client.Patch(ctx, secret, client.RawPatch(types.StrategicMergePatchType, patch)); err != nil {
667-
panic(err)
667+
return err
668668
}
669669
}
670670

pkg/autoscaling/const.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ const (
4141

4242
// CustomPrometheusCaCertFolderPath -
4343
CustomPrometheusCaCertFolderPath = "/etc/pki/ca-trust/extracted/pem/"
44+
45+
PrometheusEndpointSecret = "metric-storage-prometheus-endpoint"
4446
)
4547

4648
// PrometheusReplicas -

pkg/metricstorage/const.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,9 @@ package metricstorage
1717

1818
const (
1919
RabbitMQPrometheusPort = 15691
20+
21+
PrometheusHost = "host"
22+
PrometheusPort = "port"
23+
PrometheusCaCertSecret = "ca_secret"
24+
PrometheusCaCertKey = "ca_key"
2025
)

0 commit comments

Comments
 (0)