Skip to content

Commit b575014

Browse files
committed
Do not touch ServiceMonitor not owned by us.
1 parent 2eec97c commit b575014

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

pkg/deployment/resources/servicemonitor.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func (r *Resources) EnsureServiceMonitor() error {
107107

108108
// Check if ServiceMonitor already exists
109109
serviceMonitors := mClient.ServiceMonitors(ns)
110-
_, err = serviceMonitors.Get(serviceMonitorName, metav1.GetOptions{})
110+
servMon, err := serviceMonitors.Get(serviceMonitorName, metav1.GetOptions{})
111111
if err != nil {
112112
if k8sutil.IsNotFound(err) {
113113
if !wantMetrics {
@@ -147,6 +147,19 @@ func (r *Resources) EnsureServiceMonitor() error {
147147
serviceMonitorName)
148148
return nil
149149
}
150+
// Check if the service monitor is ours, otherwise we do not touch it:
151+
found := false
152+
for _, owner := range servMon.ObjectMeta.OwnerReferences {
153+
if owner.Kind == "ArangoDeployment" &&
154+
owner.Name == deploymentName {
155+
found = true
156+
break
157+
}
158+
}
159+
if !found {
160+
log.Debug().Msgf("Found unneeded ServiceMonitor %s, but not owned by us, will not touch it", serviceMonitorName)
161+
return nil
162+
}
150163
// Need to get rid of the ServiceMonitor:
151164
err = serviceMonitors.Delete(serviceMonitorName, &metav1.DeleteOptions{})
152165
if err == nil {

0 commit comments

Comments
 (0)