Skip to content

Commit

Permalink
Correct labels on memcached servicemonitors (#740)
Browse files Browse the repository at this point in the history
  • Loading branch information
philipgough authored Feb 12, 2025
1 parent f393d6a commit c6c9c35
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
7 changes: 5 additions & 2 deletions magefiles/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,15 +237,18 @@ func createCacheHeadlessService(config *memcachedConfig) *corev1.Service {
}

func createCacheServiceMonitor(config *memcachedConfig) *monitoringv1.ServiceMonitor {
labels := deepCopyMap(config.Labels)
labels[openshiftCustomerMonitoringLabel] = openShiftClusterMonitoringLabelValue

return &monitoringv1.ServiceMonitor{
TypeMeta: metav1.TypeMeta{
Kind: "ServiceMonitor",
APIVersion: "monitoring.coreos.com/v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: config.Name,
Namespace: config.Namespace,
Labels: config.Labels,
Namespace: openshiftCustomerMonitoringNamespace,
Labels: labels,
},
Spec: monitoringv1.ServiceMonitorSpec{
Endpoints: []monitoringv1.Endpoint{
Expand Down
23 changes: 17 additions & 6 deletions magefiles/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ const (
serviceRedirectAnnotation = "serviceaccounts.openshift.io/oauth-redirectreference.application"

serviceMonitorTemplate = "service-monitor-template.yaml"

openshiftCustomerMonitoringLabel = "prometheus"
openShiftClusterMonitoringLabelValue = "app-sre"
openshiftCustomerMonitoringNamespace = "openshift-customer-monitoring"
)

type resourceRequirements struct {
Expand Down Expand Up @@ -137,12 +141,7 @@ func getAndRemoveObject[T metav1.Object](objects []runtime.Object, name string)

// postProcessServiceMonitor updates the service monitor to work with the app-sre prometheus.
func postProcessServiceMonitor(serviceMonitor *monv1.ServiceMonitor, namespaceSelector string) encoding.Encoder {
const (
openshiftCustomerMonitoringLabel = "prometheus"
openShiftClusterMonitoringLabelValue = "app-sre"
)

serviceMonitor.ObjectMeta.Namespace = "openshift-customer-monitoring"
serviceMonitor.ObjectMeta.Namespace = openshiftCustomerMonitoringNamespace
serviceMonitor.Spec.NamespaceSelector.MatchNames = []string{namespaceSelector}
serviceMonitor.ObjectMeta.Labels[openshiftCustomerMonitoringLabel] = openShiftClusterMonitoringLabelValue

Expand Down Expand Up @@ -174,3 +173,15 @@ func createServiceAccount(name, namespace string, labels map[string]string) *cor
},
}
}

func deepCopyMap(m map[string]string) map[string]string {
if m == nil {
return nil
}

result := make(map[string]string, len(m))
for k, v := range m {
result[k] = v
}
return result
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ objects:
app.kubernetes.io/name: memcached
app.kubernetes.io/part-of: observatorium
app.kubernetes.io/version: 1.5-316
prometheus: app-sre
name: api-memcached
namespace: rhobs-stage
namespace: openshift-customer-monitoring
spec:
endpoints:
- honorLabels: true
Expand Down

0 comments on commit c6c9c35

Please sign in to comment.