Skip to content

Commit

Permalink
fix finalizer removal
Browse files Browse the repository at this point in the history
  • Loading branch information
QuentinBisson committed May 27, 2024
1 parent 5446950 commit 9e96792
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions pkg/monitoring/prometheusagent/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ func (pas PrometheusAgentService) deleteConfigMap(ctx context.Context, cluster *
Name: getPrometheusAgentRemoteWriteConfigName(cluster),
Namespace: cluster.GetNamespace(),
}
current := &corev1.ConfigMap{}
configMap := &corev1.ConfigMap{}
// Get the current configmap if it exists.
err := pas.Client.Get(ctx, objectKey, current)
err := pas.Client.Get(ctx, objectKey, configMap)
if apierrors.IsNotFound(err) {
// Ignore cases where the configmap is not found (if it was manually deleted, for instance).
return nil
Expand All @@ -189,14 +189,13 @@ func (pas PrometheusAgentService) deleteConfigMap(ctx context.Context, cluster *
}

// Delete the finalizer
desired := current.DeepCopy()
controllerutil.RemoveFinalizer(desired, monitoring.MonitoringFinalizer)
err = pas.Client.Patch(ctx, desired, client.MergeFrom(current))
controllerutil.RemoveFinalizer(configMap, monitoring.MonitoringFinalizer)
err = pas.Client.Update(ctx, configMap)
if err != nil {
return errors.WithStack(err)
}

err = pas.Client.Delete(ctx, desired)
err = pas.Client.Delete(ctx, configMap)
if err != nil {
return errors.WithStack(err)
}
Expand All @@ -208,9 +207,9 @@ func (pas PrometheusAgentService) deleteSecret(ctx context.Context, cluster *clu
Name: getPrometheusAgentRemoteWriteSecretName(cluster),
Namespace: cluster.GetNamespace(),
}
current := &corev1.Secret{}
secret := &corev1.Secret{}
// Get the current secret if it exists.
err := pas.Client.Get(ctx, objectKey, current)
err := pas.Client.Get(ctx, objectKey, secret)
if apierrors.IsNotFound(err) {
// Ignore cases where the secret is not found (if it was manually deleted, for instance).
return nil
Expand All @@ -219,14 +218,13 @@ func (pas PrometheusAgentService) deleteSecret(ctx context.Context, cluster *clu
}

// Delete the finalizer
desired := current.DeepCopy()
controllerutil.RemoveFinalizer(desired, monitoring.MonitoringFinalizer)
err = pas.Client.Patch(ctx, current, client.MergeFrom(desired))
controllerutil.RemoveFinalizer(secret, monitoring.MonitoringFinalizer)
err = pas.Client.Update(ctx, secret)
if err != nil {
return errors.WithStack(err)
}

err = pas.Client.Delete(ctx, desired)
err = pas.Client.Delete(ctx, secret)
if err != nil {
return errors.WithStack(err)
}
Expand Down

0 comments on commit 9e96792

Please sign in to comment.