Skip to content

Commit

Permalink
Rename ServiceMonitors to not get deleted by operator
Browse files Browse the repository at this point in the history
We create our own ServiceMonitor resources, since the argocd-operator
doesn't support creating ServiceMonitors without also deploying a
Prometheus instance.

However, the operator will delete any ServiceMonitor which matches the
name that it would generate for its managed ServiceMonitors if the
Prometheus component is disabled, cf.
https://github.com/argoproj-labs/argocd-operator/blob/17064c9b310785ab145747a367f7deb5507a572e/controllers/argocd/prometheus.go#L129-L136

This causes the component-managed ServiceMonitors to get deleted from
time to time, and they get recreated after a while by an ArgoCD resync.

This commit circumvents the issue by renaming the component-managed
ServiceMonitors so they don't get deleted by the operator.
  • Loading branch information
simu committed Nov 16, 2023
1 parent 331559a commit 6cd258e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 39 deletions.
8 changes: 5 additions & 3 deletions component/monitoring.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,10 @@ local promEnable = function(obj)
;

[
promEnable(serviceMonitor('syn-argocd-metrics')),
promEnable(serviceMonitor('syn-argocd-server-metrics')),
promEnable(serviceMonitor('syn-argocd-repo-server')),
// We explicitly select names for the service monitors which don't match the
// operator-generated names for instance syn-argocd
promEnable(serviceMonitor('syn-component-argocd-metrics')),
promEnable(serviceMonitor('syn-component-argocd-server-metrics')),
promEnable(serviceMonitor('syn-component-argocd-repo-server')),
promEnable(alert_rules),
] + if params.monitoring.dashboards then [ grafana_dashboard ] else []
24 changes: 12 additions & 12 deletions tests/golden/defaults/argocd/argocd/01_namespace/20_monitoring.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,56 +3,56 @@ kind: ServiceMonitor
metadata:
annotations: {}
labels:
app.kubernetes.io/name: syn-argocd-metrics
app.kubernetes.io/name: syn-component-argocd-metrics
app.kubernetes.io/part-of: argocd
monitoring.syn.tools/enabled: 'true'
name: syn-argocd-metrics
name: syn-argocd-metrics
name: syn-component-argocd-metrics
name: syn-component-argocd-metrics
namespace: syn
spec:
endpoints:
- port: metrics
selector:
matchLabels:
app.kubernetes.io/name: syn-argocd-metrics
app.kubernetes.io/name: syn-component-argocd-metrics
app.kubernetes.io/part-of: argocd
---
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
annotations: {}
labels:
app.kubernetes.io/name: syn-argocd-server-metrics
app.kubernetes.io/name: syn-component-argocd-server-metrics
app.kubernetes.io/part-of: argocd
monitoring.syn.tools/enabled: 'true'
name: syn-argocd-server-metrics
name: syn-argocd-server-metrics
name: syn-component-argocd-server-metrics
name: syn-component-argocd-server-metrics
namespace: syn
spec:
endpoints:
- port: metrics
selector:
matchLabels:
app.kubernetes.io/name: syn-argocd-server-metrics
app.kubernetes.io/name: syn-component-argocd-server-metrics
app.kubernetes.io/part-of: argocd
---
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
annotations: {}
labels:
app.kubernetes.io/name: syn-argocd-repo-server
app.kubernetes.io/name: syn-component-argocd-repo-server
app.kubernetes.io/part-of: argocd
monitoring.syn.tools/enabled: 'true'
name: syn-argocd-repo-server
name: syn-argocd-repo-server
name: syn-component-argocd-repo-server
name: syn-component-argocd-repo-server
namespace: syn
spec:
endpoints:
- port: metrics
selector:
matchLabels:
app.kubernetes.io/name: syn-argocd-repo-server
app.kubernetes.io/name: syn-component-argocd-repo-server
app.kubernetes.io/part-of: argocd
---
apiVersion: monitoring.coreos.com/v1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,56 +3,56 @@ kind: ServiceMonitor
metadata:
annotations: {}
labels:
app.kubernetes.io/name: syn-argocd-metrics
app.kubernetes.io/name: syn-component-argocd-metrics
app.kubernetes.io/part-of: argocd
monitoring.syn.tools/enabled: 'true'
name: syn-argocd-metrics
name: syn-argocd-metrics
name: syn-component-argocd-metrics
name: syn-component-argocd-metrics
namespace: syn
spec:
endpoints:
- port: metrics
selector:
matchLabels:
app.kubernetes.io/name: syn-argocd-metrics
app.kubernetes.io/name: syn-component-argocd-metrics
app.kubernetes.io/part-of: argocd
---
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
annotations: {}
labels:
app.kubernetes.io/name: syn-argocd-server-metrics
app.kubernetes.io/name: syn-component-argocd-server-metrics
app.kubernetes.io/part-of: argocd
monitoring.syn.tools/enabled: 'true'
name: syn-argocd-server-metrics
name: syn-argocd-server-metrics
name: syn-component-argocd-server-metrics
name: syn-component-argocd-server-metrics
namespace: syn
spec:
endpoints:
- port: metrics
selector:
matchLabels:
app.kubernetes.io/name: syn-argocd-server-metrics
app.kubernetes.io/name: syn-component-argocd-server-metrics
app.kubernetes.io/part-of: argocd
---
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
annotations: {}
labels:
app.kubernetes.io/name: syn-argocd-repo-server
app.kubernetes.io/name: syn-component-argocd-repo-server
app.kubernetes.io/part-of: argocd
monitoring.syn.tools/enabled: 'true'
name: syn-argocd-repo-server
name: syn-argocd-repo-server
name: syn-component-argocd-repo-server
name: syn-component-argocd-repo-server
namespace: syn
spec:
endpoints:
- port: metrics
selector:
matchLabels:
app.kubernetes.io/name: syn-argocd-repo-server
app.kubernetes.io/name: syn-component-argocd-repo-server
app.kubernetes.io/part-of: argocd
---
apiVersion: monitoring.coreos.com/v1
Expand Down
24 changes: 12 additions & 12 deletions tests/golden/params/argocd/argocd/01_namespace/20_monitoring.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,53 +3,53 @@ kind: ServiceMonitor
metadata:
annotations: {}
labels:
app.kubernetes.io/name: syn-argocd-metrics
app.kubernetes.io/name: syn-component-argocd-metrics
app.kubernetes.io/part-of: argocd
name: syn-argocd-metrics
name: syn-argocd-metrics
name: syn-component-argocd-metrics
name: syn-component-argocd-metrics
namespace: syn
spec:
endpoints:
- port: metrics
selector:
matchLabels:
app.kubernetes.io/name: syn-argocd-metrics
app.kubernetes.io/name: syn-component-argocd-metrics
app.kubernetes.io/part-of: argocd
---
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
annotations: {}
labels:
app.kubernetes.io/name: syn-argocd-server-metrics
app.kubernetes.io/name: syn-component-argocd-server-metrics
app.kubernetes.io/part-of: argocd
name: syn-argocd-server-metrics
name: syn-argocd-server-metrics
name: syn-component-argocd-server-metrics
name: syn-component-argocd-server-metrics
namespace: syn
spec:
endpoints:
- port: metrics
selector:
matchLabels:
app.kubernetes.io/name: syn-argocd-server-metrics
app.kubernetes.io/name: syn-component-argocd-server-metrics
app.kubernetes.io/part-of: argocd
---
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
annotations: {}
labels:
app.kubernetes.io/name: syn-argocd-repo-server
app.kubernetes.io/name: syn-component-argocd-repo-server
app.kubernetes.io/part-of: argocd
name: syn-argocd-repo-server
name: syn-argocd-repo-server
name: syn-component-argocd-repo-server
name: syn-component-argocd-repo-server
namespace: syn
spec:
endpoints:
- port: metrics
selector:
matchLabels:
app.kubernetes.io/name: syn-argocd-repo-server
app.kubernetes.io/name: syn-component-argocd-repo-server
app.kubernetes.io/part-of: argocd
---
apiVersion: monitoring.coreos.com/v1
Expand Down

0 comments on commit 6cd258e

Please sign in to comment.